Skip to content

Commit

Permalink
Merge pull request #32 from NREL/develop
Browse files Browse the repository at this point in the history
v0.8.0 release
  • Loading branch information
kflemin authored May 3, 2024
2 parents 148678c + daf9afc commit 8ee7f59
Show file tree
Hide file tree
Showing 19 changed files with 270 additions and 1,398 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## Version 0.8.0
* BCLXML validation: adjust schemas
* removed staging, pushing, updating of components
* removed login
* simplified config file to only contain server URL
* removed test to download component via POST (was that needed?)
* code clean-up and test clean-up
* updated dependencies to support Ruby 3.2.2 & OpenStudio 3.8.0

## Version 0.7.1
* Update license to standard OpenStudio 4-clause BSD license
* Upgrade dependencies for security
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OpenStudio(R), Copyright (c) 2008-2021, Alliance for Sustainable Energy, LLC. All rights reserved.
OpenStudio(R), Copyright (c) 2008-2024, Alliance for Sustainable Energy, LLC. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
Expand Down
301 changes: 37 additions & 264 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
# *******************************************************************************
# OpenStudio(R), Copyright (c) 2008-2021, Alliance for Sustainable Energy, LLC.
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# (3) Neither the name of the copyright holder nor the names of any contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission from the respective party.
#
# (4) Other than as required in clauses (1) and (2), distributions in any form
# of modifications or other derivative works may not use the "OpenStudio"
# trademark, "OS", "os", or any other confusingly similar designation without
# specific prior written permission from Alliance for Sustainable Energy, LLC.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
# See also https://openstudio.net/license
# *******************************************************************************

require 'bundler'
Expand Down Expand Up @@ -60,43 +30,36 @@ namespace :test do
# search with all=false
# ensure the same a) and b) as above
bcl = BCL::ComponentMethods.new
bcl.login
results = bcl.search('Add', 'show_rows=10', false)
puts "there are #{results[:result].count} results"
puts "there are #{results[:result].count} results returned in this response"
puts "there are #{results[:complete_results_count]} total results available for this query"
results[:result].each do |res|
puts (res[:measure][:name]).to_s
end
end

desc 'test measure upload'
task :measure_upload do
bcl = BCL::ComponentMethods.new
bcl.login
filename = "#{File.dirname(__FILE__)}/spec/api/resources/measure_original.tar.gz"
valid, res = bcl.push_content(filename, false, 'nrel_measure')
end

desc 'test the BCL login credentials defined in .bcl/config.yml'
task :bcl_login do
desc 'test search and return ALL versions functionality'
task :search_all_versions do
# search with all=true
# ensure that a) results are returned (> 0) and b) [:measure][:name] is a string
# search with all=false
# ensure the same a) and b) as above
bcl = BCL::ComponentMethods.new
bcl.login
end

desc 'test component spreadsheet'
task :spreadsheet do
bclcomponents = BCL::ComponentFromSpreadsheet.new(File.expand_path('lib/files/Components.xls', __dir__), ['Roofing'])
bclcomponents.save(File.expand_path('lib/files/staged', __dir__))
results = bcl.search('Add', 'show_rows=10&all_content_versions=1', false)
puts "there are #{results[:result].count} results returned in this response"
puts "there are #{results[:complete_results_count]} total results available for this query"
results[:result].each do |res|
puts (res[:measure][:name]).to_s
end
end

desc 'test measure download'
task :measure_download do
# find a component with keyword 'Ashrae'
query = 'ashrae'
filter = 'fq[]=bundle:nrel_component&show_rows=3'
filter = 'fq=bundle:nrel_component&show_rows=3'

bcl = BCL::ComponentMethods.new
bcl.login

results = bcl.search(query, filter)
uids = []
results[:result].each do |result|
Expand All @@ -111,223 +74,33 @@ namespace :test do
f = File.open("#{download_path}/#{uids[0]}.tar.gz", 'wb')
f.write(content)
end
end

namespace :bcl do
STAGED_PATH = Pathname.new(Dir.pwd + '/staged')

# initialize BCL and login
bcl = BCL::ComponentMethods.new
bcl.login

# to call: rake "bcl:stage_and_upload[/path/to/your/content/directory, true]"
# content_path arg: path to components or measures to upload
# reset flag:
# If TRUE: content in the staged directory will be re-generated and receipt files will be deleted.
# If FALSE, content that already exists in the staged directory will remain and content with receipt files will not be re-uploaded.
desc 'stage and push/update all content in a repo'
task :stage_and_upload, [:content_path, :reset] do |t, args|
options = { reset: false }
options[:content_path] = Pathname.new args[:content_path]
if args[:reset].to_s == 'true'
options[:reset] = true
end

