bcl 0.5.9 → 0.7.1

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.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +21 -0
  3. data/.rubocop.yml +8 -0
  4. data/CHANGELOG.md +79 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.md +27 -0
  7. data/README.md +40 -0
  8. data/Rakefile +347 -0
  9. data/bcl.gemspec +48 -0
  10. data/lib/bcl/base_xml.rb +31 -15
  11. data/lib/bcl/component.rb +32 -16
  12. data/lib/bcl/component_from_spreadsheet.rb +37 -23
  13. data/lib/bcl/component_methods.rb +52 -38
  14. data/lib/bcl/core_ext.rb +31 -15
  15. data/lib/bcl/tar_ball.rb +31 -15
  16. data/lib/bcl/version.rb +32 -16
  17. data/lib/bcl.rb +37 -4
  18. data/schemas/v2/component_2012_11_08.xsd +291 -0
  19. data/schemas/v2/measure_2013_3_26.xsd +153 -0
  20. data/schemas/v3/common_bcl_v3.xsd +422 -0
  21. data/schemas/v3/component_v3.xsd +445 -0
  22. data/schemas/v3/measure_v3.xsd +496 -0
  23. metadata +102 -81
  24. data/lib/bcl/component_spreadsheet.rb +0 -287
  25. data/lib/bcl/master_taxonomy.rb +0 -528
  26. data/lib/files/downloads/40237ee0-5ea7-0130-ad9b-14109fdf0b37.tar.gz +0 -0
  27. data/lib/files/staged/components/Asphalt_Shingles_1_8_in/Asphalt_Shingles_1_8_in.tar.gz +0 -0
  28. data/lib/files/staged/components/Asphalt_Shingles_1_8_in/component.xml +0 -81
  29. data/lib/files/staged/components/Built_up_Roofing_3_8_in/Built_up_Roofing_3_8_in.tar.gz +0 -0
  30. data/lib/files/staged/components/Built_up_Roofing_3_8_in/component.xml +0 -76
  31. data/lib/files/staged/components/Metal_Surface_1_16_in/Metal_Surface_1_16_in.tar.gz +0 -0
  32. data/lib/files/staged/components/Metal_Surface_1_16_in/component.xml +0 -76
  33. data/lib/files/staged/components/Shingle_Backer_1_4_in/Shingle_Backer_1_4_in.tar.gz +0 -0
  34. data/lib/files/staged/components/Shingle_Backer_1_4_in/component.xml +0 -81
  35. data/lib/files/staged/components/Shingle_Backer_3_8_in/Shingle_Backer_3_8_in.tar.gz +0 -0
  36. data/lib/files/staged/components/Shingle_Backer_3_8_in/component.xml +0 -81
  37. data/lib/files/staged/components/Wood_Shingles_1_4_in/Wood_Shingles_1_4_in.tar.gz +0 -0
  38. data/lib/files/staged/components/Wood_Shingles_1_4_in/component.xml +0 -81
  39. data/lib/files/staged/gather/1/Asphalt_Shingles_1_8_in.tar.gz +0 -0
  40. data/lib/files/staged/gather/1/Built_up_Roofing_3_8_in.tar.gz +0 -0
  41. data/lib/files/staged/gather/1/Metal_Surface_1_16_in.tar.gz +0 -0
  42. data/lib/files/staged/gather/1/Shingle_Backer_1_4_in.tar.gz +0 -0
  43. data/lib/files/staged/gather/1/Shingle_Backer_3_8_in.tar.gz +0 -0
  44. data/lib/files/staged/gather/1/Wood_Shingles_1_4_in.tar.gz +0 -0
  45. data/lib/files/staged/gather/components_1.tar.gz +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e73294b8462def2d2ff8831ec1b3e334efcf47e4
4
- data.tar.gz: 535c60ceb7b0095ec0fe6952d3b4ef0788c9b5d9
2
+ SHA256:
3
+ metadata.gz: 6a9c714a1d731180ba6a697a3f945d0269ea258d381b31d83c91752415e60603
4
+ data.tar.gz: f86719936cbb27b79dd812174d5dc1707fa4426439879a16cfc78f9cb8f2666b
5
5
  SHA512:
