bcl 0.5.3 → 0.5.4
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/base_xml.rb +33 -16
- data/lib/bcl/component.rb +388 -390
- data/lib/bcl/component_from_spreadsheet.rb +34 -37
- data/lib/bcl/component_methods.rb +864 -790
- data/lib/bcl/component_spreadsheet.rb +295 -309
- data/lib/bcl/core_ext.rb +38 -6
- data/lib/bcl/master_taxonomy.rb +533 -552
- data/lib/bcl/tar_ball.rb +78 -80
- data/lib/bcl/version.rb +2 -2
- data/lib/bcl.rb +41 -34
- metadata +84 -14
@@ -1,17 +1,17 @@
|
|
1
1
|
######################################################################
|
2
|
-
# Copyright (c) 2008-
|
2
|
+
# Copyright (c) 2008-2014, Alliance for Sustainable Energy.
|
3
3
|
# All rights reserved.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# This library is free software; you can redistribute it and/or
|
6
6
|
# modify it under the terms of the GNU Lesser General Public
|
7
7
|
# License as published by the Free Software Foundation; either
|
8
8
|
# version 2.1 of the License, or (at your option) any later version.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# This library is distributed in the hope that it will be useful,
|
11
11
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
12
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
13
|
# Lesser General Public License for more details.
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# You should have received a copy of the GNU Lesser General Public
|
16
16
|
# License along with this library; if not, write to the Free Software
|
17
17
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
@@ -23,49 +23,46 @@ require 'rubyXL'
|
|
23
23
|
require 'bcl'
|
24
24
|
|
25
25
|
module BCL
|
26
|
-
|
27
26
|
WorksheetStruct = Struct.new(:name, :components)
|
28
27
|
HeaderStruct = Struct.new(:name, :children)
|
29
28
|
ComponentStruct = Struct.new(:row, :name, :uid, :version_id, :headers, :values)
|
30
29
|
|
31
30
|
class ComponentFromSpreadsheet
|
32
|
-
|
33
31
|
@@changed = false
|
34
32
|
|
35
33
|
public
|
36
34
|
|
37
|
-
#initialize with Excel spreadsheet to read
|
38
|
-
def initialize(xlsx_path, worksheet_names =[
|
39
|
-
|
35
|
+
# initialize with Excel spreadsheet to read
|
36
|
+
def initialize(xlsx_path, worksheet_names = ['all'])
|
40
37
|
@xlsx_path = Pathname.new(xlsx_path).realpath.to_s
|
41
38
|
@worksheets = []
|
42
39
|
|
43
40
|
begin
|
44
|
-
xlsx= RubyXL::Parser.parse(@xlsx_path)
|
41
|
+
xlsx = RubyXL::Parser.parse(@xlsx_path)
|
45
42
|
|
46
|
-
#by default, operate on all worksheets
|
47
|
-
if worksheet_names == [
|
43
|
+
# by default, operate on all worksheets
|
44
|
+
if worksheet_names == ['all']
|
48
45
|
xlsx.worksheets.each do |xlsx_worksheet|
|
49
46
|
parse_xlsx_worksheet(xlsx_worksheet)
|
50
47
|
end
|
51
|
-
else #if specific worksheets are specified, operate on them
|
48
|
+
else # if specific worksheets are specified, operate on them
|
52
49
|
worksheet_names.each do |worksheet_name|
|
53
50
|
parse_xlsx_worksheet(xlsx[worksheet_name])
|
54
51
|
end
|
55
52
|
end
|
56
53
|
|
57
|
-
#save spreadsheet if changes have been made
|
54
|
+
# save spreadsheet if changes have been made
|
58
55
|
if @@changed
|
59
56
|
xlsx.write(@xlsx_path)
|
60
|
-
puts
|
57
|
+
puts '[ComponentFromSpreadsheet] Spreadsheet changes saved'
|
61
58
|
end
|
62
59
|
ensure
|
63
|
-
xlsx=nil
|
60
|
+
xlsx = nil
|
64
61
|
end
|
65
62
|
end
|
66
63
|
|
67
64
|
def save(save_path, chunk_size = 1000, delete_old_gather = false)
|
68
|
-
#FileUtils.rm_rf(save_path) if File.exists?(save_path) and File.directory?(save_path)
|
65
|
+
# FileUtils.rm_rf(save_path) if File.exists?(save_path) and File.directory?(save_path)
|
69
66
|
# TODO: validate against taxonomy
|
70
67
|
|
71
68
|
@worksheets.each do |worksheet|
|
@@ -91,19 +88,19 @@ module BCL
|
|
91
88
|
author = values.delete_at(0)
|
92
89
|
datetime = values.delete_at(0)
|
93
90
|
if datetime.nil?
|
94
|
-
#puts "[ComponentSpreadsheet] WARNING missing the date in the datetime column in the spreadsheet - assuming today"
|
91
|
+
# puts "[ComponentSpreadsheet] WARNING missing the date in the datetime column in the spreadsheet - assuming today"
|
95
92
|
datetime = DateTime.new
|
96
93
|
end
|
97
94
|
|
98
95
|
comment = values.delete_at(0)
|
99
|
-
component_xml.add_provenance(author.to_s, datetime.strftime(
|
96
|
+
component_xml.add_provenance(author.to_s, datetime.strftime('%Y-%m-%d'), comment.to_s)
|
100
97
|
elsif /tag/i.match(header.name)
|
101
98
|
value = values.delete_at(0)
|
102
99
|
component_xml.add_tag(value)
|
103
100
|
elsif /attribute/i.match(header.name)
|
104
101
|
value = values.delete_at(0)
|
105
102
|
name = header.children[0]
|
106
|
-
units =
|
103
|
+
units = ''
|
107
104
|
if match_data = /(.*)\((.*)\)/.match(name)
|
108
105
|
name = match_data[1].strip
|
109
106
|
units = match_data[2].strip
|
@@ -126,12 +123,12 @@ module BCL
|
|
126
123
|
filename = values.delete_at(0)
|
127
124
|
filetype = values.delete_at(0)
|
128
125
|
filepath = values.delete_at(0)
|
129
|
-
#not all components(rows) have all files; skip if filename "" or nil
|
130
|
-
next if filename ==
|
131
|
-
#skip the file if it doesn't exist at the specified location
|
132
|
-
|
126
|
+
# not all components(rows) have all files; skip if filename "" or nil
|
127
|
+
next if filename == '' or filename.nil?
|
128
|
+
# skip the file if it doesn't exist at the specified location
|
129
|
+
unless File.exist?(filepath)
|
133
130
|
puts "[ComponentFromSpreadsheet] ERROR #{filepath} -> File does not exist, will not be included in component xml"
|
134
|
-
next #go to the next file
|
131
|
+
next # go to the next file
|
135
132
|
end
|
136
133
|
component_xml.add_file(software_program, version, filepath, filename, filetype)
|
137
134
|
else
|
@@ -150,22 +147,22 @@ module BCL
|
|
150
147
|
|
151
148
|
def parse_xlsx_worksheet(xlsx_worksheet)
|
152
149
|
worksheet = WorksheetStruct.new
|
153
|
-
worksheet.name = xlsx_worksheet[0][0].value #get A1, order is: row, col
|
150
|
+
worksheet.name = xlsx_worksheet[0][0].value # get A1, order is: row, col
|
154
151
|
worksheet.components = []
|
155
152
|
puts "[ComponentFromSpreadsheet] Starting parsing components of type #{worksheet.name}"
|
156
153
|
|
157
154
|
# find number of rows, first column should be name, should not be empty
|
158
155
|
|
159
156
|
xlsx_data = xlsx_worksheet.extract_data
|
160
|
-
#puts "Data: #{xlsx_data.inspect}"
|
157
|
+
# puts "Data: #{xlsx_data.inspect}"
|
161
158
|
|
162
159
|
num_rows = xlsx_data.size
|
163
|
-
#puts "Number of Rows: #{xlsx_data.size}"
|
160
|
+
# puts "Number of Rows: #{xlsx_data.size}"
|
164
161
|
num_rows = 2
|
165
|
-
while true
|
162
|
+
while true
|
166
163
|
test = xlsx_data[num_rows][0]
|
167
164
|
if test.nil? or test.empty?
|
168
|
-
#num_rows -= 1
|
165
|
+
# num_rows -= 1
|
169
166
|
break
|
170
167
|
end
|
171
168
|
num_rows += 1
|
@@ -176,12 +173,12 @@ module BCL
|
|
176
173
|
header = nil
|
177
174
|
max_col = nil
|
178
175
|
|
179
|
-
xlsx_data[0].each_with_index do |
|
176
|
+
xlsx_data[0].each_with_index do |_col, index|
|
180
177
|
value1 = xlsx_data[0][index]
|
181
178
|
value2 = xlsx_data[1][index]
|
182
179
|
|
183
180
|
if not value1.nil? and not value1.empty?
|
184
|
-
|
181
|
+
unless header.nil?
|
185
182
|
headers << header
|
186
183
|
end
|
187
184
|
header = HeaderStruct.new
|
@@ -190,7 +187,7 @@ module BCL
|
|
190
187
|
end
|
191
188
|
|
192
189
|
if not value2.nil? and not value2.empty?
|
193
|
-
|
190
|
+
unless header.nil?
|
194
191
|
header.children << value2
|
195
192
|
end
|
196
193
|
end
|
@@ -202,18 +199,18 @@ module BCL
|
|
202
199
|
max_col = index
|
203
200
|
end
|
204
201
|
|
205
|
-
|
202
|
+
unless header.nil?
|
206
203
|
headers << header
|
207
204
|
end
|
208
205
|
|
209
|
-
|
210
|
-
headers[0].name =
|
206
|
+
unless headers.empty?
|
207
|
+
headers[0].name = 'description'
|
211
208
|
end
|
212
209
|
|
213
210
|
puts " Found #{num_rows - 2} components"
|
214
211
|
|
215
212
|
components = []
|
216
|
-
for i in 2..num_rows-1 do
|
213
|
+
for i in 2..num_rows - 1 do
|
217
214
|
component = ComponentStruct.new
|
218
215
|
component.row = i
|
219
216
|
|