current_dir = Dir.pwd

# stage content
Rake.application.invoke_task("bcl:stage_content[#{options[:content_path]}, #{options[:reset]}]")
Dir.chdir(current_dir)

# upload (new and updated). pass in skip flag
Rake.application.invoke_task("bcl:upload_content[#{options[:reset]}]")
end

# to call: rake "bcl:upload_content[true]"
# TODO: catch errors and continue
desc 'upload/update BCL content'
task :upload_content, [:reset] do |t, args|
# process options
options = { reset: false }
if args[:reset].to_s == 'true'
options[:reset] = true
end

total_count = 0
successes = 0
errors = 0
skipped = 0

# grab all the new measure and component tar files and push to bcl
['measure', 'component'].each do |content_type|
items = []
paths = Pathname.glob(STAGED_PATH.to_s + "/push/#{content_type}/*.tar.gz")
paths.each do |path|
# puts path
items << path.to_s
end

items.each do |item|
puts item.split('/').last
total_count += 1

receipt_file = File.dirname(item) + '/' + File.basename(item, '.tar.gz') + '.receipt'
if !options[:reset] && File.exist?(receipt_file)
skipped += 1
puts 'SKIP: receipt file found'
next
end

valid, res = bcl.push_content(item, true, "nrel_#{content_type}")
if valid
successes += 1
else
errors += 1
if res.key?(:error)
puts " ERROR MESSAGE: #{res[:error]}"
else
puts "ERROR: #{res.inspect.chomp}"
end
end
puts '', '---'
end
end
desc 'test measure download - legacy syntax'
task :measure_download do
# find a component with keyword 'Ashrae'
query = 'ashrae'
filter = 'fq[]=bundle:nrel_component&show_rows=3'

# grab all the updated content (measures and components) tar files and push to bcl
items = []
paths = Pathname.glob(STAGED_PATH.to_s + '/update/*.tar.gz')
paths.each do |path|
# puts path
items << path.to_s
bcl = BCL::ComponentMethods.new
results = bcl.search(query, filter)
uids = []
results[:result].each do |result|
uids << result[:component][:uuid]
end
items.each do |item|
puts item.split('/').last
total_count += 1

receipt_file = File.dirname(item) + '/' + File.basename(item, '.tar.gz') + '.receipt'
if !options[:reset] && File.exist?(receipt_file)
skipped += 1
puts 'SKIP: receipt file found'
next
end

valid, res = bcl.update_content(item, true)
if valid
successes += 1
else
errors += 1
if res.key?(:error)
puts " ERROR MESSAGE: #{res[:error]}"
else
puts "ERROR MESSAGE: #{res.inspect.chomp}"
end
end
puts '', '---'
end
content = bcl.download_component(uids[0])

puts "****UPLOAD DONE**** #{total_count} total, #{successes} success, #{errors} failures, #{skipped} skipped"
# save as tar.gz
download_path = File.expand_path('lib/files/downloads', __dir__)
FileUtils.mkdir(download_path) if !File.exist? download_path
f = File.open("#{download_path}/#{uids[0]}.tar.gz", 'wb')
f.write(content)
end

# to call: rake "bcl:stage_content[/path/to/your/content/directory, true]"
desc 'stage content for BCL'
task :stage_content, [:content_path, :reset] do |t, args|
# process options
options = { reset: false }
options[:content_path] = Pathname.new args[:content_path]
if args[:reset].to_s == 'true'
options[:reset] = true
end
puts "OPTIONS -- content_path: #{options[:content_path]}, reset: #{options[:reset]}"

FileUtils.mkdir_p(STAGED_PATH)

# delete existing tarballs if reset is true
if options[:reset]
FileUtils.rm_rf(Dir.glob("#{STAGED_PATH}/*"))
end

# create new and existing directories
FileUtils.mkdir_p(STAGED_PATH.to_s + '/update')
FileUtils.mkdir_p(STAGED_PATH.to_s + '/push/component')
FileUtils.mkdir_p(STAGED_PATH.to_s + '/push/measure')

# keep track of noop, update, push
noops = 0
new_ones = 0
updates = 0

# get all content directories to process
dirs = Dir.glob("#{options[:content_path]}/*")