6
- metadata.gz: 8ebe642bcbf101803db171a0af1916a8bb9b4b883924bc07fd30c25c16614f34ef75733d333607eb1a511a1a70fcf5a8ec8ebae63c0893184f84d0059a54f1fd
7
- data.tar.gz: 7f61168eb018bd9db461ecbd8f96fd0b17d86fe600deaa908e88a1b6675101fb21901322bed63e81710d469bd9df3d51e668a7f2e2f7552385eb5958e0049828
6
+ metadata.gz: 9d0fa86c270c26fd224153d5a8179ff24c46b9f27373879c7a1c140279100098da8c83167345f5518c72f14fd6a7c5c22e50506d9fec8ed258f74afa72dfaade
7
+ data.tar.gz: 713bfd1a0e94a4a4c7b5cdd702ab250c82cd64e1b8188d810a0879fc9b513ec138c8168988cb0242fedfc9deb1d0e58e61a6e5154fea159c88439d9e2eae1743
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ .DS_Store
2
+ .bundle
3
+ .idea
4
+ .ruby-version
5
+ .Rhistory
6
+ faraday.log
7
+ gems/
8
+ *.swp
9
+ *.gem
10
+ tmp/*
11
+ rubocop-results.xml
12
+ .rubocop-http*
13
+ Gemfile.lock
14
+ /spec/bcl/output
15
+ /spec/reports
16
+ /spec/api/resources/*.receipt
17
+ measures/
18
+ staged/
19
+ lib/files/staged/
20
+ lib/files/downloads/
21
+ .rubocop-https*
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'measures/**/*'
4
+ - 'spec/api/resources/measure_example/**/*'
5
+ - 'gems/**/*'
6
+
7
+ inherit_from:
8
+ - http://s3.amazonaws.com/openstudio-resources/styles/rubocop_v3.yml
data/CHANGELOG.md ADDED
@@ -0,0 +1,79 @@
1
+ # Change Log
2
+
3
+ ## Version 0.7.1
4
+ * Update license to standard OpenStudio 4-clause BSD license
5
+ * Upgrade dependencies for security
6
+
7
+ ## Version 0.7.0
8
+ * Support Ruby > 2.7
9
+ * Minimum version of OpenStudio Measure Tester Gem to 0.3.0
10
+ * Update copyrights
11
+
12
+ ## Version 0.6.1
13
+ * Remove dependency for winole (`require 'win32ole'`). This affects the reading of the component spreadsheets and the
14
+ the master taxomony.
15
+ * Use new rubocop (v3) from s3 openstudio-resources
16
+
17
+ ## Version 0.6.0
18
+ * Support Ruby > 2.5
19
+ * Update dependencies
20
+
21
+ ## Version 0.5.9
22
+ * Update copyrights
23
+ * Update rubocop version (security)
24
+ * Updates to support OpenStudio Extension gem
25
+
26
+ ## Version 0.5.8
27
+ * Cleanup code (rubocop)
28
+
29
+ ## Version 0.5.7
30
+ * Update to_underscore method to not break apart EnergyPlus nor OpenStudio
31
+
32
+ ## Version 0.5.6
33
+ * Allow no display name when parsing measure arguments (measure argument does not have setDisplayName)
34
+ * Parse measure display name, description, modeler description, and argument units
35
+ * Add basic validation that prints to the terminal
36
+ * Upgrade spec and ci reporter
37
+ * New branch for development (develop)
38
+
39
+ ## Version 0.5.5
40
+ * Read as binary for .tar.gz
41
+ * When downloading and parsing measures, skip instance where the measure class name is already the directory name.
42
+
43
+ ## Version 0.5.2-4
44
+ * Remove libxml dependency
45
+ * Add OpenStudio static measure parsing method
46
+ * Add translate to CSV from static measures to support OpenStudio-analysis spreadsheet
47
+ * Fix Group ID
48
+ * Pull UUID out of tar.gz files
49
+ * More testing around measures and components API
50
+ * Rubocop
51
+
52
+ ## Version 0.5.1
53
+ * Fix bug when parsing BCL measures and nil arguments
54
+
55
+ ## Version 0.5.0
56
+ * Remove support for Ruby 1.8.7. Only supporting > 1.9.2
57
+ * Remove JSON gem. Using multi_json
58
+ * Removed obsolete tests
59
+ * Removed RestClient in favor of Faraday (used for testing)
60
+
61
+ ## Version 0.4.1
62
+ * Several fixes to previous gem
63
+ * Put required gems into the gemspec
64
+
65
+ ### New Features
66
+ * Able to specify the group_id when you create the component methods
67
+ * Added parsing of BCL measures for extracting arguments
68
+
69
+ ## Version 0.3.7
70
+
71
+ ### New Features
72
+ * Added a search for measures that returns the JSON
73
+ * Added the ability to download a component (measure or component). Result returns the file data that needes to be persisted.
74
+
75
+ ## Version 0.1.7
76
+
77
+ ### New Features
78
+ * Added rspec for testing
79
+ * Made a datatype method in BCL class to resolve the appropriate values per BCL convention (i.e. int, float, string)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,27 @@
1
+ OpenStudio(R), Copyright (c) 2008-2021, Alliance for Sustainable Energy, LLC. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted
4
+ provided that the following conditions are met:
5
+
6
+ (1) Redistributions of source code must retain the above copyright notice, this list of conditions
7
+ and the following disclaimer.
8
+
9
+ (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+ (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse
13
+ or promote products derived from this software without specific prior written permission from the
14
+ respective party.
15
+
16
+ (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other
17
+ derivative works may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar
18
+ designation without specific prior written permission from Alliance for Sustainable Energy, LLC.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
21
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES GOVERNMENT,
23
+ OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
25
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # BCL Gem
2
+
3
+ All the methods to build, test, and release the gem available as rake tasks via bundler/gem_tasks. Note that you can see all the rake tasks by calling `rake -T` at the command line.
4
+
5
+ ## Building BCL Gem
6
+
7
+ If this is a new version that will be release first edit the ./lib/bcl/version.rb file and increment the version number. This will automatically propagate through the build process.
8
+
9
+ `rake build`
10
+
11
+ To install:
12
+
13
+ `rake install`
14
+
15
+ ## Releasing Gem
16
+
17
+ Note: Releasing the gem will call the build command, tag it in Git, and push to rubygems.
18
+
19
+ run `rake release`
20
+
21
+ ## Testing
22
+
23
+ `rake spec`
24
+
25
+ ## Uninstall
26
+
27
+ run `gem uninstall bcl -a`
28
+
29
+ ## Workflow for pushing content to BCL
30
+
31
+ run `rake bcl:stage_and_upload[/path/to/content, resetFlag]`
32
+
33
+ where `path/to/content` is a path to the directory of measures or components to upload and `resetFlag` is a boolean flag indicating whether to clear already staged content and receipt files (true), or to keep the staged content and receipt files (false).
34
+
35
+ Staging and Uploading tasks can be called separately:
36
+
37
+ `rake bcl:stage_content[/path/to/content, resetFlag]`
38
+
39
+ `rake bcl:upload_content[resetFlag]`
40
+
data/Rakefile ADDED
@@ -0,0 +1,347 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2021, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
24
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
27
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
28
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
30
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
36
+ require 'bundler'
37
+ Bundler.setup
38
+
39
+ require 'rake'
40
+ require 'rspec/core/rake_task'
41
+ require 'bundler/gem_tasks'
42
+
43
+ require 'pathname'
44
+
45
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
46
+ require 'bcl'
47
+ require 'bcl/version'
48
+
49
+ RSpec::Core::RakeTask.new('spec') do |spec|
50
+ puts 'running tests...'
51
+ spec.rspec_opts = ['--format', 'progress']
52
+ spec.pattern = 'spec/**/*_spec.rb'
53
+ end
54
+
55
+ namespace :test do
56
+ desc 'test search all functionality'
57
+ task :search_all do
58
+ # search with all=true
59
+ # ensure that a) results are returned (> 0) and b) [:measure][:name] is a string
60
+ # search with all=false
61
+ # ensure the same a) and b) as above
62
+ bcl = BCL::ComponentMethods.new
63
+ bcl.login
64
+ results = bcl.search('Add', 'show_rows=10', false)
65
+ puts "there are #{results[:result].count} results"
66
+ results[:result].each do |res|
67
+ puts (res[:measure][:name]).to_s
68
+ end
69
+ end
70
+
71
+ desc 'test measure upload'
72
+ task :measure_upload do
73
+ bcl = BCL::ComponentMethods.new
74
+ bcl.login
75
+ filename = "#{File.dirname(__FILE__)}/spec/api/resources/measure_original.tar.gz"
76
+ valid, res = bcl.push_content(filename, false, 'nrel_measure')
77
+ end
78
+
79
+ desc 'test the BCL login credentials defined in .bcl/config.yml'
80
+ task :bcl_login do
81
+ bcl = BCL::ComponentMethods.new
82
+ bcl.login
83
+ end
84
+
85
+ desc 'test component spreadsheet'
86
+ task :spreadsheet do
87
+ bclcomponents = BCL::ComponentFromSpreadsheet.new(File.expand_path('lib/files/Components.xls', __dir__), ['Roofing'])
88
+ bclcomponents.save(File.expand_path('lib/files/staged', __dir__))
89
+ end
90
+
91
+ desc 'test measure download'
92
+ task :measure_download do
93
+ # find a component with keyword 'Ashrae'
94
+ query = 'ashrae'
95
+ filter = 'fq[]=bundle:nrel_component&show_rows=3'
96
+
97
+ bcl = BCL::ComponentMethods.new
98
+ bcl.login
99
+
100
+ results = bcl.search(query, filter)
101
+ uids = []
102
+ results[:result].each do |result|
103
+ uids << result[:component][:uuid]
104
+ end
105
+
106
+ content = bcl.download_component(uids[0])
107
+
108
+ # save as tar.gz
109
+ download_path = File.expand_path('lib/files/downloads', __dir__)
110
+ FileUtils.mkdir(download_path) if !File.exist? download_path
111
+ f = File.open("#{download_path}/#{uids[0]}.tar.gz", 'wb')
112
+ f.write(content)
113
+ end
114
+ end
115
+
116
+ namespace :bcl do
117
+ STAGED_PATH = Pathname.new(Dir.pwd + '/staged')
118
+
119
+ # initialize BCL and login
120
+ bcl = BCL::ComponentMethods.new
121
+ bcl.login
122
+
123
+ # to call: rake "bcl:stage_and_upload[/path/to/your/content/directory, true]"
124
+ # content_path arg: path to components or measures to upload
125
+ # reset flag:
126
+ # If TRUE: content in the staged directory will be re-generated and receipt files will be deleted.
127
+ # If FALSE, content that already exists in the staged directory will remain and content with receipt files will not be re-uploaded.
128
+ desc 'stage and push/update all content in a repo'
129
+ task :stage_and_upload, [:content_path, :reset] do |t, args|
130
+ options = { reset: false }
131
+ options[:content_path] = Pathname.new args[:content_path]
132
+ if args[:reset].to_s == 'true'
133
+ options[:reset] = true
134
+ end
135
+
136
+ current_dir = Dir.pwd
137
+
138
+ # stage content
139
+ Rake.application.invoke_task("bcl:stage_content[#{options[:content_path]}, #{options[:reset]}]")
140
+ Dir.chdir(current_dir)
141
+
142
+ # upload (new and updated). pass in skip flag
143
+ Rake.application.invoke_task("bcl:upload_content[#{options[:reset]}]")
144
+ end
145
+
146
+ # to call: rake "bcl:upload_content[true]"
147
+ # TODO: catch errors and continue
148
+ desc 'upload/update BCL content'
149
+ task :upload_content, [:reset] do |t, args|
150
+ # process options
151
+ options = { reset: false }
152
+ if args[:reset].to_s == 'true'
153
+ options[:reset] = true
154
+ end
155
+
156
+ total_count = 0
157
+ successes = 0
158
+ errors = 0
159
+ skipped = 0
160
+
161
+ # grab all the new measure and component tar files and push to bcl
162
+ ['measure', 'component'].each do |content_type|
163
+ items = []
164
+ paths = Pathname.glob(STAGED_PATH.to_s + "/push/#{content_type}/*.tar.gz")
165
+ paths.each do |path|
166
+ # puts path
167
+ items << path.to_s
168
+ end
169
+
170
+ items.each do |item|
171
+ puts item.split('/').last
172
+ total_count += 1
173
+
174
+ receipt_file = File.dirname(item) + '/' + File.basename(item, '.tar.gz') + '.receipt'
175
+ if !options[:reset] && File.exist?(receipt_file)
176
+ skipped += 1
177
+ puts 'SKIP: receipt file found'
178
+ next
179
+ end
180
+
181
+ valid, res = bcl.push_content(item, true, "nrel_#{content_type}")
182
+ if valid
183
+ successes += 1
184
+ else
185
+ errors += 1
186
+ if res.key?(:error)
187
+ puts " ERROR MESSAGE: #{res[:error]}"
188
+ else
189
+ puts "ERROR: #{res.inspect.chomp}"
190
+ end
191
+ end
192
+ puts '', '---'
193
+ end
194
+ end
195
+
196
+ # grab all the updated content (measures and components) tar files and push to bcl
197
+ items = []
198
+ paths = Pathname.glob(STAGED_PATH.to_s + '/update/*.tar.gz')
199
+ paths.each do |path|
200
+ # puts path
201
+ items << path.to_s
202
+ end
203
+ items.each do |item|
204
+ puts item.split('/').last
205
+ total_count += 1
206
+
207
+ receipt_file = File.dirname(item) + '/' + File.basename(item, '.tar.gz') + '.receipt'
208
+ if !options[:reset] && File.exist?(receipt_file)
209
+ skipped += 1
210
+ puts 'SKIP: receipt file found'
211
+ next
212
+ end
213
+
214
+ valid, res = bcl.update_content(item, true)
215
+ if valid
216
+ successes += 1
217
+ else
218
+ errors += 1
219
+ if res.key?(:error)
220
+ puts " ERROR MESSAGE: #{res[:error]}"
221
+ else
222
+ puts "ERROR MESSAGE: #{res.inspect.chomp}"
223
+ end
224
+ end
225
+ puts '', '---'
226
+ end
227
+
228
+ puts "****UPLOAD DONE**** #{total_count} total, #{successes} success, #{errors} failures, #{skipped} skipped"
229
+ end
230
+
231
+ # to call: rake "bcl:stage_content[/path/to/your/content/directory, true]"
232
+ desc 'stage content for BCL'
233
+ task :stage_content, [:content_path, :reset] do |t, args|
234
+ # process options
235
+ options = { reset: false }
236
+ options[:content_path] = Pathname.new args[:content_path]
237
+ if args[:reset].to_s == 'true'
238
+ options[:reset] = true
239
+ end
240
+ puts "OPTIONS -- content_path: #{options[:content_path]}, reset: #{options[:reset]}"
241
+
242
+ FileUtils.mkdir_p(STAGED_PATH)
243
+
244
+ # delete existing tarballs if reset is true
245
+ if options[:reset]
246
+ FileUtils.rm_rf(Dir.glob("#{STAGED_PATH}/*"))
247
+ end
248
+
249
+ # create new and existing directories
250
+ FileUtils.mkdir_p(STAGED_PATH.to_s + '/update')
251
+ FileUtils.mkdir_p(STAGED_PATH.to_s + '/push/component')
252
+ FileUtils.mkdir_p(STAGED_PATH.to_s + '/push/measure')
253
+
254
+ # keep track of noop, update, push
255
+ noops = 0
256
+ new_ones = 0
257
+ updates = 0
258
+
259
+ # get all content directories to process
260
+ dirs = Dir.glob("#{options[:content_path]}/*")
261
+
262
+ dirs.each do |dir|
263
+ next if dir.include?('Rakefile')
264
+
265
+ current_d = Dir.pwd
266
+ content_name = File.basename(dir)
267
+ puts '', '---'
268
+ puts "Generating #{content_name}"
269
+
270
+ Dir.chdir(dir)
271
+
272
+ # figure out whether to upload new or update existing
273
+ files = Pathname.glob('**/*')
274
+ uuid = nil
275
+ vid = nil
276
+ content_type = 'measure'
277
+
278
+ paths = []
279
+ files.each do |file|
280
+ # don't tar tests/outputs directory
281
+ next if file.to_s.start_with?('tests/output') # From measure testing process
282
+ next if file.to_s.start_with?('tests/test') # From openstudio-measure-tester-gem
283
+ next if file.to_s.start_with?('tests/coverage') # From openstudio-measure-tester-gem
284
+ next if file.to_s.start_with?('test_results') # From openstudio-measure-tester-gem
285
+
286
+ paths << file.to_s
287
+ if file.to_s =~ /^.{0,2}component.xml$/ || file.to_s =~ /^.{0,2}measure.xml$/
288
+ if file.to_s.match?(/^.{0,2}component.xml$/)
289
+ content_type = 'component'
290
+ end
291
+ # extract uuid and vid
292
+ uuid, vid = bcl.uuid_vid_from_xml(file)
293
+ end
294
+ end
295
+ puts "UUID: #{uuid}, VID: #{vid}"
296
+
297
+ # note: if uuid is missing, will assume new content
298
+ action = bcl.search_by_uuid(uuid, vid)
299
+ puts "#{content_name} ACTION TO TAKE: #{action}"
300
+ # new content functionality needs to know if measure or component. update is agnostic.
301
+ if action == 'noop' # ignore up-to-date content
302
+ puts " - WARNING: local #{content_name} uuid and vid match BCL... no update will be performed"
303
+ noops += 1
304
+ next
305
+ elsif action == 'update'
306
+ # puts "#{content_name} labeled as update for BCL"
307
+ destination = STAGED_PATH.join(action, "#{content_name}.tar.gz")
308
+ updates += 1
309
+ elsif action == 'push'
310
+ # puts "#{content_name} labeled as new content for BCL"
311
+ destination = STAGED_PATH.join(action, content_type, "#{content_name}.tar.gz")
312
+ new_ones += 1
313
+ end
314
+
315
+ puts "destination: #{destination}"
316
+
317
+ # copy over only if 'reset_receipts' is set to TRUE. otherwise ignore if file exists already
318
+ if File.exist?(destination)
319
+ if options[:reset]
320
+ FileUtils.rm(destination)
321
+ BCL.tarball(destination, paths)
322
+ else
323
+ puts "*** WARNING: File #{content_name}.tar.gz already exists in staged directory... keeping existing file. To overwrite, set reset_receipts arg to true ***"
324
+ end
325
+ else
326
+ BCL.tarball(destination, paths)
327
+ end
328
+ Dir.chdir(current_d)
329
+ end
330
+ puts '', "****STAGING DONE**** #{new_ones} new content, #{updates} updates, #{noops} skipped (already up-to-date on BCL)", ''
331
+ end
332
+ end
333
+
334
+ require 'rubocop/rake_task'
335
+ desc 'Run RuboCop on the lib directory'
336
+ RuboCop::RakeTask.new(:rubocop) do |task|
337
+ # only show the files with failures
338
+ task.options = ['--no-color', '--out=rubocop-results.xml']
339
+ task.formatters = ['RuboCop::Formatter::CheckstyleFormatter']
340
+ task.requires = ['rubocop/formatter/checkstyle_formatter']
341
+ # don't abort rake on failure
342
+ task.fail_on_error = false
343
+ end
344
+
345
+ desc 'Default task run rspec tests'
346
+ task test: :spec
347
+ task default: :spec