nli_pipeline 0.1.1 → 0.1.2
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/History.txt +52 -0
- data/lib/nli_pipeline/file_manager.rb +52 -8
- data/lib/nli_pipeline/setup_pipeline.rb +85 -16
- data/lib/nli_pipeline.rb +2 -1
- 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: 5803338257515506b32dc63259908d23d660e701
|
4
|
+
data.tar.gz: b5a12fbcf9b2e604464bd3c99c6b9f3101e34539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b547fd4c73d957517ca8b8cc0b30f189d042188e025d37f9ad42238bdbeae976efede708a6229f9b64a39c4fe353d9e611cdd983393830f45025ef0525b4d77a
|
7
|
+
data.tar.gz: 6ec520a89825c94223381bff4169f807a24d29988c7207f27d0fdbef385c5c581542a751f2ccd49b2888da274f4614e5810e13301e5ebaa544466ec1d6160baf
|
data/History.txt
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
=== 0.1.2 / 2018-06-08
|
4
|
+
Features:
|
5
|
+
* --help show help screen
|
6
|
+
* --show-commands show available commands
|
7
|
+
* --show-flags show available arguments
|
8
|
+
* show_last_created show file created by last setup_pipeline command
|
9
|
+
|
10
|
+
Slight improvement on doc and test coverage
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
=== 0.1.1 / 2018-05-14
|
15
|
+
|
16
|
+
Bug Fixes
|
17
|
+
|
18
|
+
* Include runtime and development dependencies
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
=== 0.1.0 / 2018-05-11
|
23
|
+
|
24
|
+
Breaking changes:
|
25
|
+
|
26
|
+
* Remove --backup and --no-backup flags (should always backup if file already exists)
|
27
|
+
|
28
|
+
|
29
|
+
Features:
|
30
|
+
|
31
|
+
* Add color output
|
32
|
+
* Add --debug flag to show all system commands and config
|
33
|
+
* Add no_output option to suppress all output during tests
|
34
|
+
|
35
|
+
|
36
|
+
=== 0.0.1 / 2018-05-11
|
37
|
+
|
38
|
+
Features:
|
39
|
+
|
40
|
+
* Add RDOC
|
41
|
+
* Add --version flag to show current version
|
42
|
+
* Add --backup flag and --no-backup to handle backups
|
43
|
+
* Add --extension= flag to use custom example file extenstions
|
44
|
+
* Add undo option to load backup files from setup_pipeline executable
|
45
|
+
* Slightly better testing, still unfinished / not using fake file system
|
46
|
+
|
47
|
+
|
48
|
+
=== 0.0.0 / 2018-04-26
|
49
|
+
|
50
|
+
Features:
|
51
|
+
|
52
|
+
* Basic setup_pipeline executable which moves all .EXAMPLE to non .EXAMPLE location
|
@@ -8,8 +8,11 @@ require 'colorize'
|
|
8
8
|
# => Moving 1 .EXAMPLE files
|
9
9
|
class FileManager
|
10
10
|
|
11
|
+
# String: must be valid file path
|
11
12
|
attr_reader :path
|
13
|
+
# String: file extension default: .EXAMPLE
|
12
14
|
attr_accessor :extension
|
15
|
+
# Bool: show all system commands run by ruby
|
13
16
|
attr_accessor :debug
|
14
17
|
|
15
18
|
# Arguments:
|
@@ -23,37 +26,63 @@ class FileManager
|
|
23
26
|
@extension = extension
|
24
27
|
@debug = debug
|
25
28
|
@no_output = no_output
|
29
|
+
@log_dir = "#{path}/.pipeline_logs"
|
30
|
+
@created_log_name = "created_files_"
|
31
|
+
|
32
|
+
unless File.directory?(@log_dir)
|
33
|
+
Dir.mkdir(@log_dir)
|
34
|
+
end
|
26
35
|
end
|
27
36
|
|
37
|
+
# get backup dates in order from newest to oldest
|
28
38
|
def get_all_backups()
|
29
39
|
backup_files = Dir.glob("#{@path}/**/*.backup*")
|
30
40
|
backup_numbers = backup_files.map {|x| x.split(".backup").last}
|
31
41
|
return backup_numbers.uniq.sort
|
32
42
|
end
|
33
43
|
|
34
|
-
#
|
35
|
-
|
36
|
-
def copy_example_files(command="cp")
|
37
|
-
puts("Setting up pipeline in #{@path}".yellow()) unless @no_output
|
44
|
+
# find all example files under @path
|
45
|
+
def get_all_example_files()
|
38
46
|
example_file_path = "#{@path}/**/*#{extension}"
|
39
47
|
example_files = Dir.glob(example_file_path)
|
40
48
|
if example_files.empty?
|
41
|
-
raise "No #{extension} Files found at #{example_file_path}"
|
49
|
+
raise ArgumentError.new("No #{extension} Files found at #{example_file_path}")
|
42
50
|
else
|
43
51
|
puts("Moving #{example_files.count} #{extension} files".green()) unless @no_output
|
44
52
|
end
|
53
|
+
return example_files
|
54
|
+
end
|
45
55
|
|
56
|
+
# read latest log in .pipeline_logs
|
57
|
+
# @return [String] files created by last setup_pipeline
|
58
|
+
def get_last_created_files()
|
59
|
+
logs = Dir.glob("#{@log_dir}/*")
|
60
|
+
if logs.empty?
|
61
|
+
raise ArgumentError.new("No logs found in #{@log_dir}")
|
62
|
+
end
|
63
|
+
log_numbers = logs.map {|x| x.split("#{@created_log_name}").last}
|
64
|
+
latest_log_number = log_numbers.uniq.sort.first
|
65
|
+
return File.readlines("#{@log_dir}/#{@created_log_name}#{latest_log_number}")
|
66
|
+
end
|
67
|
+
|
68
|
+
# Arguments:
|
69
|
+
# command: (string: system command)
|
70
|
+
def copy_example_files(command="cp")
|
71
|
+
time_stamp = Time.now.strftime("%Y%m%d%H%M")
|
72
|
+
puts("Setting up pipeline in #{@path}".yellow()) unless @no_output
|
73
|
+
example_files = get_all_example_files
|
46
74
|
files_to_backup = example_files.map {|f| f.gsub(@extension, "")}.select {|file| File.exists?(file) }
|
75
|
+
# raise ArgumentError.new("#{files_to_backup.to_s} #{example_files.to_s}")
|
76
|
+
|
47
77
|
if !files_to_backup.empty?
|
48
78
|
# 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
79
|
puts("Backing up #{files_to_backup.count} files".green()) unless @no_output
|
51
80
|
files_to_backup.each do |file_to_backup|
|
52
|
-
full_command = "#{command} #{file_to_backup} #{file_to_backup}.backup#{
|
81
|
+
full_command = "#{command} #{file_to_backup} #{file_to_backup}.backup#{time_stamp}"
|
53
82
|
puts("\t#{full_command}") if @debug
|
54
83
|
system(full_command)
|
55
84
|
end
|
56
|
-
end
|
85
|
+
end
|
57
86
|
|
58
87
|
example_files.each do |example_file|
|
59
88
|
target_file = example_file.gsub(@extension, "")
|
@@ -61,7 +90,13 @@ class FileManager
|
|
61
90
|
full_command = "#{command} #{example_file} #{target_file}"
|
62
91
|
puts("\t#{full_command}") if @debug
|
63
92
|
system(full_command)
|
93
|
+
|
94
|
+
if File.exists?(target_file)
|
95
|
+
add_to_log(target_file, time_stamp)
|
96
|
+
puts("\t add #{target_file} to log #{get_log_name(time_stamp)}") if @debug
|
97
|
+
end
|
64
98
|
end
|
99
|
+
|
65
100
|
end
|
66
101
|
|
67
102
|
# Arguments:
|
@@ -97,4 +132,13 @@ class FileManager
|
|
97
132
|
end
|
98
133
|
end
|
99
134
|
|
135
|
+
private
|
136
|
+
def get_log_name(date)
|
137
|
+
return "#{@log_dir}/#{@created_log_name}#{date}"
|
138
|
+
end
|
139
|
+
|
140
|
+
def add_to_log(line, date)
|
141
|
+
File.open(get_log_name(date), "a") {|file| file.write(line)}
|
142
|
+
end
|
143
|
+
|
100
144
|
end
|
@@ -12,42 +12,111 @@ class SetupPipeline
|
|
12
12
|
# Raises:
|
13
13
|
# ArgumentError if $1 is missing or is not a valid directory
|
14
14
|
|
15
|
-
|
15
|
+
# commands available from setup_pipeline (hash of proc)
|
16
|
+
attr_reader :commands
|
17
|
+
# custom error message for when dir is not provided as arg (string)
|
18
|
+
attr_reader :dir_error
|
19
|
+
|
20
|
+
# Set up class attributes
|
21
|
+
def initialize()
|
22
|
+
@commands = {
|
23
|
+
undo: Proc.new {|fm| fm.load_from_backup()},
|
24
|
+
show_last_created: Proc.new {|fm| puts(fm.get_last_created_files().to_s())},
|
25
|
+
}
|
26
|
+
|
27
|
+
@dir_error = "
|
28
|
+
The first argument to setup_pipeline must be a valid directory.
|
29
|
+
For example, setting up a pipeline in the current directory:
|
30
|
+
|
31
|
+
setup_pipeline $PWD
|
32
|
+
|
33
|
+
The exceptions to this are:\n
|
34
|
+
setup_pipeline --version
|
35
|
+
setup_pipeline --help
|
36
|
+
setup_pipeline --show-commands
|
37
|
+
setup_pipeline --show-flags
|
38
|
+
"
|
39
|
+
end
|
40
|
+
|
41
|
+
# simple formatter
|
42
|
+
def show_commands()
|
43
|
+
puts(@commands.keys)
|
44
|
+
end
|
45
|
+
|
46
|
+
# print help screen to console
|
47
|
+
def help(opts)
|
48
|
+
how_to_use = "HOW TO USE:\n
|
49
|
+
setup_pipeline $PWD
|
50
|
+
|
51
|
+
#{opts}
|
52
|
+
|
53
|
+
other commands:\n
|
54
|
+
#{@commands.keys}
|
55
|
+
|
56
|
+
"
|
57
|
+
|
58
|
+
errors = "COMMON ERRORS:\n
|
59
|
+
#{@dir_error}
|
60
|
+
"
|
61
|
+
|
62
|
+
docs = "FOR MORE INFORMATION PLEASE READ THE DOCS:\n
|
63
|
+
on bitbucket:\t\thttps://bitbucket.org/nlireland/nli-pipeline-gem\n
|
64
|
+
or on ruby gems:\t\thttps://rubygems.org/gems/nli_pipeline\n
|
65
|
+
"
|
66
|
+
|
67
|
+
puts("#{how_to_use}\n#{errors}\n#{docs}")
|
68
|
+
end
|
69
|
+
|
70
|
+
# parse flags (and check if first argument if not valid directory)
|
71
|
+
def parse_flags()
|
16
72
|
options = {}
|
17
73
|
OptionParser.new do |opts|
|
18
|
-
opts.on("-v", "--version") do |v|
|
19
|
-
puts NliPipeline::VERSION
|
20
|
-
# break out of function, don't throw exception about passing directory path
|
21
|
-
return false
|
22
|
-
end
|
23
74
|
opts.on("--extension=[\w+]") do |v|
|
24
75
|
options[:extension] = v
|
25
76
|
end
|
26
77
|
opts.on("--debug") do |v|
|
27
78
|
options[:debug] = v
|
28
79
|
end
|
80
|
+
|
81
|
+
# break out of function, don't throw exception about passing directory path
|
82
|
+
opts.on("-v", "--version") do |v|
|
83
|
+
puts NliPipeline::VERSION
|
84
|
+
return false
|
85
|
+
end
|
86
|
+
opts.on("--show-commands") do |v|
|
87
|
+
show_commands()
|
88
|
+
return false
|
89
|
+
end
|
90
|
+
opts.on("--show-flags") do |v|
|
91
|
+
puts(opts)
|
92
|
+
return false
|
93
|
+
end
|
94
|
+
opts.on("-h", "--help") do |v|
|
95
|
+
help(opts)
|
96
|
+
return false
|
97
|
+
end
|
29
98
|
end.parse!
|
30
99
|
|
31
100
|
if !ARGV[0] || !Dir.exist?(ARGV[0])
|
32
|
-
|
33
|
-
example = "For example, setting up a pipeline in the current directory: setup_pipeline $PWD"
|
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")
|
101
|
+
raise ArgumentError.new("\n\n#{@dir_error}\n\n")
|
36
102
|
else
|
37
103
|
return [ARGV[0], options]
|
38
104
|
end
|
39
105
|
end
|
40
106
|
|
41
107
|
# Method called by bin/setup_pipeline
|
42
|
-
#
|
108
|
+
# Parse commands (command line arguments) and pass flags / flags to parse_flags
|
109
|
+
# TODO: move undo arg handling to parse_flags?
|
43
110
|
def main()
|
44
|
-
|
45
|
-
|
46
|
-
|
111
|
+
flags = parse_flags()
|
112
|
+
|
113
|
+
if flags
|
114
|
+
dir, options = flags
|
47
115
|
# pass options hash as keyword arguments
|
48
116
|
fm = FileManager.new(dir, **options)
|
49
|
-
|
50
|
-
|
117
|
+
command = ARGV[1].to_sym unless ARGV[1].nil? || ARGV[1].empty?
|
118
|
+
if @commands.keys.include?(command)
|
119
|
+
@commands[command].call(fm)
|
51
120
|
else
|
52
121
|
fm.copy_example_files()
|
53
122
|
end
|
data/lib/nli_pipeline.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# used to defined constants and include requirements for /bin/setup_pipeline
|
1
2
|
module NliPipeline
|
2
3
|
|
3
4
|
# constant use in nli_pipeline.gemspec and bin/setup_pipeline
|
4
5
|
# to determine current version of gem
|
5
6
|
# should also match tag on bitbucket
|
6
|
-
VERSION = "0.1.
|
7
|
+
VERSION = "0.1.2"
|
7
8
|
|
8
9
|
require_relative 'nli_pipeline/file_manager'
|
9
10
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conor Sheehan
|
@@ -55,8 +55,10 @@ email: csheehan@nli.ie
|
|
55
55
|
executables:
|
56
56
|
- setup_pipeline
|
57
57
|
extensions: []
|
58
|
-
extra_rdoc_files:
|
58
|
+
extra_rdoc_files:
|
59
|
+
- History.txt
|
59
60
|
files:
|
61
|
+
- History.txt
|
60
62
|
- bin/setup_pipeline
|
61
63
|
- lib/nli_pipeline.rb
|
62
64
|
- lib/nli_pipeline/file_manager.rb
|