bcl 0.3.7 → 0.3.8
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/lib/bcl.rb +4 -2
- data/lib/bcl/component_methods.rb +291 -49
- data/lib/bcl/component_xml.rb +1 -1
- data/lib/bcl/measure_xml.rb +1 -5
- data/lib/bcl/tar_ball.rb +31 -2
- data/lib/bcl/version.rb +1 -1
- metadata +3 -18
- data/lib/bcl/mongo_to_component.rb +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbd79659281ee21204429f1a34bb6f5d65ce7feb
|
4
|
+
data.tar.gz: 6dd76b45e44bddd5b2783fe25247aa8a52c51e64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9495c30a31a7c3ed00adb152dd484c38614b7c43266d613980a56e7572a586e1427234199ccfac79277507515627dd75c292abcc93991c7f96f842786bdc35e0
|
7
|
+
data.tar.gz: 3133b42d0e3c1e33790e5d56c843d881405c9ceaf62abefb79c356184a89c20317aa7b0c969a5525424c251ebe4b53108955bebcefca9afe564a35726826a922
|
data/lib/bcl.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'zlib'
|
3
|
+
|
1
4
|
require 'bcl/component_spreadsheet'
|
2
5
|
require 'bcl/component_xml'
|
3
6
|
require 'bcl/component_methods'
|
@@ -5,5 +8,4 @@ require 'bcl/measure_xml'
|
|
5
8
|
require 'bcl/bcl_xml'
|
6
9
|
require 'bcl/tar_ball'
|
7
10
|
require 'bcl/master_taxonomy'
|
8
|
-
require 'bcl/
|
9
|
-
require 'bcl/version'
|
11
|
+
require 'bcl/version'
|
@@ -38,36 +38,22 @@ module BCL
|
|
38
38
|
attr_accessor :config
|
39
39
|
attr_accessor :session
|
40
40
|
attr_accessor :http
|
41
|
+
attr_accessor :parsed_measures_path
|
41
42
|
|
42
43
|
def initialize(group_id = nil)
|
44
|
+
@parsed_measures_path = './measures/parsed/'
|
43
45
|
@config = nil
|
44
46
|
@session = nil
|
45
47
|
@access_token = nil
|
46
48
|
@http = nil
|
47
49
|
@api_version = 2.0
|
48
|
-
#set group to NREL (32) if nil
|
49
|
-
@group_id = group_id.nil? ? 32 : group_id
|
50
|
-
config_path = File.expand_path('~') + '/.bcl'
|
51
|
-
config_name = 'config.yml'
|
52
|
-
if File.exists?(config_path + "/" + config_name)
|
53
|
-
puts "loading config settings from #{config_path + "/" + config_name}"
|
54
|
-
@config = YAML.load_file(config_path + "/" + config_name)
|
55
|
-
else
|
56
|
-
#location of template file
|
57
|
-
FileUtils.mkdir_p(config_path)
|
58
|
-
File.open(config_path + "/" + config_name, 'w') do |file|
|
59
|
-
file << default_yaml.to_yaml
|
60
|
-
end
|
61
|
-
puts "******** Please fill in user credentials in #{config_path}/#{config_name} file. DO NOT COMMIT THIS FILE. **********"
|
62
|
-
end
|
50
|
+
@group_id = group_id.nil? ? 32 : group_id #set group to NREL (32) if nil
|
63
51
|
|
52
|
+
|
53
|
+
load_config
|
64
54
|
end
|
65
55
|
|
66
|
-
|
67
|
-
settings = {:server => {:url => "https://bcl.nrel.gov", :user => {:username => "ENTER_BCL_USERNAME", :password => "ENTER_BCL_PASSWORD"}}}
|
68
|
-
|
69
|
-
settings
|
70
|
-
end
|
56
|
+
|
71
57
|
|
72
58
|
|
73
59
|
def login(username=nil, password=nil, url=nil)
|
@@ -159,8 +145,8 @@ module BCL
|
|
159
145
|
puts "error info: #{access_token.body}"
|
160
146
|
end
|
161
147
|
|
162
|
-
#puts "access_token = *#{@access_token}*"
|
163
|
-
#puts "cookie = #{@session}"
|
148
|
+
#puts "access_token = *#{@access_token}*"
|
149
|
+
# puts "cookie = #{@session}"
|
164
150
|
|
165
151
|
res
|
166
152
|
else
|
@@ -173,6 +159,163 @@ module BCL
|
|
173
159
|
end
|
174
160
|
end
|
175
161
|
|
162
|
+
#retrieve, parse, and save metadata for BCL measures
|
163
|
+
def measure_metadata(search_term = nil, filter_term=nil, return_all_pages = false)
|
164
|
+
|
165
|
+
#setup results directory
|
166
|
+
if !Dir.exists?(@parsed_measures_path)
|
167
|
+
FileUtils.mkdir_p(@parsed_measures_path)
|
168
|
+
end
|
169
|
+
puts "...storing parsed metadata in #{@parsed_measures_path}"
|
170
|
+
|
171
|
+
#retrieve measures
|
172
|
+
puts "retrieving measures that match search_term: #{search_term.nil? ? "nil":search_term} and filters: #{filter_term.nil? ? "nil":filter_term}"
|
173
|
+
retrieve_measures(search_term, filter_term, return_all_pages) do |measure|
|
174
|
+
#parse and save
|
175
|
+
parse_measure_metadata(measure)
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
return true
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
#expects a JSON measure object
|
184
|
+
def parse_measure_metadata(measure)
|
185
|
+
|
186
|
+
#check for valid measure
|
187
|
+
if measure[:measure][:name] && measure[:measure][:uuid]
|
188
|
+
|
189
|
+
file_data = download_component(measure[:measure][:uuid])
|
190
|
+
|
191
|
+
if file_data
|
192
|
+
save_file = File.expand_path("@{parsed_measures_path}#{measure[:measure][:name].downcase.gsub(" ", "_")}.zip")
|
193
|
+
File.open(save_file, 'wb') { |f| f << file_data }
|
194
|
+
|
195
|
+
#unzip file and delete zip.
|
196
|
+
#TODO check that something was downloaded here before extracting zip
|
197
|
+
if File.exists?(save_file)
|
198
|
+
BCL.extract_zip(save_file, @parsed_measures_path, true)
|
199
|
+
|
200
|
+
# catch a weird case where there is an extra space in an unzip file structure but not in the measure.name
|
201
|
+
if measure[:measure][:name] == "Add Daylight Sensor at Center of Spaces with a Specified Space Type Assigned"
|
202
|
+
if !File.exists? "#{@parsed_measures_path}#{measure[:measure][:name]}"
|
203
|
+
temp_dir_name = "#{@parsed_measures_path}Add Daylight Sensor at Center of Spaces with a Specified Space Type Assigned"
|
204
|
+
FileUtils.move(temp_dir_name, "#{@parsed_measures_path}#{measure[:measure][:name]}")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
temp_dir_name = "#{@parsed_measures_path}#{measure[:measure][:name]}"
|
209
|
+
|
210
|
+
# Read the measure.rb file
|
211
|
+
#puts "save dir name #{temp_dir_name}"
|
212
|
+
measure_filename = "#{temp_dir_name}/measure.rb"
|
213
|
+
if File.exists?(measure_filename)
|
214
|
+
measure_hash = {}
|
215
|
+
# read in the measure file and extract some information
|
216
|
+
measure_string = File.read(measure_filename)
|
217
|
+
|
218
|
+
measure_hash[:classname] = measure_string.match(/class (.*) </)[1]
|
219
|
+
measure_hash[:path] = "#{@parsed_measures_path}#{measure_hash[:classname]}"
|
220
|
+
measure_hash[:name] = measure[:measure][:name]
|
221
|
+
if measure_string =~ /OpenStudio::Ruleset::WorkspaceUserScript/
|
222
|
+
measure_hash[:measure_type] = "EnergyPlusMeasure"
|
223
|
+
elsif measure_string =~ /OpenStudio::Ruleset::ModelUserScript/
|
224
|
+
measure_hash[:measure_type] = "RubyMeasure"
|
225
|
+
elsif measure_string =~ /OpenStudio::Ruleset::ReportingUserScript/
|
226
|
+
measure_hash[:measure_type] = "ReportingMeasure"
|
227
|
+
else
|
228
|
+
raise "measure type is unknown with an inherited class in #{measure_filename}: #{measure_hash.inspect}"
|
229
|
+
end
|
230
|
+
|
231
|
+
# move the directory to the class name
|
232
|
+
FileUtils.rm_rf(measure_hash[:path]) if Dir.exists?(measure_hash[:path]) && temp_dir_name != measure_hash[:path]
|
233
|
+
FileUtils.move(temp_dir_name, measure_hash[:path]) unless temp_dir_name == measure_hash[:path]
|
234
|
+
|
235
|
+
measure_hash[:arguments] = []
|
236
|
+
|
237
|
+
args = measure_string.scan(/(.*).*=.*OpenStudio::Ruleset::OSArgument::make(.*)Argument\((.*).*\)/)
|
238
|
+
#puts "found #{args.size} arguments for measure '#{measure[:measure][:name]}'"
|
239
|
+
args.each do |arg|
|
240
|
+
new_arg = {}
|
241
|
+
new_arg[:local_variable] = arg[0].strip
|
242
|
+
new_arg[:variable_type] = arg[1]
|
243
|
+
arg_params = arg[2].split(",")
|
244
|
+
new_arg[:name] = arg_params[0].gsub(/"|'/, "")
|
245
|
+
choice_vector = arg_params[1]
|
246
|
+
|
247
|
+
# local variable name to get other attributes
|
248
|
+
new_arg[:display_name] = measure_string.match(/#{new_arg[:local_variable]}.setDisplayName\((.*)\)/)[1]
|
249
|
+
new_arg[:display_name].gsub!(/"|'/, "") if new_arg[:display_name]
|
250
|
+
|
251
|
+
if measure_string =~ /#{new_arg[:local_variable]}.setDefaultValue/
|
252
|
+
new_arg[:default_value] = measure_string.match(/#{new_arg[:local_variable]}.setDefaultValue\((.*)\)/)[1]
|
253
|
+
case new_arg[:variable_type]
|
254
|
+
when "Choice"
|
255
|
+
# Choices to appear to only be strings?
|
256
|
+
new_arg[:default_value].gsub!(/"|'/, "")
|
257
|
+
|
258
|
+
# parse the choices from the measure
|
259
|
+
choices = measure_string.scan(/#{choice_vector}.*<<.*("|')(.*)("|')/)
|
260
|
+
|
261
|
+
new_arg[:choices] = choices.map { |c| c[1] }
|
262
|
+
# if the choices are inherited from the model, then need to just display the default value which
|
263
|
+
# somehow magically works because that is the display name
|
264
|
+
new_arg[:choices] << new_arg[:default_value] unless new_arg[:choices].include?(new_arg[:default_value])
|
265
|
+
when "String"
|
266
|
+
new_arg[:default_value].gsub!(/"|'/, "")
|
267
|
+
when "Bool"
|
268
|
+
new_arg[:default_value] = new_arg[:default_value].downcase == "true" ? true : false
|
269
|
+
when "Integer"
|
270
|
+
new_arg[:default_value] = new_arg[:default_value].to_i
|
271
|
+
when "Double"
|
272
|
+
new_arg[:default_value] = new_arg[:default_value].to_f
|
273
|
+
else
|
274
|
+
raise "unknown variable type of #{new_arg[:variable_type]}"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
measure_hash[:arguments] << new_arg
|
279
|
+
end
|
280
|
+
|
281
|
+
# create a new measure.json file for parsing later if need be
|
282
|
+
File.open("#{measure_hash[:path]}/measure.json", 'w') { |f| f << JSON.pretty_generate(measure_hash) }
|
283
|
+
|
284
|
+
end
|
285
|
+
else
|
286
|
+
puts "Problems downloading #{measure[:measure][:name]}...moving on"
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
# retrieve measures for parsing metadata.
|
293
|
+
# specify a search term to narrow down search or leave nil to retrieve all
|
294
|
+
# set all_pages to true to iterate over all pages of results
|
295
|
+
# can't specify filters other than the hard-coded bundle and show_rows
|
296
|
+
def retrieve_measures(search_term = nil, filter_term=nil, return_all_pages = false, &block)
|
297
|
+
#raise "Please login before performing this action" if @session.nil?
|
298
|
+
|
299
|
+
#make sure filter_term includes bundle
|
300
|
+
if filter_term.nil?
|
301
|
+
filter_term = "fq[]=bundle%3Anrel_measure"
|
302
|
+
elsif !filter_term.include? "bundle"
|
303
|
+
filter_term = filter_term + "&fq[]=bundle%3Anrel_measure"
|
304
|
+
end
|
305
|
+
|
306
|
+
|
307
|
+
# use provided search term or nil.
|
308
|
+
# if return_all_pages is true, iterate over pages of API results. Otherwise only return first 100
|
309
|
+
results = search(search_term, filter_term, return_all_pages)
|
310
|
+
puts "#{results[:result].count} results returned"
|
311
|
+
|
312
|
+
results[:result].each do |result|
|
313
|
+
puts "retrieving measure: #{result[:measure][:name]}"
|
314
|
+
yield result
|
315
|
+
end
|
316
|
+
|
317
|
+
end
|
318
|
+
|
176
319
|
# pushes component to the bcl and publishes them (if logged-in as BCL Website Admin user).
|
177
320
|
# username and password set in ~/.bcl/config.yml file
|
178
321
|
def push_content(filename_and_path, write_receipt_file, content_type)
|
@@ -196,10 +339,10 @@ module BCL
|
|
196
339
|
"node" =>
|
197
340
|
{
|
198
341
|
"type" => "#{content_type}",
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
342
|
+
"field_component_tags" => #TODO remove this field_component_tags once BCL is fixed
|
343
|
+
{
|
344
|
+
"und" => "1289"
|
345
|
+
},
|
203
346
|
"og_group_ref" =>
|
204
347
|
{
|
205
348
|
"und" =>
|
@@ -215,14 +358,17 @@ module BCL
|
|
215
358
|
|
216
359
|
path = "/api/content.json"
|
217
360
|
headers = {'Content-Type' => 'application/json', 'X-CSRF-Token' => @access_token, 'Cookie' => @session}
|
218
|
-
|
361
|
+
|
362
|
+
|
219
363
|
res = @http.post(path, @data.to_json, headers)
|
220
364
|
|
221
365
|
res_j = "could not get json from http post response"
|
222
366
|
if res.code == '200'
|
367
|
+
puts "200"
|
223
368
|
res_j = JSON.parse(res.body)
|
224
369
|
puts " 200 - Successful Upload"
|
225
370
|
valid = true
|
371
|
+
|
226
372
|
elsif res.code == '404'
|
227
373
|
puts " error code: #{res.code} - #{res.body}"
|
228
374
|
puts " 404 - check these common causes first:"
|
@@ -249,6 +395,7 @@ module BCL
|
|
249
395
|
end
|
250
396
|
|
251
397
|
[valid, res_j]
|
398
|
+
|
252
399
|
end
|
253
400
|
|
254
401
|
def push_contents(array_of_components, skip_files_with_receipts, content_type)
|
@@ -293,10 +440,10 @@ module BCL
|
|
293
440
|
"node" =>
|
294
441
|
{
|
295
442
|
"uuid" => "#{uuid}",
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
443
|
+
"field_component_tags" => #TODO remove this field_component_tags once BCL is fixed
|
444
|
+
{
|
445
|
+
"und" => "1289"
|
446
|
+
},
|
300
447
|
"og_group_ref" =>
|
301
448
|
{
|
302
449
|
"und" =>
|
@@ -375,7 +522,7 @@ module BCL
|
|
375
522
|
else
|
376
523
|
log_message = "pushing updated content #{File.basename(comp)}"
|
377
524
|
puts log_message
|
378
|
-
valid, res = update_content(comp, true, uuid
|
525
|
+
valid, res = update_content(comp, true, uuid)
|
379
526
|
log_message += " #{valid} #{res.inspect.chomp}"
|
380
527
|
end
|
381
528
|
end
|
@@ -384,28 +531,84 @@ module BCL
|
|
384
531
|
logs
|
385
532
|
end
|
386
533
|
|
387
|
-
# Simple method to search bcl and return the result as
|
388
|
-
|
389
|
-
|
534
|
+
# Simple method to search bcl and return the result as hash with symbols
|
535
|
+
# If all = true, iterate over pages of results and return all
|
536
|
+
# JSON ONLY
|
537
|
+
def search(search_str=nil, filter_str=nil, all=false)
|
538
|
+
full_url = "/api/search/"
|
390
539
|
|
391
540
|
#add search term
|
392
|
-
if !search_str.nil?
|
393
|
-
full_url = full_url +
|
541
|
+
if !search_str.nil? and search_str != ""
|
542
|
+
full_url = full_url + search_str
|
543
|
+
#strip out xml in case it's included. make sure .json is included
|
544
|
+
full_url = full_url.gsub('.xml', '')
|
545
|
+
unless search_str.include? ".json"
|
546
|
+
full_url = full_url + ".json"
|
547
|
+
end
|
548
|
+
else
|
549
|
+
full_url = full_url + "*.json"
|
394
550
|
end
|
551
|
+
|
395
552
|
#add api_version
|
553
|
+
if @api_version < 2.0
|
554
|
+
puts "WARNING: attempting to use search with api_version #{@api_version}. Use API v2.0 for this functionality."
|
555
|
+
end
|
396
556
|
full_url = full_url + "?api_version=#{@api_version}"
|
557
|
+
|
397
558
|
#add filters
|
398
559
|
if !filter_str.nil?
|
560
|
+
#strip out api_version from filters, if included
|
561
|
+
if filter_str.include? "api_version="
|
562
|
+
filter_str = filter_str.gsub(/api_version=\d{1,}/, '')
|
563
|
+
filter_str = filter_str.gsub(/&api_version=\d{1,}/, '')
|
564
|
+
end
|
399
565
|
full_url = full_url + "&" + filter_str
|
400
566
|
end
|
401
567
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
568
|
+
#simple search vs. all results
|
569
|
+
if !all
|
570
|
+
puts "search url: #{full_url}"
|
571
|
+
res = @http.get(full_url)
|
572
|
+
#return unparsed
|
573
|
+
JSON.parse(res.body, :symbolize_names => true)
|
574
|
+
else
|
575
|
+
#iterate over result pages
|
576
|
+
#modify filter_str for show_rows=200 for maximum returns
|
577
|
+
if filter_str.include? "show_rows="
|
578
|
+
full_url = full_url.gsub(/show_rows=\d{1,}/, "show_rows=200")
|
579
|
+
else
|
580
|
+
full_url = full_url + "&show_rows=200"
|
581
|
+
end
|
582
|
+
#make sure filter_str doesn't already have a page=x
|
583
|
+
full_url.gsub(/page=\d{1,}/, '')
|
584
|
+
|
585
|
+
pagecnt = 0
|
586
|
+
continue = 1
|
587
|
+
results = Array.new
|
588
|
+
while continue == 1
|
589
|
+
#retrieve current page
|
590
|
+
full_url_all = full_url + "&page=#{pagecnt}"
|
591
|
+
puts "search url: #{full_url_all}"
|
592
|
+
response = @http.get(full_url_all)
|
593
|
+
#parse here so you can build results array
|
594
|
+
res = JSON.parse(response.body)
|
595
|
+
|
596
|
+
if res["result"].count > 0
|
597
|
+
pagecnt += 1
|
598
|
+
res["result"].each do |r|
|
599
|
+
results << r
|
600
|
+
end
|
601
|
+
else
|
602
|
+
continue = 0
|
603
|
+
end
|
604
|
+
end
|
605
|
+
#return unparsed b/c that is what is expected
|
606
|
+
formatted_results = {"result" => results}
|
607
|
+
results_to_return = JSON.parse(formatted_results.to_json, :symbolize_names => true)
|
608
|
+
end
|
406
609
|
end
|
407
610
|
|
408
|
-
|
611
|
+
# Delete receipt files
|
409
612
|
def delete_receipts(array_of_components)
|
410
613
|
array_of_components.each do |comp|
|
411
614
|
receipt_file = File.dirname(comp) + "/" + File.basename(comp, '.tar.gz') + ".receipt"
|
@@ -417,21 +620,59 @@ module BCL
|
|
417
620
|
end
|
418
621
|
|
419
622
|
def list_all_measures()
|
420
|
-
json =
|
623
|
+
json = search(nil, "fq[]=bundle%3Anrel_measure&show_rows=100")
|
421
624
|
|
422
625
|
json
|
423
626
|
end
|
424
|
-
|
627
|
+
|
425
628
|
def download_component(uid)
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
629
|
+
|
630
|
+
begin
|
631
|
+
result = @http.get("/api/component/download?uids=#{uid}")
|
632
|
+
puts "DOWNLOADING: /api/component/download?uids=#{uid}"
|
633
|
+
#puts "RESULTS: #{result.inspect}"
|
634
|
+
#puts "RESULTS BODY: #{result.body}"
|
635
|
+
|
636
|
+
#look at response code
|
637
|
+
if result.code == '200'
|
638
|
+
puts "Download Successful"
|
639
|
+
result.body ? result.body : nil
|
640
|
+
else
|
641
|
+
puts "Download fail. Error code #{result.code}"
|
642
|
+
nil
|
643
|
+
end
|
644
|
+
|
645
|
+
rescue
|
646
|
+
puts "Couldn't download uid(s): #{uid}...skipping"
|
647
|
+
nil
|
648
|
+
end
|
649
|
+
|
430
650
|
end
|
431
651
|
|
652
|
+
private
|
653
|
+
|
654
|
+
def load_config()
|
655
|
+
config_filename = File.expand_path("~/.bcl/config.yml")
|
656
|
+
|
657
|
+
if File.exists?(config_filename)
|
658
|
+
puts "loading config settings from #{config_filename}"
|
659
|
+
@config = YAML.load_file(config_filename)
|
660
|
+
else
|
661
|
+
#location of template file
|
662
|
+
FileUtils.mkdir_p(File.dirname(config_filename))
|
663
|
+
File.open(config_filename, 'w') { |f| f << default_yaml.to_yaml }
|
664
|
+
File.chmod(0600, config_filename)
|
665
|
+
puts "******** Please fill in user credentials in #{config_filename} file if you need to upload data **********"
|
666
|
+
end
|
667
|
+
end
|
668
|
+
|
669
|
+
def default_yaml
|
670
|
+
settings = {:server => {:url => "https://bcl.nrel.gov", :user => {:username => "ENTER_BCL_USERNAME", :password => "ENTER_BCL_PASSWORD"}}}
|
671
|
+
|
672
|
+
settings
|
673
|
+
end
|
432
674
|
end #class ComponentMethods
|
433
675
|
|
434
|
-
|
435
676
|
|
436
677
|
# TODO make this extend the component_xml class (or create a super class around components)
|
437
678
|
|
@@ -495,4 +736,5 @@ module BCL
|
|
495
736
|
|
496
737
|
end
|
497
738
|
|
739
|
+
|
498
740
|
end # module BCL
|
data/lib/bcl/component_xml.rb
CHANGED
data/lib/bcl/measure_xml.rb
CHANGED
@@ -27,12 +27,10 @@ require 'fileutils'
|
|
27
27
|
require 'csv'
|
28
28
|
|
29
29
|
# required gems
|
30
|
-
require 'builder' #gem install builder (creates xml files)
|
31
30
|
require 'bcl/tar_ball'
|
32
31
|
require 'bcl/bcl_xml'
|
33
32
|
|
34
33
|
module BCL
|
35
|
-
|
36
34
|
class Measure
|
37
35
|
def initialize(save_path)
|
38
36
|
super(save_path)
|
@@ -43,12 +41,10 @@ module BCL
|
|
43
41
|
xmlfile = File.open(filepath, 'r').read
|
44
42
|
|
45
43
|
@xml = LibXML::XML::Document.string(xmlfile)
|
46
|
-
|
47
|
-
|
48
44
|
end
|
49
45
|
|
50
46
|
|
51
47
|
|
52
48
|
end
|
53
49
|
|
54
|
-
end
|
50
|
+
end
|
data/lib/bcl/tar_ball.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
######################################################################
|
1
|
+
######################################################################
|
2
2
|
# Copyright (c) 2008-2013, Alliance for Sustainable Energy.
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -19,8 +19,8 @@
|
|
19
19
|
|
20
20
|
require 'rubygems'
|
21
21
|
|
22
|
-
require 'zlib' #gem install zliby # need to convert this to another library (this is olllld)
|
23
22
|
require 'archive/tar/minitar' #gem install archive-tar-minitar
|
23
|
+
require 'zip/zip' #gem install rubyzip -v 0.9.9
|
24
24
|
|
25
25
|
module BCL
|
26
26
|
|
@@ -55,4 +55,33 @@ module BCL
|
|
55
55
|
}
|
56
56
|
end
|
57
57
|
|
58
|
+
def create_zip(destination, paths)
|
59
|
+
|
60
|
+
Zip::ZipFile.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
61
|
+
paths.each do |fi|
|
62
|
+
# Two arguments:
|
63
|
+
# - The name of the file as it will appear in the archive
|
64
|
+
# - The original file, including the path to find it
|
65
|
+
zipfile.add(fi.basename, fi)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def extract_zip(filename, destination, delete_zip = false)
|
72
|
+
Zip::ZipFile.open(filename) { |zip_file|
|
73
|
+
zip_file.each { |f|
|
74
|
+
f_path=File.join(destination, f.name)
|
75
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
76
|
+
zip_file.extract(f, f_path) unless File.exist?(f_path)
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
if delete_zip
|
81
|
+
fileList = Array.new
|
82
|
+
fileList << filename
|
83
|
+
FileUtils.rm(fileList)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
58
87
|
end # module BCL
|
data/lib/bcl/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Macumber
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: uuid
|
@@ -69,20 +69,6 @@ dependencies:
|
|
69
69
|
- - '>='
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
|
-
- !ruby/object:Gem::Dependency
|
73
|
-
name: mongo
|
74
|
-
requirement: !ruby/object:Gem::Requirement
|
75
|
-
requirements:
|
76
|
-
- - '>='
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: '0'
|
79
|
-
type: :runtime
|
80
|
-
prerelease: false
|
81
|
-
version_requirements: !ruby/object:Gem::Requirement
|
82
|
-
requirements:
|
83
|
-
- - '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
86
72
|
- !ruby/object:Gem::Dependency
|
87
73
|
name: json_pure
|
88
74
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,7 +127,6 @@ files:
|
|
141
127
|
- lib/bcl/current_taxonomy.xml
|
142
128
|
- lib/bcl/master_taxonomy.rb
|
143
129
|
- lib/bcl/measure_xml.rb
|
144
|
-
- lib/bcl/mongo_to_component.rb
|
145
130
|
- lib/bcl/tar_ball.rb
|
146
131
|
- lib/bcl/version.rb
|
147
132
|
- lib/bcl.rb
|
@@ -165,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
150
|
version: '0'
|
166
151
|
requirements: []
|
167
152
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.0.
|
153
|
+
rubygems_version: 2.0.3
|
169
154
|
signing_key:
|
170
155
|
specification_version: 4
|
171
156
|
summary: Classes for creating component XML files for the BCL
|
@@ -1,114 +0,0 @@
|
|
1
|
-
######################################################################
|
2
|
-
# Copyright (c) 2008-2013, Alliance for Sustainable Energy.
|
3
|
-
# All rights reserved.
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License as published by the Free Software Foundation; either
|
8
|
-
# version 2.1 of the License, or (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This library is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
# Lesser General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU Lesser General Public
|
16
|
-
# License along with this library; if not, write to the Free Software
|
17
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
-
######################################################################
|
19
|
-
|
20
|
-
#Mongo Record to Component
|
21
|
-
require 'bcl/component_xml'
|
22
|
-
|
23
|
-
module BCL
|
24
|
-
class MongoToComponent
|
25
|
-
attr_accessor :component
|
26
|
-
attr_accessor :error_message
|
27
|
-
|
28
|
-
def initialize(record)
|
29
|
-
@component = nil
|
30
|
-
@error_message = ""
|
31
|
-
|
32
|
-
if record.has_key? "general"
|
33
|
-
@component = BCL::Component.new('tmp')
|
34
|
-
general = record["general"]
|
35
|
-
|
36
|
-
#add uid/vid
|
37
|
-
if record.has_key? "unique_id"
|
38
|
-
component.uid = record["unique_id"]
|
39
|
-
else
|
40
|
-
@error_message = "Invalid Mongo record: no unique_id"
|
41
|
-
end
|
42
|
-
if record.has_key? "version_id"
|
43
|
-
component.comp_version_id = record["version_id"]
|
44
|
-
else
|
45
|
-
@error_message = "Invalid Mongo record: no version_id"
|
46
|
-
end
|
47
|
-
|
48
|
-
#add general info
|
49
|
-
if general.has_key? "name"
|
50
|
-
component.name = general["name"]
|
51
|
-
end
|
52
|
-
if general.has_key? "description"
|
53
|
-
@component.description = general["description"]
|
54
|
-
end
|
55
|
-
if general.has_key? "fidelity_level"
|
56
|
-
@component.fidelity_level = general["fidelity_level"]
|
57
|
-
end
|
58
|
-
if general.has_key? "source_manufacturer"
|
59
|
-
@component.source_manufacturer = general["source_manufacturer"]
|
60
|
-
end
|
61
|
-
if general.has_key? "source_url"
|
62
|
-
@component.source_url = general["source_url"]
|
63
|
-
end
|
64
|
-
|
65
|
-
#add tags
|
66
|
-
if general.has_key? "tags"
|
67
|
-
tags = general["tags"]
|
68
|
-
tags.each do |name,value|
|
69
|
-
@component.add_tag(value)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
#add attributes
|
74
|
-
if general.has_key? "attributes"
|
75
|
-
attribute_container = general["attributes"]
|
76
|
-
attribute_container.each do |a,attributes|
|
77
|
-
#attributes iterator is an array of hashes
|
78
|
-
#NOTE: double check this...could be old messed-up structure?
|
79
|
-
attributes.each do |attribute|
|
80
|
-
name = ""
|
81
|
-
units = ""
|
82
|
-
value = ""
|
83
|
-
datatype = ""
|
84
|
-
if attribute.has_key? "name"
|
85
|
-
name = attribute["name"]
|
86
|
-
end
|
87
|
-
if attribute.has_key? "value"
|
88
|
-
value = attribute["value"]
|
89
|
-
end
|
90
|
-
if attribute.has_key? "units"
|
91
|
-
units = attribute["units"]
|
92
|
-
end
|
93
|
-
@component.add_attribute(name, value, units)
|
94
|
-
|
95
|
-
#TODO: eventually find a way to validate the datatype in record with datatype in component
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
#todo: add provenance
|
101
|
-
|
102
|
-
else
|
103
|
-
@error_message = "Invalid Mongo record: no 'general' section"
|
104
|
-
end
|
105
|
-
#set component to NIL if there were errors
|
106
|
-
if !@error_message == nil
|
107
|
-
@component = nil
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
end # module BCL
|
114
|
-
|