nli_pipeline 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nli_pipeline/file_manager.rb +53 -37
- data/lib/nli_pipeline/setup_pipeline.rb +15 -23
- data/lib/nli_pipeline.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d8bf060accfdf2aab9524b1c876e39cc6727b36
|
4
|
+
data.tar.gz: 2604f60e3bb6dd5b8871aa69373b4e8a18a8b390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 797f7b480c8d9b2521110993c62955662b9ab7be228cb84663db0700b21e9486d0de13b75317ecb6e7eb2722df4f79c77359ffa0ef867b844002b184080a27fe
|
7
|
+
data.tar.gz: 8d884eb2bd4713aee5e879f57e788d0697a55c0b951f8b8dc4ce9decf7688caf323a90cfbc2ce6258584cf3802f54c746c7326a26bacfc31b5da39d744494963
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'colorize'
|
2
3
|
|
3
4
|
# Manage example files
|
4
5
|
#
|
@@ -7,77 +8,92 @@ require 'rubygems'
|
|
7
8
|
# => Moving 1 .EXAMPLE files
|
8
9
|
class FileManager
|
9
10
|
|
10
|
-
|
11
|
+
attr_reader :path
|
11
12
|
attr_accessor :extension
|
13
|
+
attr_accessor :debug
|
12
14
|
|
13
|
-
#
|
14
|
-
#
|
15
|
+
# Arguments:
|
16
|
+
# path: (string: path to directory)
|
15
17
|
# extension: (string)
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
# debug: (boolean)
|
19
|
+
# no_output: (boolean: used for suppressing output during tests)
|
20
|
+
def initialize(path, extension: ".EXAMPLE", debug: false, no_output: false)
|
21
|
+
puts("config = {path: '#{path}', extension: '#{extension}', debug: #{debug}, no_output: #{no_output}}".yellow()) if debug
|
22
|
+
@path = path
|
19
23
|
@extension = extension
|
24
|
+
@debug = debug
|
25
|
+
@no_output = no_output
|
20
26
|
end
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
return backup_files.map {|x| x.split(".backup").last.to_i}
|
28
|
+
def get_all_backups()
|
29
|
+
backup_files = Dir.glob("#{@path}/**/*.backup*")
|
30
|
+
backup_numbers = backup_files.map {|x| x.split(".backup").last}
|
31
|
+
return backup_numbers.uniq.sort
|
27
32
|
end
|
28
33
|
|
29
|
-
#
|
30
|
-
# path: (string: filepath)
|
34
|
+
# Arguments:
|
31
35
|
# command: (string: system command)
|
32
|
-
def copy_example_files(
|
33
|
-
|
36
|
+
def copy_example_files(command="cp")
|
37
|
+
puts("Setting up pipeline in #{@path}".yellow()) unless @no_output
|
38
|
+
example_file_path = "#{@path}/**/*#{extension}"
|
34
39
|
example_files = Dir.glob(example_file_path)
|
35
40
|
if example_files.empty?
|
36
41
|
raise "No #{extension} Files found at #{example_file_path}"
|
37
42
|
else
|
38
|
-
puts("Moving #{example_files.count} #{extension} files")
|
43
|
+
puts("Moving #{example_files.count} #{extension} files".green()) unless @no_output
|
39
44
|
end
|
40
45
|
|
41
|
-
example_files.
|
42
|
-
|
43
|
-
# backup
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
files_to_backup = example_files.map {|f| f.gsub(@extension, "")}.select {|file| File.exists?(file) }
|
47
|
+
if !files_to_backup.empty?
|
48
|
+
# preset backup time so all backups fomr same batch have the same timestamp
|
49
|
+
backup_time_stamp = Time.now.strftime("%Y%m%d%H%M")
|
50
|
+
puts("Backing up #{files_to_backup.count} files".green()) unless @no_output
|
51
|
+
files_to_backup.each do |file_to_backup|
|
52
|
+
full_command = "#{command} #{file_to_backup} #{file_to_backup}.backup#{backup_time_stamp}"
|
53
|
+
puts("\t#{full_command}") if @debug
|
54
|
+
system(full_command)
|
47
55
|
end
|
56
|
+
end
|
57
|
+
|
58
|
+
example_files.each do |example_file|
|
59
|
+
target_file = example_file.gsub(@extension, "")
|
48
60
|
# convert the example file to real config
|
49
|
-
|
61
|
+
full_command = "#{command} #{example_file} #{target_file}"
|
62
|
+
puts("\t#{full_command}") if @debug
|
63
|
+
system(full_command)
|
50
64
|
end
|
51
65
|
end
|
52
66
|
|
53
|
-
#
|
54
|
-
# path: (string: filepath)
|
67
|
+
# Arguments:
|
55
68
|
# command: (string: system command)
|
56
69
|
#
|
57
70
|
# to remove backup, use mv
|
58
71
|
# to keep backup, use cp
|
59
|
-
def load_from_backup(
|
60
|
-
|
72
|
+
def load_from_backup(command="cp")
|
73
|
+
puts("loading backup in #{@path}".yellow())
|
74
|
+
backups = get_all_backups()
|
61
75
|
if backups.empty?
|
76
|
+
# TODO: better exception class here?
|
62
77
|
raise "\n No backups found \n"
|
63
78
|
end
|
64
|
-
|
79
|
+
|
80
|
+
puts "which backup would you like to load?\n#{backups}".yellow()
|
65
81
|
latest_backup_date = STDIN.gets().chomp()
|
66
82
|
|
67
|
-
|
68
|
-
|
69
|
-
puts "
|
70
|
-
puts "please choose from: #{backups}"
|
83
|
+
while !backups.include?(latest_backup_date)
|
84
|
+
puts "#{latest_backup_date} is not in backups".red()
|
85
|
+
puts "please choose from: #{backups}".yellow()
|
71
86
|
latest_backup_date = STDIN.gets().chomp()
|
72
87
|
end
|
73
88
|
|
74
|
-
|
89
|
+
files_to_load = Dir.glob("#{@path}/**/*.backup#{latest_backup_date}")
|
90
|
+
puts "loading #{files_to_load.count} files from #{@path}/**/*.backup#{latest_backup_date}".green()
|
75
91
|
|
76
|
-
|
92
|
+
files_to_load.each do |backup_file|
|
77
93
|
target_file = backup_file.gsub("\.backup#{latest_backup_date}", "")
|
78
|
-
|
79
|
-
puts(
|
80
|
-
system(
|
94
|
+
full_command = "#{command} #{backup_file} #{target_file}"
|
95
|
+
puts("\t#{full_command}") if @debug
|
96
|
+
system(full_command)
|
81
97
|
end
|
82
98
|
end
|
83
99
|
|
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'optparse' # core gem, no install required
|
2
2
|
|
3
|
-
# Class used to parse
|
3
|
+
# Class used to parse arguments from bin/setup_pipeline executable
|
4
4
|
class SetupPipeline
|
5
|
-
# Commandline
|
5
|
+
# Commandline Arguments:
|
6
6
|
# $1 (file path) (required)
|
7
7
|
# $2 (undo) (not required)
|
8
8
|
# --version
|
9
|
-
# --backup
|
10
|
-
# --no-backup
|
11
9
|
# --extension=(string: file extension)
|
10
|
+
# --debug (show system commands when enabled)
|
12
11
|
#
|
13
12
|
# Raises:
|
14
13
|
# ArgumentError if $1 is missing or is not a valid directory
|
@@ -16,48 +15,41 @@ class SetupPipeline
|
|
16
15
|
def parse_args()
|
17
16
|
options = {}
|
18
17
|
OptionParser.new do |opts|
|
19
|
-
usage = "Usage: setup_pipeline [directory:str (backup:bool) (extension:str)]"
|
20
|
-
usage_example = "Example: setup_pipeline $PWD"
|
21
|
-
opts.banner = "#{usage}\n#{usage_example}"
|
22
|
-
|
23
18
|
opts.on("-v", "--version") do |v|
|
24
19
|
puts NliPipeline::VERSION
|
25
20
|
# break out of function, don't throw exception about passing directory path
|
26
21
|
return false
|
27
22
|
end
|
28
|
-
|
29
|
-
opts.on("--[no-]backup") do |v|
|
30
|
-
options[:backup] = v
|
31
|
-
end
|
32
|
-
|
33
23
|
opts.on("--extension=[\w+]") do |v|
|
34
24
|
options[:extension] = v
|
35
25
|
end
|
36
|
-
|
26
|
+
opts.on("--debug") do |v|
|
27
|
+
options[:debug] = v
|
28
|
+
end
|
37
29
|
end.parse!
|
38
30
|
|
39
|
-
|
40
31
|
if !ARGV[0] || !Dir.exist?(ARGV[0])
|
41
|
-
error_message = "The first
|
32
|
+
error_message = "The first argument to setup_pipeline must be a valid directory."
|
42
33
|
example = "For example, setting up a pipeline in the current directory: setup_pipeline $PWD"
|
43
|
-
|
34
|
+
exception = "The only exception to this is: setup_pipeline --version"
|
35
|
+
raise ArgumentError.new("\n\n#{error_message}\n#{example}\n#{exception}\n\n")
|
44
36
|
else
|
45
37
|
return [ARGV[0], options]
|
46
38
|
end
|
47
39
|
end
|
48
40
|
|
41
|
+
# Method called by bin/setup_pipeline
|
42
|
+
# TODO: move undo arg handling to parse_args?
|
49
43
|
def main()
|
50
44
|
args = parse_args()
|
51
45
|
if args
|
52
46
|
dir, options = args
|
53
|
-
# pass options hash as keyword
|
54
|
-
fm = FileManager.new(**options)
|
47
|
+
# pass options hash as keyword arguments
|
48
|
+
fm = FileManager.new(dir, **options)
|
55
49
|
if ARGV[1] == "undo"
|
56
|
-
|
57
|
-
fm.load_from_backup(dir)
|
50
|
+
fm.load_from_backup()
|
58
51
|
else
|
59
|
-
|
60
|
-
fm.copy_example_files(dir)
|
52
|
+
fm.copy_example_files()
|
61
53
|
end
|
62
54
|
end
|
63
55
|
end
|
data/lib/nli_pipeline.rb
CHANGED
@@ -3,7 +3,7 @@ module NliPipeline
|
|
3
3
|
# constant use in nli_pipeline.gemspec and bin/setup_pipeline
|
4
4
|
# to determine current version of gem
|
5
5
|
# should also match tag on bitbucket
|
6
|
-
VERSION = "0.0
|
6
|
+
VERSION = "0.1.0"
|
7
7
|
|
8
8
|
require_relative 'nli_pipeline/file_manager'
|
9
9
|
require_relative 'nli_pipeline/setup_pipeline'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nli_pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conor Sheehan
|
@@ -24,7 +24,8 @@ files:
|
|
24
24
|
homepage: https://rubygems.org/gems/nli_pipeline
|
25
25
|
licenses:
|
26
26
|
- MIT
|
27
|
-
metadata:
|
27
|
+
metadata:
|
28
|
+
source_code_uri: https://bitbucket.org/nlireland/nli-pipeline-gem
|
28
29
|
post_install_message:
|
29
30
|
rdoc_options: []
|
30
31
|
require_paths:
|