advance 0.1.9 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 959278c59b5b2bf7bf45922583e0b368a56d14f8
4
- data.tar.gz: c87b409a2140fb5474e35035e7f3ff4bca1ac63f
3
+ metadata.gz: 42dc426c725cb4bda0ce5c03bade294c5f17fba2
4
+ data.tar.gz: 2d68640161cc0d5d453a206524b5d5790ca7451b
5
5
  SHA512:
6
- metadata.gz: b8ba0aff845359971f8431370692853692aea860a9c4c93631096edb0a88570024fa2eeb51ed1eceb8131fe07b1f141667bc9886720cad03ebe000c4666b5e9f
7
- data.tar.gz: 36c02b886fc17bc1dd4cd06f745cab82cd98b081bb3d291eb2b672ae91f8533edfefd6303a57fc223a00a5ddf8a0b4a2067e2763b9d01c3f071595376e3585a7
6
+ metadata.gz: 3a7b77e2d9f746a388fb794229132512cbf1333d69c8c6203fd1e1e83b3a7b9755fb2b9ce6f79b326a1a5a91c1083e95e679e58585db65b1e014843016620921
7
+ data.tar.gz: 39d2498042455ddec9a3a3cf056b2d092c146d565744343cbb670c8aec821ccbff4c93013f1ba4581fa52364f07691f53cfadf01984f7c3eff806df774262923
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- advance (0.1.9)
4
+ advance (0.1.12)
5
5
  team_effort
6
6
 
7
7
  GEM
data/lib/advance.rb CHANGED
@@ -18,112 +18,116 @@ module Advance
18
18
  WHITE="\e[1;37m"
19
19
  YELLOW="\e[33m"
20
20
 
21
- def do_command(command, feedback = true)
22
- puts "#{YELLOW}#{command}#{RESET} " if feedback
23
- start_time = Time.now
24
- stdout, stderr, status = Open3.capture3(command)
25
- elapsed_time = Time.now - start_time
26
- File.open("log", "w") do |f|
27
- f.puts "%%% command: >#{command}<"
28
- f.puts "%%% returned status: >#{status}<"
29
- f.puts "%%% elapsed time: #{elapsed_time} seconds"
30
- f.puts "%%% stdout:"
31
- f.puts stdout
32
- f.puts "%%% stderr:"
33
- f.puts stderr
34
- end
35
- if !status.success?
36
- raise "step #{$step} failed with #{status}\n#{stderr}"
37
- end
21
+ def advance(processing_mode, label, command)
22
+ $redo_mode ||= :checking
23
+ $step ||= 0
24
+ previous_dir_path = get_previous_dir_path
25
+
26
+ $step += 1
27
+ dir_prefix = step_dir_prefix($step)
28
+ dir_name = "#{dir_prefix}_#{label}"
29
+
30
+ puts "#{CYAN}advance #{$step} #{label}#{WHITE}... #{RESET}"
31
+ return if $redo_mode == :checking && Dir.exist?(dir_name)
32
+
33
+ clean_previous_step_dirs(dir_prefix)
34
+
35
+ send(processing_mode, label, command, previous_dir_path, dir_prefix, dir_name)
38
36
  end
39
37
 
40
- def previous_dir_path
38
+ def static(processing_mode, label, command)
39
+ $redo_mode ||= :checking
40
+ $step ||= 0
41
+ previous_dir_path = get_previous_dir_path
42
+ dir_prefix = static_dir_prefix($step)
43
+ dir_name = "#{dir_prefix}_#{label}"
44
+ puts "#{CYAN}static #{$step} #{label}#{WHITE}... #{RESET}"
45
+ return if $redo_mode == :checking && Dir.exist?(dir_name)
46
+
47
+ FileUtils.rm_rf dir_name
48
+
49
+ send(processing_mode, label, command, previous_dir_path, dir_prefix, dir_name)
50
+ end
51
+
52
+ def get_previous_dir_path
41
53
  relative_path = case $step
