bcl 0.5.7.pre → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 35f0906c51b3ebb744a4980ed17a074f6221b19d
4
- data.tar.gz: 59bf6f68230139b3a8032954f87f4063cfb03fb9
2
+ SHA256:
3
+ metadata.gz: 4073198c37e54e15c0465cf53849145a45e4f32e7037bbcd7832427f7d66afbb
4
+ data.tar.gz: 88c9cf9fbc81084c3b65d06db4546c71f7f26782b2a201149e0be8ee19ce4ecf
5
5
  SHA512:
6
- metadata.gz: 3fd9470fcb35faccde668b6230fedd7a63938ed63a32019b4dae7076ab83c0ba503f1524548ffdfb43647f87a62712712e06f686db593f85bc0700674a533a7f
7
- data.tar.gz: 9f8d0e630fa89c9700020d056d0f823c347a49d5de1febcd399efc9a502585da8befa00d428c17a222f12b5007a825365c18ad232014c107f3dd6683e746363a
6
+ metadata.gz: 20fd7f2591c9fbe6cf7372d3f03dbb3023f54e51da5faff2cb2cb15e34a757451c2773678f8fb0add969b43ea3ab0c2e6c2770a585e8f981103a9d3ad34ed476
7
+ data.tar.gz: 685bd62bee9ffab69be8da4e84dda1508ba46f6e9c3a8348a62264203a606f48c7f5b5dc95ebed7b2cca73acd27f0caec66c81c57b4542cf5db20cb3af27983d
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,75 @@
1
+ # Change Log
2
+
3
+ ## Version 0.7.0
4
+ * Support Ruby > 2.7
5
+ * Minimum version of OpenStudio Measure Tester Gem to 0.3.0
6
+ * Update copyrights
7
+
8
+ ## Version 0.6.1
9
+ * Remove dependency for winole (`require 'win32ole'`). This affects the reading of the component spreadsheets and the
10
+ the master taxomony.
11
+ * Use new rubocop (v3) from s3 openstudio-resources
12
+
13
+ ## Version 0.6.0
14
+ * Support Ruby > 2.5
15
+ * Update dependencies
16
+
17
+ ## Version 0.5.9
18
+ * Update copyrights
19
+ * Update rubocop version (security)
20
+ * Updates to support OpenStudio Extension gem
21
+
22
+ ## Version 0.5.8
23
+ * Cleanup code (rubocop)
24
+
25
+ ## Version 0.5.7
26
+ * Update to_underscore method to not break apart EnergyPlus nor OpenStudio
27
+
28
+ ## Version 0.5.6
29
+ * Allow no display name when parsing measure arguments (measure argument does not have setDisplayName)
30
+ * Parse measure display name, description, modeler description, and argument units
31
+ * Add basic validation that prints to the terminal
32
+ * Upgrade spec and ci reporter
33
+ * New branch for development (develop)
34
+
35
+ ## Version 0.5.5
36
+ * Read as binary for .tar.gz
37
+ * When downloading and parsing measures, skip instance where the measure class name is already the directory name.
38
+
39
+ ## Version 0.5.2-4
40
+ * Remove libxml dependency
41
+ * Add OpenStudio static measure parsing method
42
+ * Add translate to CSV from static measures to support OpenStudio-analysis spreadsheet
43
+ * Fix Group ID
44
+ * Pull UUID out of tar.gz files
45
+ * More testing around measures and components API
46
+ * Rubocop
47
+
48
+ ## Version 0.5.1
49
+ * Fix bug when parsing BCL measures and nil arguments
50
+
51
+ ## Version 0.5.0
52
+ * Remove support for Ruby 1.8.7. Only supporting > 1.9.2
53
+ * Remove JSON gem. Using multi_json
54
+ * Removed obsolete tests
55
+ * Removed RestClient in favor of Faraday (used for testing)
56
+
57
+ ## Version 0.4.1
58
+ * Several fixes to previous gem
59
+ * Put required gems into the gemspec
60
+
61
+ ### New Features
62
+ * Able to specify the group_id when you create the component methods
63
+ * Added parsing of BCL measures for extracting arguments
64
+
65
+ ## Version 0.3.7
66
+
67
+ ### New Features
68
+ * Added a search for measures that returns the JSON
69
+ * Added the ability to download a component (measure or component). Result returns the file data that needes to be persisted.
70
+
71
+ ## Version 0.1.7
72
+
73
+ ### New Features
74
+ * Added rspec for testing
75
+ * 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,11 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'rake'
5
+
6
+ group :test do
7
+ gem 'ci_reporter_rspec'
8
+ gem 'rspec', '~> 3.7.0'
9
+ gem 'rubocop', '~> 0.54'
10
+ gem 'rubocop-checkstyle_formatter', '~> 0.4'
11
+ end
data/License.txt ADDED
@@ -0,0 +1,65 @@
1
+ Copyright (c) 2008-2021, Alliance for Sustainable Energy.
2
+ All rights reserved.
3
+
4
+ NOTICE
5
+
6
+ This computer software (Software) is code in development prepared by the
7
+ Alliance for Sustainable Energy, (hereinafter the "Contractor"), under
8
+ Contract DE-AC36-08GO28308 (Contract) with the Department of Energy (DOE).
9
+ The United States Government has been granted for itself and others acting
10
+ on its behalf a paid-up, non-exclusive, irrevocable, worldwide license in
11
+ the Software to reproduce, prepare derivative works, and perform publicly
12
+ and display publicly. Beginning five (5) years after the date permission
13
+ to assert copyright is obtained from the DOE, and subject to any
14
+ subsequent five (5) year renewals, the United States Government is granted
15
+ for itself and others acting on its behalf a paid-up, non-exclusive,
16
+ irrevocable, worldwide license in the Software to reproduce, prepare
17
+ derivative works, distribute copies to the public, perform publicly and
18
+ display publicly, and to permit others to do so. If the Contractor ceases
19
+ to make this computer software available, it may be obtained from DOE's
20
+ Office of Scientific and Technical Information's Energy Science and
21
+ Technology Software Center (ESTSC) at P.O. Box 1020, Oak Ridge, TN 37831-
22
+ 1020.
23
+
24
+ DISCLAIMER
25
+
26
+ THIS SOFTWARE IS PROVIDED BY THE CONTRACTOR "AS IS" AND ANY EXPRESS OR
27
+ IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
29
+ NO EVENT SHALL THE CONTRACTOR OR THE U.S. GOVERNMENT BE LIABLE FOR ANY
30
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER,
31
+ INCLUDING BUT NOT LIMITED TO CLAIMS ASSOCIATED WITH THE LOSS OF DATA OR
32
+ PROFITS, WHICH MAY RESULT FROM AN ACTION IN CONTRACT, NEGLIGENCE OR OTHER
33
+ TORTIOUS CLAIM THAT ARISES OUT OF OR IN CONNECTION WITH THE ACCESS, USE OR
34
+ PERFORMANCE OF THIS SOFTWARE.
35
+
36
+ YOU AGREE TO INDEMNIFY DOE/NREL/ALLIANCE, AND ITS SUBSIDIARIES,
37
+ AFFILIATES, OFFICERS, AGENTS, AND EMPLOYEES AGAINST ANY CLAIM OR DEMAND,
38
+ INCLUDING REASONABLE ATTORNEYS' FEES, RELATED TO YOUR USE OF THESE DATA.
39
+
40
+ DOE/NREL/Alliance is not obligated to provide the user with any support,
41
+ consulting, training or assistance of any kind with regard to the use of
42
+ these Data or to provide the user with any updates, revisions or new
43
+ versions of these Data.
44
+
45
+ The names DOE/NREL/Alliance may not be used in any advertising or
46
+ publicity to endorse or promote any products or commercial entities unless
47
+ specific written permission is obtained from DOE/NREL/Alliance.
48
+
49
+
50
+ OPEN SOURCE LICENSE
51
+
52
+ This library is free software; you can redistribute it and/or
53
+ modify it under the terms of the GNU Lesser General Public
54
+ License as published by the Free Software Foundation; either
55
+ version 2.1 of the License, or (at your option) any later version.
56
+
57
+ This library is distributed in the hope that it will be useful,
58
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
59
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60
+ Lesser General Public License for more details here.
61
+
62
+ You should have received a copy of the GNU Lesser General Public
63
+ License along with this library; if not, write to the Free Software
64
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
65
+
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,312 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+ require 'bundler/gem_tasks'
7
+
8
+ require 'pathname'
9
+
10
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
11
+ require 'bcl'
12
+ require 'bcl/version'
13
+
14
+ RSpec::Core::RakeTask.new('spec') do |spec|
15
+ puts 'running tests...'
16
+ spec.rspec_opts = ['--format', 'progress']
17
+ spec.pattern = 'spec/**/*_spec.rb'
18
+ end
19
+
20
+ namespace :test do
21
+ desc 'test search all functionality'
22
+ task :search_all do
23
+ # search with all=true
24
+ # ensure that a) results are returned (> 0) and b) [:measure][:name] is a string
25
+ # search with all=false
26
+ # ensure the same a) and b) as above
27
+ bcl = BCL::ComponentMethods.new
28
+ bcl.login
29
+ results = bcl.search('Add', 'show_rows=10', false)
30
+ puts "there are #{results[:result].count} results"
31
+ results[:result].each do |res|
32
+ puts (res[:measure][:name]).to_s
33
+ end
34
+ end
35
+
36
+ desc 'test measure upload'
37
+ task :measure_upload do
38
+ bcl = BCL::ComponentMethods.new
39
+ bcl.login
40
+ filename = "#{File.dirname(__FILE__)}/spec/api/resources/measure_original.tar.gz"
41
+ valid, res = bcl.push_content(filename, false, 'nrel_measure')
42
+ end
43
+
44
+ desc 'test the BCL login credentials defined in .bcl/config.yml'
45
+ task :bcl_login do
46
+ bcl = BCL::ComponentMethods.new
47
+ bcl.login
48
+ end
49
+
50
+ desc 'test component spreadsheet'
51
+ task :spreadsheet do
52
+ bclcomponents = BCL::ComponentFromSpreadsheet.new(File.expand_path('lib/files/Components.xls', __dir__), ['Roofing'])
53
+ bclcomponents.save(File.expand_path('lib/files/staged', __dir__))
54
+ end
55
+
56
+ desc 'test measure download'
57
+ task :measure_download do
58
+ # find a component with keyword 'Ashrae'
59
+ query = 'ashrae'
60
+ filter = 'fq[]=bundle:nrel_component&show_rows=3'
61
+
62
+ bcl = BCL::ComponentMethods.new
63
+ bcl.login
64
+
65
+ results = bcl.search(query, filter)
66
+ uids = []
67
+ results[:result].each do |result|
68
+ uids << result[:component][:uuid]
69
+ end
70
+
71
+ content = bcl.download_component(uids[0])
72
+
73
+ # save as tar.gz
74
+ download_path = File.expand_path('lib/files/downloads', __dir__)
75
+ FileUtils.mkdir(download_path) if !File.exist? download_path
76
+ f = File.open("#{download_path}/#{uids[0]}.tar.gz", 'wb')
77
+ f.write(content)
78
+ end
79
+ end
80
+
81
+ namespace :bcl do
82
+ STAGED_PATH = Pathname.new(Dir.pwd + '/staged')
83
+
84
+ # initialize BCL and login
85
+ bcl = BCL::ComponentMethods.new
86
+ bcl.login
87
+
88
+ # to call: rake "bcl:stage_and_upload[/path/to/your/content/directory, true]"
89
+ # content_path arg: path to components or measures to upload
90
+ # reset flag:
91
+ # If TRUE: content in the staged directory will be re-generated and receipt files will be deleted.
92
+ # If FALSE, content that already exists in the staged directory will remain and content with receipt files will not be re-uploaded.
93
+ desc 'stage and push/update all content in a repo'
94
+ task :stage_and_upload, [:content_path, :reset] do |t, args|
95
+ options = { reset: false }
96
+ options[:content_path] = Pathname.new args[:content_path]
97
+ if args[:reset].to_s == 'true'
98
+ options[:reset] = true
99
+ end
100
+
101
+ current_dir = Dir.pwd
102
+
103
+ # stage content
104
+ Rake.application.invoke_task("bcl:stage_content[#{options[:content_path]}, #{options[:reset]}]")
105
+ Dir.chdir(current_dir)
106
+
107
+ # upload (new and updated). pass in skip flag
108
+ Rake.application.invoke_task("bcl:upload_content[#{options[:reset]}]")
109
+ end
110
+
111
+ # to call: rake "bcl:upload_content[true]"
112
+ # TODO: catch errors and continue
113
+ desc 'upload/update BCL content'
114
+ task :upload_content, [:reset] do |t, args|
115
+ # process options
116
+ options = { reset: false }
117
+ if args[:reset].to_s == 'true'
118
+ options[:reset] = true
119
+ end
120
+
121
+ total_count = 0
122
+ successes = 0
123
+ errors = 0
124
+ skipped = 0
125
+
126
+ # grab all the new measure and component tar files and push to bcl
127
+ ['measure', 'component'].each do |content_type|
128
+ items = []
129
+ paths = Pathname.glob(STAGED_PATH.to_s + "/push/#{content_type}/*.tar.gz")
130
+ paths.each do |path|
131
+ # puts path
132
+ items << path.to_s
133
+ end
134
+
135
+ items.each do |item|
136
+ puts item.split('/').last
137
+ total_count += 1
138
+
139
+ receipt_file = File.dirname(item) + '/' + File.basename(item, '.tar.gz') + '.receipt'
140
+ if !options[:reset] && File.exist?(receipt_file)
141
+ skipped += 1
142
+ puts 'SKIP: receipt file found'
143
+ next
144
+ end
145
+
146
+ valid, res = bcl.push_content(item, true, "nrel_#{content_type}")
147
+ if valid
148
+ successes += 1
149
+ else
150
+ errors += 1
151
+ if res.key?(:error)
152
+ puts " ERROR MESSAGE: #{res[:error]}"
153
+ else
154
+ puts "ERROR: #{res.inspect.chomp}"
155
+ end
156
+ end
157
+ puts '', '---'
158
+ end
159
+ end
160
+
161
+ # grab all the updated content (measures and components) tar files and push to bcl
162
+ items = []
163
+ paths = Pathname.glob(STAGED_PATH.to_s + '/update/*.tar.gz')
164
+ paths.each do |path|
165
+ # puts path
166
+ items << path.to_s
167
+ end
168
+ items.each do |item|
169
+ puts item.split('/').last
170
+ total_count += 1
171
+
172
+ receipt_file = File.dirname(item) + '/' + File.basename(item, '.tar.gz') + '.receipt'
173
+ if !options[:reset] && File.exist?(receipt_file)
174
+ skipped += 1
175
+ puts 'SKIP: receipt file found'
176
+ next
177
+ end
178
+
179
+ valid, res = bcl.update_content(item, true)
180
+ if valid
181
+ successes += 1
182
+ else
183
+ errors += 1
184
+ if res.key?(:error)
185
+ puts " ERROR MESSAGE: #{res[:error]}"
186
+ else
187
+ puts "ERROR MESSAGE: #{res.inspect.chomp}"
188
+ end
189
+ end
190
+ puts '', '---'
191
+ end
192
+
193
+ puts "****UPLOAD DONE**** #{total_count} total, #{successes} success, #{errors} failures, #{skipped} skipped"
194
+ end
195
+
196
+ # to call: rake "bcl:stage_content[/path/to/your/content/directory, true]"
197
+ desc 'stage content for BCL'
198
+ task :stage_content, [:content_path, :reset] do |t, args|
199
+ # process options
200
+ options = { reset: false }
201
+ options[:content_path] = Pathname.new args[:content_path]
202
+ if args[:reset].to_s == 'true'
203
+ options[:reset] = true
204
+ end
205
+ puts "OPTIONS -- content_path: #{options[:content_path]}, reset: #{options[:reset]}"
206
+
207
+ FileUtils.mkdir_p(STAGED_PATH)
208
+
209
+ # delete existing tarballs if reset is true
210
+ if options[:reset]
211
+ FileUtils.rm_rf(Dir.glob("#{STAGED_PATH}/*"))
212
+ end
213
+
214
+ # create new and existing directories
215
+ FileUtils.mkdir_p(STAGED_PATH.to_s + '/update')
216
+ FileUtils.mkdir_p(STAGED_PATH.to_s + '/push/component')
217
+ FileUtils.mkdir_p(STAGED_PATH.to_s + '/push/measure')
218
+
219
+ # keep track of noop, update, push
220
+ noops = 0
221
+ new_ones = 0
222
+ updates = 0
223
+
224
+ # get all content directories to process
225
+ dirs = Dir.glob("#{options[:content_path]}/*")
226
+
227
+ dirs.each do |dir|
228
+ next if dir.include?('Rakefile')
229
+
230
+ current_d = Dir.pwd
231
+ content_name = File.basename(dir)
232
+ puts '', '---'
233
+ puts "Generating #{content_name}"
234
+
235
+ Dir.chdir(dir)
236
+
237
+ # figure out whether to upload new or update existing
238
+ files = Pathname.glob('**/*')
239
+ uuid = nil
240
+ vid = nil
241
+ content_type = 'measure'
242
+
243
+ paths = []
244
+ files.each do |file|
245
+ # don't tar tests/outputs directory
246
+ next if file.to_s.start_with?('tests/output') # From measure testing process
247
+ next if file.to_s.start_with?('tests/test') # From openstudio-measure-tester-gem
248
+ next if file.to_s.start_with?('tests/coverage') # From openstudio-measure-tester-gem
249
+ next if file.to_s.start_with?('test_results') # From openstudio-measure-tester-gem
250
+
251
+ paths << file.to_s
252
+ if file.to_s =~ /^.{0,2}component.xml$/ || file.to_s =~ /^.{0,2}measure.xml$/
253
+ if file.to_s.match?(/^.{0,2}component.xml$/)
254
+ content_type = 'component'
255
+ end
256
+ # extract uuid and vid
257
+ uuid, vid = bcl.uuid_vid_from_xml(file)
258
+ end
259
+ end
260
+ puts "UUID: #{uuid}, VID: #{vid}"
261
+
262
+ # note: if uuid is missing, will assume new content
263
+ action = bcl.search_by_uuid(uuid, vid)
264
+ puts "#{content_name} ACTION TO TAKE: #{action}"
265
+ # new content functionality needs to know if measure or component. update is agnostic.
266
+ if action == 'noop' # ignore up-to-date content
267
+ puts " - WARNING: local #{content_name} uuid and vid match BCL... no update will be performed"
268
+ noops += 1
269
+ next
270
+ elsif action == 'update'
271
+ # puts "#{content_name} labeled as update for BCL"
272
+ destination = STAGED_PATH.join(action, "#{content_name}.tar.gz")
273
+ updates += 1
274
+ elsif action == 'push'
275
+ # puts "#{content_name} labeled as new content for BCL"
276
+ destination = STAGED_PATH.join(action, content_type, "#{content_name}.tar.gz")
277
+ new_ones += 1
278
+ end
279
+
280
+ puts "destination: #{destination}"
281
+
282
+ # copy over only if 'reset_receipts' is set to TRUE. otherwise ignore if file exists already
283
+ if File.exist?(destination)
284
+ if options[:reset]
285
+ FileUtils.rm(destination)
286
+ BCL.tarball(destination, paths)
287
+ else
288
+ puts "*** WARNING: File #{content_name}.tar.gz already exists in staged directory... keeping existing file. To overwrite, set reset_receipts arg to true ***"
289
+ end
290
+ else
291
+ BCL.tarball(destination, paths)
292
+ end
293
+ Dir.chdir(current_d)
294
+ end
295
+ puts '', "****STAGING DONE**** #{new_ones} new content, #{updates} updates, #{noops} skipped (already up-to-date on BCL)", ''
296
+ end
297
+ end
298
+
299
+ require 'rubocop/rake_task'
300
+ desc 'Run RuboCop on the lib directory'
301
+ RuboCop::RakeTask.new(:rubocop) do |task|
302
+ # only show the files with failures
303
+ task.options = ['--no-color', '--out=rubocop-results.xml']
304
+ task.formatters = ['RuboCop::Formatter::CheckstyleFormatter']
305
+ task.requires = ['rubocop/formatter/checkstyle_formatter']
306
+ # don't abort rake on failure
307
+ task.fail_on_error = false
308
+ end
309
+
310
+ desc 'Default task run rspec tests'
311
+ task test: :spec
312
+ task default: :spec