advance 0.1.13 → 0.2.0

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
- SHA1:
3
- metadata.gz: 6b4874cc32a71d6f9508975d5be54f4bf14ed6b3
4
- data.tar.gz: 105e62fdc6a1de857bd88b2d2d3d34766a96839a
2
+ SHA256:
3
+ metadata.gz: 842391aeff4f6050e96a64caee6e31d599d9052639936baab5f50acefcac976c
4
+ data.tar.gz: 1034ef6eb9ce638ca3ca484064fcfec2e0cfc6cae47383e467fc37526a10badf
5
5
  SHA512:
6
- metadata.gz: 82b976e4783a3fdaed9c0f1393f495f30c2e931208dc6e664783cc03eb4aab5dd437932a10b345ac4e17b868311db2d009f247b5261207a8f2735fed40d40ac5
7
- data.tar.gz: 88bc243a5d86c794c544b0a7faceae599bfb1dc669c383655f5ab8b5093e1c08842a45302d2fbd80c220019d6b41ef441df484508bf69fa3fb6382112dd5d745
6
+ metadata.gz: 6fb5dbf6d11989a1b7496ede0801fd8c43138194cf425cbbe5b7c05a9443c16f042e327348b19199458a50e4503b0033f55aaac2da79872fd3f7c19fbf057197
7
+ data.tar.gz: f19a3493ae52d4971fa907d736bcccaa2fd364e52814d55bfdf99ed0b679cd4438ff142904aef7d815f2201ef6581c9844ac742409b24175c61c67a1fccce48e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- advance (0.1.13)
4
+ advance (0.2.0)
5
5
  team_effort
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module Advance
2
- VERSION = "0.1.13"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/advance.rb CHANGED
@@ -1,5 +1,6 @@
1
- require "advance/version"
1
+ require_relative "./advance/version"
2
2
  require "find"
3
+ require "fileutils"
3
4
  require "open3"
4
5
  require "team_effort"
5
6
 
@@ -18,6 +19,8 @@ module Advance
18
19
  WHITE="\e[1;37m"
19
20
  YELLOW="\e[33m"
20
21
 
22
+ puts "loading module"
23
+
21
24
  def advance(processing_mode, label, command)
22
25
  $redo_mode ||= :checking
23
26
  $step ||= 0
@@ -32,7 +35,7 @@ module Advance
32
35
 
33
36
  clean_previous_step_dirs(dir_prefix)
34
37
 
35
- send(processing_mode, label, command, previous_dir_path, dir_prefix, dir_name)
38
+ send(processing_mode, command, previous_dir_path, dir_name)
36
39
  end
37
40
 
38
41
  def static(processing_mode, label, command)
@@ -46,7 +49,7 @@ module Advance
46
49
 
47
50
  FileUtils.rm_rf dir_name
48
51
 
49
- send(processing_mode, label, command, previous_dir_path, dir_prefix, dir_name)
52
+ send(processing_mode, command, previous_dir_path, dir_name)
50
53
  end
51
54
 
52
55
  def get_previous_dir_path
@@ -79,7 +82,7 @@ module Advance
79
82
  dirs.find { |d| d =~ /^#{dir_prefix}/ }
80
83
  end
81
84
 
82
- def single(label, command, previous_dir_path, dir_prefix, dir_name)
85
+ def single(command, previous_dir_path, dir_name)
83
86
  work_in_sub_dir(dir_name) do
84
87
  if command =~ /\{previous_file\}/
85
88
  command.gsub!("{previous_file}", previous_file_path(previous_dir_path))
@@ -94,7 +97,7 @@ module Advance
94
97
  end
95
98
  end
96
99
 
97
- def multi(label, command, previous_dir_path, dir_prefix, dir_name)
100
+ def multi(command, previous_dir_path, dir_name)
98
101
  no_feedback = false
99
102
  work_in_sub_dir(dir_name) do
100
103
  file_paths = Find.find(previous_dir_path).reject { |path| FileTest.directory?(path) || File.basename(path) == "log" }
@@ -108,8 +111,8 @@ module Advance
108
111
  TeamEffort.work(file_paths, $cores, progress_proc: progress_proc) do |file_path|
109
112
  begin
110
113
  file = File.basename(file_path)
111
- command.gsub!("{file_path}", file_path) unless $step == 1
112
- command.gsub!("{file}", file) unless $step == 1
114
+ command.gsub!("{file_path}", file_path)
115
+ command.gsub!("{file}", file)
113
116
  puts "#{YELLOW}#{command}#{RESET}"
114
117
  work_in_sub_dir(file) do
115
118
  do_command command, no_feedback
@@ -123,13 +126,14 @@ module Advance
123
126
  end
124
127
 
125
128
  def work_in_sub_dir(dir_name)
126
- if $redo_mode == :checking && Dir.exist?(dir_name)
129
+ stripped_dir_name = strip_extensions(dir_name)
130
+ if $redo_mode == :checking && Dir.exist?(stripped_dir_name)
127
131
  return
128
132
  end
129
133
 
130
134
  $redo_mode = :replacing
131
135
 
132
- tmp_dir_name = "tmp_#{dir_name}"
136
+ tmp_dir_name = "tmp_#{stripped_dir_name}"
133
137
  FileUtils.rm_rf tmp_dir_name
134
138
  FileUtils.mkdir_p tmp_dir_name
135
139
  FileUtils.cd tmp_dir_name
@@ -137,7 +141,31 @@ module Advance
137
141
  yield
138
142
 
139
143
  FileUtils.cd ".."
140
- FileUtils.mv tmp_dir_name, dir_name
144
+ FileUtils.mv tmp_dir_name, stripped_dir_name
145
+ end
146
+
147
+ def strip_extensions(dir_name)
148
+ extensions = %w(
149
+ csv
150
+ csv_nh
151
+ geo_json
152
+ geojson
153
+ gz
154
+ json
155
+ tar
156
+ tgz
157
+ zip
158
+ )
159
+
160
+ changed_dir_name = dir_name
161
+ last_dir_name = nil
162
+ until last_dir_name == changed_dir_name do
163
+ last_dir_name = changed_dir_name
164
+ extensions.each do |extension|
165
+ changed_dir_name = changed_dir_name.gsub(%r(\.#{extension}$), "")
166
+ end
167
+ end
168
+ changed_dir_name
141
169
  end
142
170
 
143
171
  def previous_file_path(previous_dir_path)
@@ -173,11 +201,6 @@ module Advance
173
201
  end
174
202
  end
175
203
 
176
- # def find_step_dir
177
- # dirs = Dir.entries(".")
178
- # dirs.find { |d| d =~ /^#{step_dir_prefix($step)}/ }
179
- # end
180
- #
181
204
  def ensure_bin_on_path
182
205
  advance_path = File.dirname(__FILE__)
183
206
  add_dir_to_path(advance_path)
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.13
4
+ version: 0.2.0
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-23 00:00:00.000000000 Z
11
+ date: 2019-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: team_effort
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project:
127
- rubygems_version: 2.4.8
127
+ rubygems_version: 2.7.8
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: A framework for building data transformation pipelines