nli_pipeline 0.0.0 → 0.0.1
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/bin/setup_pipeline +1 -11
- data/lib/nli_pipeline/file_manager.rb +84 -0
- data/lib/nli_pipeline/setup_pipeline.rb +64 -0
- data/lib/nli_pipeline.rb +7 -45
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94d6783976cf9ba327368ffc9ecd7081e9499991
|
4
|
+
data.tar.gz: 5c8853eb5884a7b8196ccbebfc0fa91df2d29bff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ab3bb4ee792d86473846b2ef7c56c14a677ddfc8de11a01b2f280a9172679e6a847815702db32ddbeba992ddd0390a602911bfd564e1f76f36ce95610d247eb
|
7
|
+
data.tar.gz: 9d65983f9e2bcb845c9f58143f9bd015ad315a4af0604df1bbb94c356386a354df8836eacf22c47ddae43d078ef49298acc8a158cdc8afef58f78dd382146741
|
data/bin/setup_pipeline
CHANGED
@@ -1,14 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
2
|
require 'nli_pipeline'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
if !ARGV[0]
|
8
|
-
dir = File.expand_path(File.dirname(__dir__))
|
9
|
-
else
|
10
|
-
dir = ARGV[0]
|
11
|
-
end
|
12
|
-
|
13
|
-
puts "setting up pipeline in #{dir}"
|
14
|
-
fm.copy_example_files(dir)
|
4
|
+
SetupPipeline.new.main()
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Manage example files
|
4
|
+
#
|
5
|
+
# EXAMPLE:
|
6
|
+
# >> FileManager.new.copy_example_files()
|
7
|
+
# => Moving 1 .EXAMPLE files
|
8
|
+
class FileManager
|
9
|
+
|
10
|
+
attr_accessor :backup
|
11
|
+
attr_accessor :extension
|
12
|
+
|
13
|
+
# Arguements:
|
14
|
+
# backup: (boolean)
|
15
|
+
# extension: (string)
|
16
|
+
def initialize(backup: true, extension: ".EXAMPLE")
|
17
|
+
# puts("config= {backup: #{backup} extension: #{extension}}")
|
18
|
+
@backup = backup
|
19
|
+
@extension = extension
|
20
|
+
end
|
21
|
+
|
22
|
+
# Arguements:
|
23
|
+
# path: (string: filepath)
|
24
|
+
def get_all_backups(path)
|
25
|
+
backup_files = Dir.glob("#{path}/**/*.backup*")
|
26
|
+
return backup_files.map {|x| x.split(".backup").last.to_i}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Arguements:
|
30
|
+
# path: (string: filepath)
|
31
|
+
# command: (string: system command)
|
32
|
+
def copy_example_files(path, command="cp")
|
33
|
+
example_file_path = "#{path}/**/*#{extension}"
|
34
|
+
example_files = Dir.glob(example_file_path)
|
35
|
+
if example_files.empty?
|
36
|
+
raise "No #{extension} Files found at #{example_file_path}"
|
37
|
+
else
|
38
|
+
puts("Moving #{example_files.count} #{extension} files")
|
39
|
+
end
|
40
|
+
|
41
|
+
example_files.each do |example_file|
|
42
|
+
target_file = example_file.gsub(extension, "")
|
43
|
+
# backup configuration if it already exists
|
44
|
+
if File.exists?(target_file)
|
45
|
+
puts("backing up #{target_file}")
|
46
|
+
system("#{command} #{target_file} #{target_file}.backup#{Time.now.strftime("%Y%m%d%H%M")}")
|
47
|
+
end
|
48
|
+
# convert the example file to real config
|
49
|
+
system("#{command} #{example_file} #{target_file}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Arguements:
|
54
|
+
# path: (string: filepath)
|
55
|
+
# command: (string: system command)
|
56
|
+
#
|
57
|
+
# to remove backup, use mv
|
58
|
+
# to keep backup, use cp
|
59
|
+
def load_from_backup(path, command="cp")
|
60
|
+
backups = get_all_backups(path)
|
61
|
+
if backups.empty?
|
62
|
+
raise "\n No backups found \n"
|
63
|
+
end
|
64
|
+
puts "which backup would you like to load? #{backups}"
|
65
|
+
latest_backup_date = STDIN.gets().chomp()
|
66
|
+
|
67
|
+
# backups are integers, comapre as strings
|
68
|
+
while !backups.map {|b| b.to_s} .include?(latest_backup_date)
|
69
|
+
puts "#{latest_backup_date} is not in backups"
|
70
|
+
puts "please choose from: #{backups}"
|
71
|
+
latest_backup_date = STDIN.gets().chomp()
|
72
|
+
end
|
73
|
+
|
74
|
+
puts "loading *.backup#{latest_backup_date}"
|
75
|
+
|
76
|
+
Dir.glob("#{path}/**/*.backup#{latest_backup_date}").each do |backup_file|
|
77
|
+
target_file = backup_file.gsub("\.backup#{latest_backup_date}", "")
|
78
|
+
command = "#{command} #{backup_file} #{target_file}"
|
79
|
+
puts(command)
|
80
|
+
system(command)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'optparse' # core gem, no install required
|
2
|
+
|
3
|
+
# Class used to parse arguements from bin/setup_pipeline executable
|
4
|
+
class SetupPipeline
|
5
|
+
# Commandline Arguements:
|
6
|
+
# $1 (file path) (required)
|
7
|
+
# $2 (undo) (not required)
|
8
|
+
# --version
|
9
|
+
# --backup
|
10
|
+
# --no-backup
|
11
|
+
# --extension=(string: file extension)
|
12
|
+
#
|
13
|
+
# Raises:
|
14
|
+
# ArgumentError if $1 is missing or is not a valid directory
|
15
|
+
|
16
|
+
def parse_args()
|
17
|
+
options = {}
|
18
|
+
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
|
+
opts.on("-v", "--version") do |v|
|
24
|
+
puts NliPipeline::VERSION
|
25
|
+
# break out of function, don't throw exception about passing directory path
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("--[no-]backup") do |v|
|
30
|
+
options[:backup] = v
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("--extension=[\w+]") do |v|
|
34
|
+
options[:extension] = v
|
35
|
+
end
|
36
|
+
|
37
|
+
end.parse!
|
38
|
+
|
39
|
+
|
40
|
+
if !ARGV[0] || !Dir.exist?(ARGV[0])
|
41
|
+
error_message = "The first arguement to setup_pipeline must be a valid directory."
|
42
|
+
example = "For example, setting up a pipeline in the current directory: setup_pipeline $PWD"
|
43
|
+
raise ArgumentError.new("\n\n#{error_message}\n#{example}\n\n")
|
44
|
+
else
|
45
|
+
return [ARGV[0], options]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def main()
|
50
|
+
args = parse_args()
|
51
|
+
if args
|
52
|
+
dir, options = args
|
53
|
+
# pass options hash as keyword arguements
|
54
|
+
fm = FileManager.new(**options)
|
55
|
+
if ARGV[1] == "undo"
|
56
|
+
puts "loading backups in #{dir}"
|
57
|
+
fm.load_from_backup(dir)
|
58
|
+
else
|
59
|
+
puts "setting up pipeline in #{dir}"
|
60
|
+
fm.copy_example_files(dir)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/nli_pipeline.rb
CHANGED
@@ -1,48 +1,10 @@
|
|
1
|
-
|
2
|
-
attr_accessor :backup
|
3
|
-
attr_accessor :extension
|
1
|
+
module NliPipeline
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def get_latest_backup_number(backup_files)
|
11
|
-
backup_dates = backup_files.map {|x| x.split(".backup").last.to_i}
|
12
|
-
return "#{backup_dates.max}"
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
def copy_example_files(path, command="cp")
|
17
|
-
example_file_path = "#{path}/**/*.EXAMPLE"
|
18
|
-
example_files = Dir.glob(example_file_path)
|
19
|
-
if example_files.empty?
|
20
|
-
raise "No Example Files found at #{example_file_path}"
|
21
|
-
else
|
22
|
-
puts("Moving #{example_files.count} example files")
|
23
|
-
end
|
24
|
-
|
25
|
-
example_files.each do |example_file|
|
26
|
-
target_file = example_file.gsub("\.EXAMPLE", "")
|
27
|
-
# backup configuration if it already exists
|
28
|
-
if File.exists?(target_file)
|
29
|
-
puts("backing up #{target_file}")
|
30
|
-
system("#{command} #{target_file} #{target_file}.backup#{Time.now.strftime("%Y%m%d%H%M")}")
|
31
|
-
end
|
32
|
-
# convert the example file to real config
|
33
|
-
system("#{command} #{example_file} #{target_file}")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
# to remove backup, use mv
|
39
|
-
# to keep backup, use cp
|
40
|
-
def undo_latest_copy_example_files(path, command="cp")
|
41
|
-
latest_backup_date = get_latest_backup_number(Dir.glob("./**/*.backup*"))
|
42
|
-
Dir.glob("#{path}/**/*.backup#{latest_backup_date}").each do |backup_file|
|
43
|
-
target_file = backup_file.gsub("\.backup#{latest_backup_date}", "")
|
44
|
-
system("#{command} #{backup_file} #{target_file}")
|
45
|
-
end
|
46
|
-
end
|
3
|
+
# constant use in nli_pipeline.gemspec and bin/setup_pipeline
|
4
|
+
# to determine current version of gem
|
5
|
+
# should also match tag on bitbucket
|
6
|
+
VERSION = "0.0.1"
|
47
7
|
|
8
|
+
require_relative 'nli_pipeline/file_manager'
|
9
|
+
require_relative 'nli_pipeline/setup_pipeline'
|
48
10
|
end
|
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.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conor Sheehan
|
@@ -19,7 +19,9 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- bin/setup_pipeline
|
21
21
|
- lib/nli_pipeline.rb
|
22
|
-
|
22
|
+
- lib/nli_pipeline/file_manager.rb
|
23
|
+
- lib/nli_pipeline/setup_pipeline.rb
|
24
|
+
homepage: https://rubygems.org/gems/nli_pipeline
|
23
25
|
licenses:
|
24
26
|
- MIT
|
25
27
|
metadata: {}
|