42
- when 1
43
- ".."
54
+ when 0
55
+ "."
44
56
  else
45
- File.join("..", Dir.entries("..").find { |d| d =~ /^#{step_dir_prefix($step - 1)}/ })
57
+ File.join(".", Dir.entries(".").find { |d| d =~ /^#{step_dir_prefix($step)}/ })
46
58
  end
47
59
  File.expand_path(relative_path)
48
60
  end
49
61
 
50
- def previous_file_path
51
- Find.find(previous_dir_path).reject { |p| FileTest.directory?(p) || File.basename(p) == "log" }.first
62
+ def step_dir_prefix(step_no)
63
+ "step_%03d" % [step_no]
52
64
  end
53
65
 
54
- def single(label, command)
55
- step(label) do
66
+ def static_dir_prefix(step_no)
67
+ "static_%03d" % [step_no]
68
+ end
69
+
70
+ def clean_previous_step_dirs(dir_prefix)
71
+ while (step_dir = find_step_dir(dir_prefix))
72
+ puts "## removing #{step_dir}"
73
+ FileUtils.rm_rf step_dir
74
+ end
75
+ end
76
+
77
+ def find_step_dir(dir_prefix)
78
+ dirs = Dir.entries(".")
79
+ dirs.find { |d| d =~ /^#{dir_prefix}/ }
80
+ end
81
+
82
+ def single(label, command, previous_dir_path, dir_prefix, dir_name)
83
+ work_in_sub_dir(dir_name) do
56
84
  if command =~ /\{previous_file\}/
57
- command.gsub!("{previous_file}", previous_file_path)
85
+ command.gsub!("{previous_file}", previous_file_path(previous_dir_path))
58
86
  end
59
87
  if command =~ /\{previous_dir\}/
60
88
  command.gsub!("{previous_dir}", previous_dir_path)
61
89
  end
62
90
  if command =~ /\{file\}/
63
- command.gsub!("{file}", File.basename(previous_file_path))
91
+ command.gsub!("{file}", File.basename(previous_file_path(previous_dir_path)))
64
92
  end
65
93
  do_command command
66
94
  end
67
95
  end
68
96
 
69
- def multi(label, command)
97
+ def multi(label, command, previous_dir_path, dir_prefix, dir_name)
70
98
  no_feedback = false
71
- step(label) do
72
- # previous_dir_path = File.expand_path(previous_dir_path)
73
- files = Dir.entries(previous_dir_path).reject { |f| f =~ %r{^(\.\.?|log)$} }
74
- file_path_template = file_path_template(previous_dir_path, files)
99
+ work_in_sub_dir(dir_name) do
100
+ file_paths = Find.find(previous_dir_path).reject { |path| FileTest.directory?(path) || path =~ %r{^(log)$} }
101
+
75
102
  last_progress = ""
76
103
  progress_proc = ->(index, max_index) do
77
104
  latest_progress = sprintf("%3i%", index.to_f / max_index * 100)
78
105
  puts latest_progress if last_progress != latest_progress
79
106
  last_progress = latest_progress
80
107
  end
81
- TeamEffort.work(files, $cores, progress_proc: progress_proc) do |file|
108
+ TeamEffort.work(file_paths, $cores, progress_proc: progress_proc) do |file_path|
82
109
  begin
83
- previous_file_path = file_path_template.gsub("{file}", file)
84
- command.gsub!("{file_path}", previous_file_path) unless $step == 1
110
+ file = File.basename(file_path)
111
+ command.gsub!("{file_path}", file_path) unless $step == 1
85
112
  command.gsub!("{file}", file) unless $step == 1
86
113
  puts "#{YELLOW}#{command}#{RESET}"
87
- dir_name = file
88
- work_in_sub_dir(dir_name) do
114
+ work_in_sub_dir(file) do
89
115
  do_command command, no_feedback
90
116
  end
91
117
  rescue
92
- puts "%%%% error while processing >>#{file}<<"
118
+ puts "%%%% error while processing >>#{file_path}<<"
93
119
  raise
94
120
  end
95
121
  end
96
122
  end
97
123
  end
98
124
 
99
- def file_path_template(dir_path, files)
100
- file = files.first
101
- file_path = File.join(dir_path, file)
102
- if File.directory?(file_path)
103
- File.join(dir_path, "{file}", "{file}")
104
- else
105
- File.join(dir_path, "{file}")
106
- end
107
- end
108
-
109
- def find_step_dir
110
- dirs = Dir.entries(".")
111
- dirs.find { |d| d =~ /^#{step_dir_prefix($step)}/ }
112
- end
113
-
114
- def clean_previous_step_dirs
115
- while (step_dir = find_step_dir)
116
- puts "## removing #{step_dir}"
117
- FileUtils.rm_rf step_dir
118
- end
119
- end
120
-
121
- def work_in_sub_dir(dir_name, existing_message = nil)
125
+ def work_in_sub_dir(dir_name)
122
126
  if $redo_mode == :checking && Dir.exist?(dir_name)
123
- return :checking
127
+ return
124
128
  end
125
129
 
126
- clean_previous_step_dirs
130
+ $redo_mode = :replacing
127
131
 
128
132
  tmp_dir_name = "tmp_#{dir_name}"
129
133
  FileUtils.rm_rf tmp_dir_name
@@ -134,26 +138,46 @@ module Advance
134
138
 
135
139
  FileUtils.cd ".."
136
140
  FileUtils.mv tmp_dir_name, dir_name
137
- :replacing
138
141
  end
139
142
 
140
- def step_dir_prefix(step_no)
141
- "step_%03d" % [step_no]
143
+ def previous_file_path(previous_dir_path)
144
+ Find.find(previous_dir_path).reject { |p| FileTest.directory?(p) || File.basename(p) == "log" }.first
142
145
  end
143
146
 
144
- def step(label)
145
- $redo_mode ||= :checking
146
- $step ||= 0
147
- $step += 1
148
- dir_name = "#{step_dir_prefix($step)}_#{label}"
149
- $previous_dir = File.join(FileUtils.pwd, dir_name)
150
- puts "#{CYAN}step #{$step} #{label}#{WHITE}... #{RESET}"
147
+ def file_path_template(dir_path, files)
148
+ file = files.first
149
+ file_path = File.join(dir_path, file)
150
+ if File.directory?(file_path)
151
+ File.join(dir_path, "{file}", "{file}")
152
+ else
153
+ File.join(dir_path, "{file}")
154
+ end
155
+ end
151
156
 
152
- $redo_mode = work_in_sub_dir(dir_name, "#{GREEN}OK#{RESET}") do
153
- yield
157
+ def do_command(command, feedback = true)
158
+ puts "#{YELLOW}#{command}#{RESET} " if feedback
159
+ start_time = Time.now
160
+ stdout, stderr, status = Open3.capture3(command)
161
+ elapsed_time = Time.now - start_time
162
+ File.open("log", "w") do |f|
163
+ f.puts "%%% command: >#{command}<"
164
+ f.puts "%%% returned status: >#{status}<"
165
+ f.puts "%%% elapsed time: #{elapsed_time} seconds"
166
+ f.puts "%%% stdout:"
167
+ f.puts stdout
168
+ f.puts "%%% stderr:"
169
+ f.puts stderr
170
+ end
171
+ if !status.success?
172
+ raise "step #{$step} failed with #{status}\n#{stderr}"
154
173
  end
155
174
  end
156
175
 
176
+ # def find_step_dir
177
+ # dirs = Dir.entries(".")
178
+ # dirs.find { |d| d =~ /^#{step_dir_prefix($step)}/ }
179
+ # end
180
+ #
157
181
  def ensure_bin_on_path
158
182
  advance_path = File.dirname(__FILE__)
159
183
  add_dir_to_path(advance_path)
@@ -1,3 +1,3 @@
1
1
  module Advance
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - janemacfarlane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-21 00:00:00.000000000 Z
11
+ date: 2019-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: team_effort