dirs.each do |dir|
next if dir.include?('Rakefile')

current_d = Dir.pwd
content_name = File.basename(dir)
puts '', '---'
puts "Generating #{content_name}"

Dir.chdir(dir)

# figure out whether to upload new or update existing
files = Pathname.glob('**/*')
uuid = nil
vid = nil
content_type = 'measure'

paths = []
files.each do |file|
# don't tar tests/outputs directory
next if file.to_s.start_with?('tests/output') # From measure testing process
next if file.to_s.start_with?('tests/test') # From openstudio-measure-tester-gem
next if file.to_s.start_with?('tests/coverage') # From openstudio-measure-tester-gem
next if file.to_s.start_with?('test_results') # From openstudio-measure-tester-gem

paths << file.to_s
if file.to_s =~ /^.{0,2}component.xml$/ || file.to_s =~ /^.{0,2}measure.xml$/
if file.to_s.match?(/^.{0,2}component.xml$/)
content_type = 'component'
end
# extract uuid and vid
uuid, vid = bcl.uuid_vid_from_xml(file)
end
end
puts "UUID: #{uuid}, VID: #{vid}"

# note: if uuid is missing, will assume new content
action = bcl.search_by_uuid(uuid, vid)
puts "#{content_name} ACTION TO TAKE: #{action}"
# new content functionality needs to know if measure or component. update is agnostic.
if action == 'noop' # ignore up-to-date content
puts " - WARNING: local #{content_name} uuid and vid match BCL... no update will be performed"
noops += 1
next
elsif action == 'update'
# puts "#{content_name} labeled as update for BCL"
destination = STAGED_PATH.join(action, "#{content_name}.tar.gz")
updates += 1
elsif action == 'push'
# puts "#{content_name} labeled as new content for BCL"
destination = STAGED_PATH.join(action, content_type, "#{content_name}.tar.gz")
new_ones += 1
end

puts "destination: #{destination}"

# copy over only if 'reset_receipts' is set to TRUE. otherwise ignore if file exists already
if File.exist?(destination)
if options[:reset]
FileUtils.rm(destination)
BCL.tarball(destination, paths)
else
puts "*** WARNING: File #{content_name}.tar.gz already exists in staged directory... keeping existing file. To overwrite, set reset_receipts arg to true ***"
end
else
BCL.tarball(destination, paths)
end
Dir.chdir(current_d)
end
puts '', "****STAGING DONE**** #{new_ones} new content, #{updates} updates, #{noops} skipped (already up-to-date on BCL)", ''
desc 'test component spreadsheet'
task :spreadsheet do
bclcomponents = BCL::ComponentFromSpreadsheet.new(File.expand_path('lib/files/Components.xls', __dir__), ['Roofing'])
bclcomponents.save(File.expand_path('lib/files/staged', __dir__))
end
end

Expand Down
6 changes: 3 additions & 3 deletions bcl.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Gem::Specification.new do |spec|
spec.metadata = {
'bug_tracker_uri' => 'https://github.com/NREL/bcl-gem/issues',
'changelog_uri' => 'https://github.com/NREL/bcl-gem/blob/develop/CHANGELOG.md',
# 'documentation_uri' => 'https://www.rubydoc.info/gems/openstudio-extension-gem/#{gem.version}',
'source_code_uri' => "https://github.com/NREL/bcl-gem/tree/v#{spec.version}"
}

Expand All @@ -27,22 +26,23 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.required_ruby_version = '~> 2.7.0'
spec.required_ruby_version = '~> 3.2.2'

spec.add_dependency 'builder', '3.2.4'
spec.add_dependency 'faraday', '~> 1.0.1'
spec.add_dependency 'minitar', '~> 0.9'

# Measure tester is not used in this project, but this will force dependencies to match versions
# requested by OpenStudio. This includes dependencies for running tests/CI
spec.add_dependency 'openstudio_measure_tester', '~> 0.3.1'
spec.add_dependency 'openstudio_measure_tester', '~> 0.4.0'
spec.add_dependency 'rexml', '3.2.5'
spec.add_dependency 'rubyzip', '~> 2.3.2'
spec.add_dependency 'spreadsheet', '1.2.9'
spec.add_dependency 'uuid', '~> 2.3.9'
spec.add_dependency 'yamler', '0.1.0'
spec.add_dependency 'zliby', '0.0.5'

spec.add_development_dependency 'bundler', '2.4.10'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.9'
end
Loading

0 comments on commit 8ee7f59

Please sign in to comment.