lib/openstudio/extension/runner.rb in openstudio-extension-0.4.2 vs lib/openstudio/extension/runner.rb in openstudio-extension-0.4.3

- old
+ new

@@ -119,19 +119,19 @@ # go to the directory with the gemfile to run these commands Dir.chdir(@gemfile_dir) # test to see if bundle is installed check_bundle = run_command('bundle -v', get_clean_env) - if !check_bundle - raise "Failed to run command 'bundle -v', check that bundle is installed" if !File.exist?(@dirname) + if !check_bundle && !File.exist?(@dirname) + raise "Failed to run command 'bundle -v', check that bundle is installed" end # TODO: check that ruby version is correct # check existing config needs_config = true - if File.exist?('./.bundle/config') # checking wrt gemfile_dir + if File.exist?('./.bundle/config') # checking wrt gemfile_dir puts 'config exists' needs_config = false config = YAML.load_file('./.bundle/config') if config['BUNDLE_PATH'] != @bundle_install_path @@ -164,14 +164,12 @@ if needs_platform run_command('bundle lock --add_platform ruby', get_clean_env) end needs_update = needs_config || needs_platform - if !needs_update - if !File.exist?('Gemfile.lock') || File.mtime(@gemfile_path) > File.mtime('Gemfile.lock') - needs_update = true - end + if !needs_update && (!File.exist?('Gemfile.lock') || File.mtime(@gemfile_path) > File.mtime('Gemfile.lock')) + needs_update = true end puts "needs_update = #{needs_update}" if needs_update run_command('bundle update', get_clean_env) @@ -239,11 +237,11 @@ result = true else puts "Error running command: '#{command}'" puts "stdout: #{stdout_str}" puts "stderr: #{stderr_str}" - STDOUT.flush + $stdout.flush result = false end ensure Dir.chdir(original_dir) end @@ -316,14 +314,14 @@ the_call = "#{cli} --verbose measure -r #{measures_dir}" end puts 'SYSTEM CALL:' puts the_call - STDOUT.flush + $stdout.flush result = run_command(the_call, get_clean_env) puts "DONE, result = #{result}" - STDOUT.flush + $stdout.flush return result end ## @@ -356,14 +354,14 @@ the_call = "#{cli} --verbose measure -t '#{m_dir}'" end puts 'SYSTEM CALL:' puts the_call - STDOUT.flush + $stdout.flush result &&= run_command(the_call, get_clean_env) puts "DONE, result = #{result}" - STDOUT.flush + $stdout.flush end return result end @@ -423,11 +421,11 @@ if measures.empty? # also try nested 2-deep to support openstudio-measures measures = Dir.glob(File.join(measures_dir, '**/**/resources/*.rb')) end - # Note: some older measures like AEDG use 'OsLib_SomeName' instead of 'os_lib_some_name' + # NOTE: some older measures like AEDG use 'OsLib_SomeName' instead of 'os_lib_some_name' # this script isn't replacing those copies # loop through resource files resource_files.each do |resource_file| # loop through measure dirs looking for matching file @@ -521,15 +519,13 @@ elsif doc_templates_dir.nil? || doc_templates_dir.empty? puts 'Doc templates dir is nil or empty' return false end - if File.exist?(File.join(doc_templates_dir, 'LICENSE.md')) - if File.exist?(File.join(root_dir, 'LICENSE.md')) - puts 'updating LICENSE.md in root dir' - FileUtils.cp(File.join(doc_templates_dir, 'LICENSE.md'), File.join(root_dir, 'LICENSE.md')) - end + if File.exist?(File.join(doc_templates_dir, 'LICENSE.md')) && File.exist?(File.join(root_dir, 'LICENSE.md')) + puts 'updating LICENSE.md in root dir' + FileUtils.cp(File.join(doc_templates_dir, 'LICENSE.md'), File.join(root_dir, 'LICENSE.md')) end ruby_regex = /^\#\s?[\#\*]{12,}.*copyright.*?\#\s?[\#\*]{12,}\s*$/mi erb_regex = /^<%\s*\#\s?[\#\*]{12,}.*copyright.*?\#\s?[\#\*]{12,}\s*%>$/mi js_regex = /^\/\* @preserve.*copyright.*license.{2}\*\//mi @@ -591,11 +587,11 @@ puts ' No license found -- adding' if f.match?(/#!/) puts ' CANNOT add license to file automatically, add it manually and it will update automatically in the future' next end - File.open(dir_file, 'w') { |write| write << f.insert(0, path[:license] + "\n") } + File.open(dir_file, 'w') { |write| write << f.insert(0, "#{path[:license]}\n") } end end end end @@ -629,11 +625,11 @@ file.puts JSON.pretty_generate(osw) end if @options[:run_simulations] cli = OpenStudio.getOpenStudioCLI - out_log = run_osw_path + '.log' + out_log = "#{run_osw_path}.log" # if Gem.win_platform? # # out_log = "nul" # else # # out_log = "/dev/null" # end @@ -653,13 +649,13 @@ the_call = "#{cli}#{verbose_string} run -w '#{run_osw_path}' 2>&1 > \"#{out_log}\"" end puts 'SYSTEM CALL:' puts the_call - STDOUT.flush + $stdout.flush result = run_command(the_call, get_clean_env) puts "DONE, result = #{result}" - STDOUT.flush + $stdout.flush else puts 'simulations are not performed, since to the @options[:run_simulations] is set to false' end if @options[:run_simulations]