spout 0.14.0.beta1 → 0.14.0.beta2
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/CHANGELOG.md +1 -0
- data/README.md +2 -2
- data/lib/spout/color.rb +100 -0
- data/lib/spout/commands/deploy.rb +43 -44
- data/lib/spout/commands/exporter.rb +2 -3
- data/lib/spout/commands/graphs.rb +2 -3
- data/lib/spout/commands/help.rb +0 -2
- data/lib/spout/commands/importer.rb +14 -15
- data/lib/spout/commands/project_generator.rb +1 -2
- data/lib/spout/commands/update.rb +12 -13
- data/lib/spout/helpers/framework.rb +3 -4
- data/lib/spout/helpers/json_request.rb +3 -3
- data/lib/spout/helpers/subject_loader.rb +6 -7
- data/lib/spout/templates/test/dictionary_test.rb +2 -2
- data/lib/spout/tests.rb +5 -12
- data/lib/spout/version.rb +1 -1
- data/lib/spout.rb +1 -0
- data/spout.gemspec +0 -1
- metadata +2 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18d01986890a2541efb2384e382e786959e53618c65f5dbe5f75ac8ee0dd7e68
|
4
|
+
data.tar.gz: a2ea53c30b10f2f6a756a5ee8452bb9417ac7d8b5571f91fedf654a9eaa89914
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e1a15e77e49767460be60264678e25629c35f904bb080fb744bbe3da423fe8f338d358d7aa77b30951f436d8abcc5f894e6bbe503d5a9b2991087736150497f
|
7
|
+
data.tar.gz: 68e75df0a0ebbdfeb9d15f08ecb2ae86591512bd3f4babd4ea4512a17fc161fc253ffbdc7678727bf1ae78416497117b7659e3160700daa839d7a07967b490d3
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
- **Framework Changes**
|
5
5
|
- Spout data dictionaries can now specify gem dependencies using `gems.rb`
|
6
6
|
instead of `Gemfile`
|
7
|
+
- Removed dependency on colorize gem
|
7
8
|
- **Test Changes**
|
8
9
|
- Improved the spout testing framework
|
9
10
|
- Tests are now run excusively using `spout t` command
|
data/README.md
CHANGED
@@ -188,9 +188,9 @@ class DictionaryTest < Minitest::Test
|
|
188
188
|
|
189
189
|
@variables.select { |v| %w(numeric integer).include?(v.type) }.each do |variable|
|
190
190
|
define_method("test_units: #{variable.path}") do
|
191
|
-
message = "\"#{variable.units}\"".
|
191
|
+
message = "\"#{variable.units}\"".red + " invalid units.\n" +
|
192
192
|
" Valid types: " +
|
193
|
-
VALID_UNITS.sort_by(&:to_s).collect { |u| u.inspect.
|
193
|
+
VALID_UNITS.sort_by(&:to_s).collect { |u| u.inspect.white }.join(", ")
|
194
194
|
assert VALID_UNITS.include?(variable.units), message
|
195
195
|
end
|
196
196
|
end
|
data/lib/spout/color.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Adds ANSI colors to string class.
|
4
|
+
class String
|
5
|
+
def black
|
6
|
+
"\e[30m#{self}\e[0m"
|
7
|
+
end
|
8
|
+
|
9
|
+
def red
|
10
|
+
"\e[31m#{self}\e[0m"
|
11
|
+
end
|
12
|
+
|
13
|
+
def green
|
14
|
+
"\e[32m#{self}\e[0m"
|
15
|
+
end
|
16
|
+
|
17
|
+
def brown
|
18
|
+
"\e[33m#{self}\e[0m"
|
19
|
+
end
|
20
|
+
|
21
|
+
def yellow
|
22
|
+
brown
|
23
|
+
end
|
24
|
+
|
25
|
+
def blue
|
26
|
+
"\e[34m#{self}\e[0m"
|
27
|
+
end
|
28
|
+
|
29
|
+
def magenta
|
30
|
+
"\e[35m#{self}\e[0m"
|
31
|
+
end
|
32
|
+
|
33
|
+
def cyan
|
34
|
+
"\e[36m#{self}\e[0m"
|
35
|
+
end
|
36
|
+
|
37
|
+
def gray
|
38
|
+
"\e[37m#{self}\e[0m"
|
39
|
+
end
|
40
|
+
|
41
|
+
def white
|
42
|
+
"\e[39m#{bold}\e[0m"
|
43
|
+
end
|
44
|
+
|
45
|
+
def bg_black
|
46
|
+
"\e[40m#{self}\e[0m"
|
47
|
+
end
|
48
|
+
|
49
|
+
def bg_red
|
50
|
+
"\e[41m#{self}\e[0m"
|
51
|
+
end
|
52
|
+
|
53
|
+
def bg_green
|
54
|
+
"\e[42m#{self}\e[0m"
|
55
|
+
end
|
56
|
+
|
57
|
+
def bg_brown
|
58
|
+
"\e[43m#{self}\e[0m"
|
59
|
+
end
|
60
|
+
|
61
|
+
def bg_blue
|
62
|
+
"\e[44m#{self}\e[0m"
|
63
|
+
end
|
64
|
+
|
65
|
+
def bg_magenta
|
66
|
+
"\e[45m#{self}\e[0m"
|
67
|
+
end
|
68
|
+
|
69
|
+
def bg_cyan
|
70
|
+
"\e[46m#{self}\e[0m"
|
71
|
+
end
|
72
|
+
|
73
|
+
def bg_gray
|
74
|
+
"\e[47m#{self}\e[0m"
|
75
|
+
end
|
76
|
+
|
77
|
+
def bold
|
78
|
+
"\e[1m#{self}\e[22m"
|
79
|
+
end
|
80
|
+
|
81
|
+
def italic
|
82
|
+
"\e[3m#{self}\e[23m"
|
83
|
+
end
|
84
|
+
|
85
|
+
def underline
|
86
|
+
"\e[4m#{self}\e[24m"
|
87
|
+
end
|
88
|
+
|
89
|
+
def blink
|
90
|
+
"\e[5m#{self}\e[25m"
|
91
|
+
end
|
92
|
+
|
93
|
+
def reverse_color
|
94
|
+
"\e[7m#{self}\e[27m"
|
95
|
+
end
|
96
|
+
|
97
|
+
def colorless
|
98
|
+
gsub(/\e\[\d{1,2}m/, "")
|
99
|
+
end
|
100
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "colorize"
|
4
3
|
require "net/http"
|
5
4
|
require "io/console"
|
6
5
|
|
@@ -77,7 +76,7 @@ module Spout
|
|
77
76
|
begin
|
78
77
|
run_all
|
79
78
|
rescue Interrupt
|
80
|
-
puts "\nINTERRUPTED".
|
79
|
+
puts "\nINTERRUPTED".red
|
81
80
|
end
|
82
81
|
end
|
83
82
|
|
@@ -104,21 +103,21 @@ module Spout
|
|
104
103
|
@slug = @config.slug
|
105
104
|
|
106
105
|
if @slug == ""
|
107
|
-
message = "#{INDENT}Please specify a dataset slug in your `.spout.yml` file!".
|
106
|
+
message = "#{INDENT}Please specify a dataset slug in your `.spout.yml` file!".red + " Ex:\n---\nslug: mydataset\n".gray
|
108
107
|
failure(message)
|
109
108
|
end
|
110
109
|
|
111
110
|
if @config.webservers.empty?
|
112
|
-
message = "#{INDENT}Please specify a webserver in your `.spout.yml` file!".
|
111
|
+
message = "#{INDENT}Please specify a webserver in your `.spout.yml` file!".red + " Ex:\n---\nwebservers:\n - name: production\n url: https://sleepdata.org\n - name: staging\n url: https://staging.sleepdata.org\n".gray
|
113
112
|
failure(message)
|
114
113
|
end
|
115
114
|
|
116
115
|
matching_webservers = @config.webservers.select { |wh| /^#{@environment}/i =~ wh["name"].to_s.downcase }
|
117
116
|
if matching_webservers.count == 0
|
118
|
-
message = "#{INDENT}0 webservers match '#{@environment}'.".
|
117
|
+
message = "#{INDENT}0 webservers match '#{@environment}'.".red + " The following webservers exist in your `.spout.yml` file:\n" + "#{INDENT}#{@config.webservers.collect{|wh| wh['name'].to_s.downcase}.join(', ')}".white
|
119
118
|
failure(message)
|
120
119
|
elsif matching_webservers.count > 1
|
121
|
-
message = "#{INDENT}#{matching_webservers.count} webservers match '#{@environment}'.".
|
120
|
+
message = "#{INDENT}#{matching_webservers.count} webservers match '#{@environment}'.".red + " Did you mean one of the following?\n" + "#{INDENT}#{matching_webservers.collect{|wh| wh['name'].to_s.downcase}.join(', ')}".white
|
122
121
|
failure(message)
|
123
122
|
end
|
124
123
|
|
@@ -126,13 +125,13 @@ module Spout
|
|
126
125
|
@url = URI.parse(matching_webservers.first["url"].to_s.strip) rescue @url = nil
|
127
126
|
|
128
127
|
if @url.to_s == ""
|
129
|
-
message = "#{INDENT}Invalid URL format for #{matching_webservers.first['name'].to_s.strip.downcase} webserver: ".
|
128
|
+
message = "#{INDENT}Invalid URL format for #{matching_webservers.first['name'].to_s.strip.downcase} webserver: ".red + "'#{matching_webservers.first['url'].to_s.strip}'".white
|
130
129
|
failure(message)
|
131
130
|
end
|
132
131
|
|
133
|
-
puts "PASS".
|
134
|
-
puts " Target Server: " + "#{@url}".
|
135
|
-
puts " Target Dataset: " + "#{@slug}".
|
132
|
+
puts "PASS".green
|
133
|
+
puts " Target Server: " + "#{@url}".white
|
134
|
+
puts " Target Dataset: " + "#{@slug}".white
|
136
135
|
end
|
137
136
|
|
138
137
|
# - **Version Check**
|
@@ -141,7 +140,7 @@ module Spout
|
|
141
140
|
# - "v#{VERSION}" matches HEAD git tag annotation
|
142
141
|
def version_check
|
143
142
|
if @skip_checks
|
144
|
-
puts " Version Check: " + "SKIP".
|
143
|
+
puts " Version Check: " + "SKIP".blue
|
145
144
|
return
|
146
145
|
end
|
147
146
|
|
@@ -151,19 +150,19 @@ module Spout
|
|
151
150
|
|
152
151
|
print " Git Status Check: "
|
153
152
|
if stdout.to_s.strip == ""
|
154
|
-
puts "PASS".
|
153
|
+
puts "PASS".green + " " + "nothing to commit, working directory clean".white
|
155
154
|
else
|
156
|
-
message = "#{INDENT}working directory contains uncomitted changes\n#{INDENT}use `".
|
155
|
+
message = "#{INDENT}working directory contains uncomitted changes\n#{INDENT}use `".red + "--skip-checks".white + "` to ignore this step".red
|
157
156
|
failure message
|
158
157
|
end
|
159
158
|
|
160
159
|
changelog = File.open("CHANGELOG.md", &:readline).strip rescue changelog = ""
|
161
160
|
if changelog.match(/^## #{@version.split('.')[0..2].join('.')}/)
|
162
|
-
puts " CHANGELOG.md: " + "PASS".
|
161
|
+
puts " CHANGELOG.md: " + "PASS".green + " " + changelog.white
|
163
162
|
else
|
164
163
|
print " CHANGELOG.md: "
|
165
|
-
message = "#{INDENT}Expected: ".
|
166
|
-
"\n#{INDENT} Actual: ".
|
164
|
+
message = "#{INDENT}Expected: ".red + "## #{@version}".white +
|
165
|
+
"\n#{INDENT} Actual: ".red + changelog.white
|
167
166
|
failure message
|
168
167
|
end
|
169
168
|
|
@@ -174,16 +173,16 @@ module Spout
|
|
174
173
|
print " Version Check: "
|
175
174
|
tag = stdout.to_s.strip
|
176
175
|
if "v#{@version}" != tag
|
177
|
-
message = "#{INDENT}Version specified in `VERSION` file ".
|
176
|
+
message = "#{INDENT}Version specified in `VERSION` file ".red + "'v#{@version}'".white + " does not match git tag on HEAD commit ".red + "'#{tag}'".white
|
178
177
|
failure message
|
179
178
|
else
|
180
|
-
puts "PASS".
|
179
|
+
puts "PASS".green + " VERSION " + "'v#{@version}'".white + " matches git tag " + "'#{tag}'".white
|
181
180
|
end
|
182
181
|
end
|
183
182
|
|
184
183
|
def test_check
|
185
184
|
if @skip_tests
|
186
|
-
puts " Spout Tests: " + "SKIP".
|
185
|
+
puts " Spout Tests: " + "SKIP".blue
|
187
186
|
return
|
188
187
|
end
|
189
188
|
|
@@ -194,31 +193,31 @@ module Spout
|
|
194
193
|
end
|
195
194
|
|
196
195
|
if stdout.match(/[^\d]0 failures, 0 errors,/)
|
197
|
-
puts "PASS".
|
196
|
+
puts "PASS".green
|
198
197
|
else
|
199
|
-
message = "#{INDENT}spout t".
|
198
|
+
message = "#{INDENT}spout t".white + " had errors or failures".red + "\n#{INDENT}Please fix all errors and failures and then run spout deploy again."
|
200
199
|
failure message
|
201
200
|
end
|
202
201
|
end
|
203
202
|
|
204
203
|
def coverage_check
|
205
204
|
if @skip_coverage
|
206
|
-
puts " Dataset Coverage: " + "SKIP".
|
205
|
+
puts " Dataset Coverage: " + "SKIP".blue
|
207
206
|
return
|
208
207
|
end
|
209
208
|
|
210
|
-
puts " Dataset Coverage: " + "NOT IMPLEMENTED".
|
209
|
+
puts " Dataset Coverage: " + "NOT IMPLEMENTED".yellow
|
211
210
|
end
|
212
211
|
|
213
212
|
def user_authorization
|
214
|
-
puts " Get your token here: " + "#{@url}/token".
|
213
|
+
puts " Get your token here: " + "#{@url}/token".blue.bg_gray.underline
|
215
214
|
print " Enter your token: "
|
216
215
|
@token = STDIN.noecho(&:gets).chomp if @token.to_s.strip == ""
|
217
216
|
(json, _status) = Spout::Helpers::JsonRequest.get("#{@url}/datasets/#{@slug}/a/#{@token}/editor.json")
|
218
217
|
if json.is_a?(Hash) && json["editor"]
|
219
|
-
puts "AUTHORIZED".
|
218
|
+
puts "AUTHORIZED".green
|
220
219
|
else
|
221
|
-
puts "UNAUTHORIZED".
|
220
|
+
puts "UNAUTHORIZED".red
|
222
221
|
puts "#{INDENT}You are not set as an editor on the #{@slug} dataset or you mistyped your token."
|
223
222
|
raise DeployError
|
224
223
|
end
|
@@ -226,7 +225,7 @@ module Spout
|
|
226
225
|
|
227
226
|
def upload_variables
|
228
227
|
if @skip_variables
|
229
|
-
puts " Upload Variables: " + "SKIP".
|
228
|
+
puts " Upload Variables: " + "SKIP".blue
|
230
229
|
return
|
231
230
|
end
|
232
231
|
load_subjects_from_csvs
|
@@ -246,12 +245,12 @@ module Spout
|
|
246
245
|
require "spout/commands/graphs"
|
247
246
|
@argv << "--clean" if @clean
|
248
247
|
Spout::Commands::Graphs.new(@argv, @version, true, @url, @slug, @token, @webserver_name, @subjects)
|
249
|
-
puts "\r Upload Variables: " + "DONE ".
|
248
|
+
puts "\r Upload Variables: " + "DONE ".green
|
250
249
|
end
|
251
250
|
|
252
251
|
def dataset_uploads
|
253
252
|
if @skip_dataset
|
254
|
-
puts " Dataset Uploads: " + "SKIP".
|
253
|
+
puts " Dataset Uploads: " + "SKIP".blue
|
255
254
|
return
|
256
255
|
end
|
257
256
|
|
@@ -261,7 +260,7 @@ module Spout
|
|
261
260
|
csv_files = Dir.glob("csvs/#{csv_directory}/**/*.csv")
|
262
261
|
|
263
262
|
csv_files.each_with_index do |csv_file, index|
|
264
|
-
print "\r Dataset Uploads: " + "#{index + 1} of #{csv_files.count}".
|
263
|
+
print "\r Dataset Uploads: " + "#{index + 1} of #{csv_files.count}".green
|
265
264
|
folder = csv_file.gsub(%r{^csvs/#{csv_directory}}, "").gsub(/#{File.basename(csv_file)}$/, "")
|
266
265
|
folder = folder.gsub(%r{/$}, "")
|
267
266
|
@created_folders << "datasets#{folder}"
|
@@ -270,12 +269,12 @@ module Spout
|
|
270
269
|
upload_file(csv_file, "datasets#{folder}") unless @archive_only
|
271
270
|
upload_file(csv_file, "datasets/archive/#{@version}#{folder}")
|
272
271
|
end
|
273
|
-
puts "\r Dataset Uploads: " + "DONE ".
|
272
|
+
puts "\r Dataset Uploads: " + "DONE ".green
|
274
273
|
end
|
275
274
|
|
276
275
|
def data_dictionary_uploads
|
277
276
|
if @skip_dictionary
|
278
|
-
puts " Dictionary Uploads: " + "SKIP".
|
277
|
+
puts " Dictionary Uploads: " + "SKIP".blue
|
279
278
|
return
|
280
279
|
end
|
281
280
|
|
@@ -286,38 +285,38 @@ module Spout
|
|
286
285
|
|
287
286
|
csv_files = Dir.glob("exports/#{@version}/*.csv")
|
288
287
|
csv_files.each_with_index do |csv_file, index|
|
289
|
-
print "\r Dictionary Uploads: " + "#{index + 1} of #{csv_files.count}".
|
288
|
+
print "\r Dictionary Uploads: " + "#{index + 1} of #{csv_files.count}".green
|
290
289
|
@created_folders << "datasets"
|
291
290
|
@created_folders << "datasets/archive"
|
292
291
|
@created_folders << "datasets/archive/#{@version}"
|
293
292
|
upload_file(csv_file, "datasets") unless @archive_only
|
294
293
|
upload_file(csv_file, "datasets/archive/#{@version}")
|
295
294
|
end
|
296
|
-
puts "\r Dictionary Uploads: " + "DONE ".
|
295
|
+
puts "\r Dictionary Uploads: " + "DONE ".green
|
297
296
|
end
|
298
297
|
|
299
298
|
def markdown_uploads
|
300
299
|
if @skip_documentation
|
301
|
-
puts "Documentation Uploads: " + "SKIP".
|
300
|
+
puts "Documentation Uploads: " + "SKIP".blue
|
302
301
|
return
|
303
302
|
end
|
304
303
|
|
305
304
|
print "Documentation Uploads:"
|
306
305
|
markdown_files = Dir.glob(%w(CHANGELOG.md KNOWNISSUES.md))
|
307
306
|
markdown_files.each_with_index do |markdown_file, index|
|
308
|
-
print "\rDocumentation Uploads: " + "#{index + 1} of #{markdown_files.count}".
|
307
|
+
print "\rDocumentation Uploads: " + "#{index + 1} of #{markdown_files.count}".green
|
309
308
|
@created_folders << "datasets"
|
310
309
|
@created_folders << "datasets/archive"
|
311
310
|
@created_folders << "datasets/archive/#{@version}"
|
312
311
|
upload_file(markdown_file, "datasets") unless @archive_only
|
313
312
|
upload_file(markdown_file, "datasets/archive/#{@version}")
|
314
313
|
end
|
315
|
-
puts "\rDocumentation Uploads: " + "DONE ".
|
314
|
+
puts "\rDocumentation Uploads: " + "DONE ".green
|
316
315
|
end
|
317
316
|
|
318
317
|
def trigger_server_updates
|
319
318
|
if @skip_server_scripts
|
320
|
-
puts "Launch Server Scripts: " + "SKIP".
|
319
|
+
puts "Launch Server Scripts: " + "SKIP".blue
|
321
320
|
return
|
322
321
|
end
|
323
322
|
|
@@ -325,16 +324,16 @@ module Spout
|
|
325
324
|
params = { auth_token: @token, dataset: @slug, version: @version, folders: @created_folders.compact.uniq }
|
326
325
|
(json, _status) = Spout::Helpers::JsonRequest.post("#{@url}/api/v1/dictionary/refresh.json", params)
|
327
326
|
if json.is_a?(Hash) && json["refresh"] == "success"
|
328
|
-
puts "DONE".
|
327
|
+
puts "DONE".green
|
329
328
|
else
|
330
|
-
puts "FAIL".
|
329
|
+
puts "FAIL".red
|
331
330
|
raise DeployError
|
332
331
|
end
|
333
332
|
end
|
334
333
|
|
335
334
|
def set_default_dataset_version
|
336
335
|
if @archive_only
|
337
|
-
puts " Set Default Version: " + "SKIP".
|
336
|
+
puts " Set Default Version: " + "SKIP".blue
|
338
337
|
return
|
339
338
|
end
|
340
339
|
print " Set Default Version: "
|
@@ -343,14 +342,14 @@ module Spout
|
|
343
342
|
"#{@url}/api/v1/dictionary/update_default_version.json", params
|
344
343
|
)
|
345
344
|
if json.is_a?(Hash) && json["version_update"] == "success"
|
346
|
-
puts @version.to_s.
|
345
|
+
puts @version.to_s.green
|
347
346
|
else
|
348
|
-
failure("#{INDENT}Unable to set default version\n#{INDENT}to " + @version.to_s.
|
347
|
+
failure("#{INDENT}Unable to set default version\n#{INDENT}to " + @version.to_s.white + " for " + @slug.to_s.white + " dataset.")
|
349
348
|
end
|
350
349
|
end
|
351
350
|
|
352
351
|
def failure(message)
|
353
|
-
puts "FAIL".
|
352
|
+
puts "FAIL".red
|
354
353
|
puts message
|
355
354
|
raise DeployError
|
356
355
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
require "csv"
|
4
4
|
require "json"
|
5
5
|
require "fileutils"
|
6
|
-
require "colorize"
|
7
6
|
|
8
7
|
require "spout/helpers/config_reader"
|
9
8
|
|
@@ -22,7 +21,7 @@ module Spout
|
|
22
21
|
|
23
22
|
def expanded_export!
|
24
23
|
folder = "exports/#{@standard_version}"
|
25
|
-
puts " create".
|
24
|
+
puts " create".green + " #{folder}" unless @quiet
|
26
25
|
FileUtils.mkpath folder
|
27
26
|
generic_export(
|
28
27
|
folder,
|
@@ -38,7 +37,7 @@ module Spout
|
|
38
37
|
|
39
38
|
def generic_export(folder, type, keys, include_domain_name = false)
|
40
39
|
export_file = export_file_name(type)
|
41
|
-
puts " export".
|
40
|
+
puts " export".blue + " #{folder}/#{export_file}" unless @quiet
|
42
41
|
CSV.open("#{folder}/#{export_file}", "wb") do |csv|
|
43
42
|
csv << if include_domain_name
|
44
43
|
%w(folder domain_id) + keys
|
@@ -5,7 +5,6 @@ require "fileutils"
|
|
5
5
|
require "rubygems"
|
6
6
|
require "json"
|
7
7
|
require "yaml"
|
8
|
-
require "colorize"
|
9
8
|
|
10
9
|
require "spout/helpers/subject_loader"
|
11
10
|
require "spout/helpers/chart_types"
|
@@ -109,7 +108,7 @@ module Spout
|
|
109
108
|
next unless Spout::Models::Subject.method_defined?(variable.id)
|
110
109
|
|
111
110
|
if @deploy_mode
|
112
|
-
print "\r Upload Variables: " + "#{"% 3d" % ((file_index+1)*100/variable_files_count)}% Uploaded".
|
111
|
+
print "\r Upload Variables: " + "#{"% 3d" % ((file_index+1)*100/variable_files_count)}% Uploaded".white
|
113
112
|
else
|
114
113
|
puts "#{file_index + 1} of #{variable_files_count}: #{variable.folder}#{variable.id}"
|
115
114
|
end
|
@@ -180,7 +179,7 @@ module Spout
|
|
180
179
|
if json.is_a?(Hash) && status.is_a?(Net::HTTPSuccess)
|
181
180
|
@progress[variable.id]["uploaded"] << @webserver_name
|
182
181
|
else
|
183
|
-
puts "\nUPLOAD FAILED: ".
|
182
|
+
puts "\nUPLOAD FAILED: ".red + variable.id
|
184
183
|
puts "- Error: #{json.inspect}"
|
185
184
|
end
|
186
185
|
end
|
data/lib/spout/commands/help.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require "json"
|
4
4
|
require "fileutils"
|
5
|
-
require "colorize"
|
6
5
|
|
7
6
|
require "spout/helpers/csv_reader"
|
8
7
|
|
@@ -41,7 +40,7 @@ EOT
|
|
41
40
|
def import_variables
|
42
41
|
Spout::Helpers::CSVReader.read_csv(@csv_file) do |row|
|
43
42
|
if not row.keys.include?("id")
|
44
|
-
puts "\nMissing column header `".
|
43
|
+
puts "\nMissing column header `".red + "id".cyan + "` in data dictionary.".red + additional_csv_info
|
45
44
|
exit(1)
|
46
45
|
end
|
47
46
|
next if row["id"] == ""
|
@@ -70,7 +69,7 @@ EOT
|
|
70
69
|
File.open(file_name, "w") do |file|
|
71
70
|
file.write(JSON.pretty_generate(hash) + "\n")
|
72
71
|
end
|
73
|
-
puts " create".
|
72
|
+
puts " create".green + " #{file_name}"
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
@@ -79,15 +78,15 @@ EOT
|
|
79
78
|
|
80
79
|
Spout::Helpers::CSVReader.read_csv(@csv_file) do |row|
|
81
80
|
if not row.keys.include?("domain_id")
|
82
|
-
puts "\nMissing column header `".
|
81
|
+
puts "\nMissing column header `".red + "domain_id".cyan + "` in data dictionary.".red + additional_csv_info
|
83
82
|
exit(1)
|
84
83
|
end
|
85
84
|
if not row.keys.include?("value")
|
86
|
-
puts "\nMissing column header `".
|
85
|
+
puts "\nMissing column header `".red + "value".cyan + "` in data dictionary.".red + additional_csv_info
|
87
86
|
exit(1)
|
88
87
|
end
|
89
88
|
if not row.keys.include?("display_name")
|
90
|
-
puts "\nMissing column header `".
|
89
|
+
puts "\nMissing column header `".red + "display_name".cyan + "` in data dictionary.".red + additional_csv_info
|
91
90
|
exit(1)
|
92
91
|
end
|
93
92
|
|
@@ -116,23 +115,23 @@ EOT
|
|
116
115
|
File.open(file_name, "w") do |file|
|
117
116
|
file.write(JSON.pretty_generate(domain_hash["options"]) + "\n")
|
118
117
|
end
|
119
|
-
puts " create".
|
118
|
+
puts " create".green + " #{file_name}"
|
120
119
|
end
|
121
120
|
end
|
122
121
|
|
123
122
|
def import_forms
|
124
123
|
Spout::Helpers::CSVReader.read_csv(@csv_file) do |row|
|
125
124
|
unless row.keys.include?("id")
|
126
|
-
puts "\nMissing column header `".
|
127
|
-
"id".
|
128
|
-
"` in data dictionary.".
|
125
|
+
puts "\nMissing column header `".red +
|
126
|
+
"id".cyan +
|
127
|
+
"` in data dictionary.".red +
|
129
128
|
additional_csv_info
|
130
129
|
exit(1)
|
131
130
|
end
|
132
131
|
unless row.keys.include?("display_name")
|
133
|
-
puts "\nMissing column header `".
|
134
|
-
"display_name".
|
135
|
-
"` in data dictionary.".
|
132
|
+
puts "\nMissing column header `".red +
|
133
|
+
"display_name".cyan +
|
134
|
+
"` in data dictionary.".red +
|
136
135
|
additional_csv_info
|
137
136
|
exit(1)
|
138
137
|
end
|
@@ -149,7 +148,7 @@ EOT
|
|
149
148
|
File.open(file_name, "w") do |file|
|
150
149
|
file.write(JSON.pretty_generate(hash) + "\n")
|
151
150
|
end
|
152
|
-
puts " create".
|
151
|
+
puts " create".green + " #{file_name}"
|
153
152
|
end
|
154
153
|
end
|
155
154
|
|
@@ -169,7 +168,7 @@ EOT
|
|
169
168
|
|
170
169
|
def additional_csv_info
|
171
170
|
"\n\nFor additional information on specifying CSV column headers before import see:\n\n " +
|
172
|
-
"https://github.com/sleepepi/spout#generate-a-new-repository-from-an-existing-csv-file".
|
171
|
+
"https://github.com/sleepepi/spout#generate-a-new-repository-from-an-existing-csv-file".cyan + "\n\n"
|
173
172
|
end
|
174
173
|
end
|
175
174
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "colorize"
|
4
3
|
require "fileutils"
|
5
4
|
|
6
5
|
require "spout/helpers/framework"
|
@@ -49,7 +48,7 @@ EOT
|
|
49
48
|
copy_file "test/dictionary_test.rb"
|
50
49
|
copy_file "test/test_helper.rb"
|
51
50
|
return if skip_gemfile
|
52
|
-
puts " run".
|
51
|
+
puts " run".green + " bundle install".cyan
|
53
52
|
Dir.chdir(@full_path)
|
54
53
|
system "bundle install"
|
55
54
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "colorize"
|
4
3
|
require "spout/helpers/json_request"
|
5
4
|
require "spout/helpers/framework"
|
6
5
|
|
@@ -24,19 +23,19 @@ module Spout
|
|
24
23
|
(json, _status) = Spout::Helpers::JsonRequest.get("https://rubygems.org/api/v1/gems/spout.json")
|
25
24
|
if json
|
26
25
|
if json["version"] == Spout::VERSION::STRING
|
27
|
-
puts "The spout gem is " + "up-to-date".
|
26
|
+
puts "The spout gem is " + "up-to-date".green + "!"
|
28
27
|
check_framework if File.exist?("Gemfile") || File.exist?("gems.rb")
|
29
28
|
else
|
30
29
|
puts "A newer version (v#{json["version"]}) is available!\n\n"
|
31
30
|
if File.exist?("gems.rb")
|
32
|
-
puts "Add the following to gems.rb and run " + "bundle update".
|
33
|
-
puts " gem \"spout\", \"~> #{json["version"]}\"\n".
|
31
|
+
puts "Add the following to gems.rb and run " + "bundle update".green + ".\n\n"
|
32
|
+
puts " gem \"spout\", \"~> #{json["version"]}\"\n".white
|
34
33
|
elsif File.exist?("Gemfile")
|
35
|
-
puts "Add the following to Gemfile and run " + "bundle update".
|
36
|
-
puts " gem \"spout\", \"~> #{json["version"]}\"\n".
|
34
|
+
puts "Add the following to Gemfile and run " + "bundle update".green + ".\n\n"
|
35
|
+
puts " gem \"spout\", \"~> #{json["version"]}\"\n".white
|
37
36
|
else
|
38
37
|
puts "Type the following command to update:\n\n"
|
39
|
-
puts " gem install spout --no-document".
|
38
|
+
puts " gem install spout --no-document".white + "\n\n"
|
40
39
|
end
|
41
40
|
end
|
42
41
|
else
|
@@ -58,13 +57,13 @@ module Spout
|
|
58
57
|
addables = ["/coverage", "/csvs", "/exports", "/graphs"]
|
59
58
|
removables = ["/dd", "/images"]
|
60
59
|
unless ((removables & lines) | (addables - lines)).empty?
|
61
|
-
puts "File: " + ".gitignore".
|
60
|
+
puts "File: " + ".gitignore".white
|
62
61
|
puts "----------------"
|
63
62
|
(removables & lines).each do |removable|
|
64
|
-
puts "REMOVE LINE ".
|
63
|
+
puts "REMOVE LINE ".red + removable.white
|
65
64
|
end
|
66
65
|
(addables - lines).each do |addable|
|
67
|
-
puts " ADD LINE ".
|
66
|
+
puts " ADD LINE ".green + addable.white
|
68
67
|
end
|
69
68
|
puts
|
70
69
|
end
|
@@ -78,10 +77,10 @@ module Spout
|
|
78
77
|
lines = IO.readlines(".ruby-version").collect(&:strip)
|
79
78
|
template_lines = IO.readlines(File.expand_path("../../templates/ruby-version", __FILE__)).collect(&:strip)
|
80
79
|
if template_lines.first != lines.first
|
81
|
-
puts "File: " + ".ruby-version".
|
80
|
+
puts "File: " + ".ruby-version".white
|
82
81
|
puts "-------------------"
|
83
|
-
print "Update Ruby from " + lines.first.to_s.
|
84
|
-
print " to " + template_lines.first.to_s.
|
82
|
+
print "Update Ruby from " + lines.first.to_s.red
|
83
|
+
print " to " + template_lines.first.to_s.green
|
85
84
|
puts "\n\n"
|
86
85
|
end
|
87
86
|
else
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "colorize"
|
4
3
|
require "date"
|
5
4
|
require "erb"
|
6
5
|
require "fileutils"
|
@@ -15,7 +14,7 @@ module Spout
|
|
15
14
|
file_name = template_file if file_name == ""
|
16
15
|
file_path = File.join(@full_path, file_name)
|
17
16
|
template_file_path = File.join(TEMPLATES_DIRECTORY, template_file)
|
18
|
-
puts " create".
|
17
|
+
puts " create".green + " #{file_name}"
|
19
18
|
FileUtils.copy(template_file_path, file_path)
|
20
19
|
end
|
21
20
|
|
@@ -25,14 +24,14 @@ module Spout
|
|
25
24
|
file_path = File.join(@full_path, file_name)
|
26
25
|
file_out = File.new(file_path, "w")
|
27
26
|
file_out.syswrite(template.result(binding))
|
28
|
-
puts " create".
|
27
|
+
puts " create".green + " #{file_name}"
|
29
28
|
ensure
|
30
29
|
file_out.close if file_out
|
31
30
|
end
|
32
31
|
|
33
32
|
def directory(directory_name)
|
34
33
|
directory_path = File.join(@full_path, directory_name)
|
35
|
-
puts " create".
|
34
|
+
puts " create".green + " #{directory_name}"
|
36
35
|
FileUtils.mkpath(directory_path)
|
37
36
|
end
|
38
37
|
end
|
@@ -36,7 +36,7 @@ module Spout
|
|
36
36
|
end
|
37
37
|
rescue
|
38
38
|
@error = "Invalid URL: #{url.inspect}"
|
39
|
-
puts @error.
|
39
|
+
puts @error.red
|
40
40
|
end
|
41
41
|
|
42
42
|
def get
|
@@ -49,7 +49,7 @@ module Spout
|
|
49
49
|
end
|
50
50
|
[JSON.parse(response.body), response]
|
51
51
|
rescue => e
|
52
|
-
puts "GET Error: #{e}".
|
52
|
+
puts "GET Error: #{e}".red
|
53
53
|
end
|
54
54
|
|
55
55
|
def post
|
@@ -59,7 +59,7 @@ module Spout
|
|
59
59
|
end
|
60
60
|
[JSON.parse(response.body), response]
|
61
61
|
rescue => e
|
62
|
-
puts "POST ERROR: #{e}".
|
62
|
+
puts "POST ERROR: #{e}".red
|
63
63
|
nil
|
64
64
|
end
|
65
65
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "colorize"
|
4
3
|
require "json"
|
5
4
|
|
6
5
|
require "spout/helpers/csv_reader"
|
@@ -45,9 +44,9 @@ module Spout
|
|
45
44
|
@csv_files = Dir.glob("#{csv_root}/**/*.csv").sort
|
46
45
|
|
47
46
|
if @csv_directory != @standard_version
|
48
|
-
puts "\n#{@csv_files.size == 0 ? 'No CSVs found' : 'Parsing files' } in " + "#{csv_root}".
|
47
|
+
puts "\n#{@csv_files.size == 0 ? 'No CSVs found' : 'Parsing files' } in " + "#{csv_root}".white + " for dictionary version " + @standard_version.to_s.green + "\n"
|
49
48
|
else
|
50
|
-
puts "\n#{@csv_files.size == 0 ? 'No CSVs found' : 'Parsing files' } in " + "#{csv_root}".
|
49
|
+
puts "\n#{@csv_files.size == 0 ? 'No CSVs found' : 'Parsing files' } in " + "#{csv_root}".white + "\n"
|
51
50
|
end
|
52
51
|
|
53
52
|
last_folder = nil
|
@@ -56,13 +55,13 @@ module Spout
|
|
56
55
|
current_file = File.basename(relative_path)
|
57
56
|
current_folder = relative_path.gsub(/#{current_file}$/, "")
|
58
57
|
count = 1 # Includes counting the header row
|
59
|
-
puts " #{current_folder}".
|
58
|
+
puts " #{current_folder}".white if current_folder.to_s != "" && current_folder != last_folder
|
60
59
|
print " #{current_file}"
|
61
60
|
last_folder = current_folder
|
62
61
|
|
63
62
|
Spout::Helpers::CSVReader.read_csv(csv_file) do |row|
|
64
63
|
count += 1
|
65
|
-
print "\r #{current_file} " + "##{count}".
|
64
|
+
print "\r #{current_file} " + "##{count}".yellow if (count % 10 == 0)
|
66
65
|
@subjects << Spout::Models::Subject.create do |t|
|
67
66
|
t._visit = row[@visit]
|
68
67
|
t._csv = File.basename(csv_file)
|
@@ -70,7 +69,7 @@ module Spout
|
|
70
69
|
row.each_with_index do |(key, value), index|
|
71
70
|
method = key.to_s.downcase.strip
|
72
71
|
if method == ""
|
73
|
-
puts "\nSkipping column #{index + 1} due to blank header.".
|
72
|
+
puts "\nSkipping column #{index + 1} due to blank header.".red if count == 2
|
74
73
|
next
|
75
74
|
end
|
76
75
|
next unless @valid_ids.include?(method) || @valid_ids.size == 0
|
@@ -91,7 +90,7 @@ module Spout
|
|
91
90
|
break if !@number_of_rows.nil? && count - 1 >= @number_of_rows
|
92
91
|
end
|
93
92
|
|
94
|
-
print "\r #{current_file} " + "##{count}".
|
93
|
+
print "\r #{current_file} " + "##{count}".green
|
95
94
|
puts "\n"
|
96
95
|
end
|
97
96
|
end
|
@@ -17,9 +17,9 @@ class DictionaryTest < Minitest::Test
|
|
17
17
|
# VALID_UNITS = ["minutes", "hours"]
|
18
18
|
# @variables.select { |v| %w(numeric integer).include?(v.type) }.each do |variable|
|
19
19
|
# define_method("test_units: #{variable.path}") do
|
20
|
-
# message = "\"#{variable.units}\"".
|
20
|
+
# message = "\"#{variable.units}\"".red + " invalid units.\n" +
|
21
21
|
# " Valid types: " +
|
22
|
-
# VALID_UNITS.sort_by(&:to_s).collect { |u| u.inspect.
|
22
|
+
# VALID_UNITS.sort_by(&:to_s).collect { |u| u.inspect.white }.join(", ")
|
23
23
|
# assert VALID_UNITS.include?(variable.units), message
|
24
24
|
# end
|
25
25
|
# end
|
data/lib/spout/tests.rb
CHANGED
@@ -5,7 +5,6 @@ require "json"
|
|
5
5
|
|
6
6
|
require "minitest/autorun"
|
7
7
|
require "minitest/reporters"
|
8
|
-
require "colorize"
|
9
8
|
|
10
9
|
module Minitest
|
11
10
|
module Reporters
|
@@ -14,10 +13,7 @@ module Minitest
|
|
14
13
|
|
15
14
|
def start
|
16
15
|
super
|
17
|
-
|
18
|
-
puts
|
19
|
-
puts
|
20
|
-
puts "Started"
|
16
|
+
puts "Started spout tests".white
|
21
17
|
puts
|
22
18
|
end
|
23
19
|
|
@@ -25,11 +21,11 @@ module Minitest
|
|
25
21
|
super
|
26
22
|
puts format("Finished in %.5f seconds.", total_time)
|
27
23
|
puts
|
28
|
-
print format("%d tests", count).
|
24
|
+
print format("%d tests", count).white
|
29
25
|
print format(", %d assertions, ", assertions)
|
30
26
|
color = failures.zero? && errors.zero? ? :green : :red
|
31
|
-
print format("%d failures, %d errors, ", failures, errors).
|
32
|
-
print format("%d skips", skips).
|
27
|
+
print format("%d failures, %d errors, ", failures, errors).send(color)
|
28
|
+
print format("%d skips", skips).yellow
|
33
29
|
puts
|
34
30
|
puts
|
35
31
|
end
|
@@ -58,7 +54,7 @@ module Minitest
|
|
58
54
|
else
|
59
55
|
:red
|
60
56
|
end
|
61
|
-
print pad_mark(result(test).to_s.upcase).
|
57
|
+
print pad_mark(result(test).to_s.upcase).send(color)
|
62
58
|
end
|
63
59
|
|
64
60
|
def before_suite(suite)
|
@@ -111,6 +107,3 @@ module Spout
|
|
111
107
|
include Spout::Tests::VariableTypeValidation
|
112
108
|
end
|
113
109
|
end
|
114
|
-
|
115
|
-
# Initialize the String class `@disable_colorization` instance variable
|
116
|
-
String.disable_colorization = false
|
data/lib/spout/version.rb
CHANGED
data/lib/spout.rb
CHANGED
data/spout.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.0.
|
4
|
+
version: 0.14.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Remo Mueller
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: colorize
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.8.1
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.8.1
|
83
69
|
description: Manage your data dictionary as a JSON repository, and easily export back
|
84
70
|
to CSV.
|
85
71
|
email:
|
@@ -95,6 +81,7 @@ files:
|
|
95
81
|
- Rakefile
|
96
82
|
- bin/spout
|
97
83
|
- lib/spout.rb
|
84
|
+
- lib/spout/color.rb
|
98
85
|
- lib/spout/commands/coverage.rb
|
99
86
|
- lib/spout/commands/deploy.rb
|
100
87
|
- lib/spout/commands/exporter.rb
|