lib/openstudio/extension/runner.rb in openstudio-extension-0.2.0 vs lib/openstudio/extension/runner.rb in openstudio-extension-0.2.1
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
# *******************************************************************************
# OpenStudio(R), Copyright (c) 2008-2020, 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:
@@ -54,21 +56,22 @@
# When initialized with a directory containing a Gemfile, the Runner will attempt to create a bundle
# compatible with the OpenStudio CLI.
##
# @param [String] dirname Directory to run commands in, defaults to Dir.pwd. If directory includes a Gemfile then create a local bundle.
# @param bundle_without [Hash] Hash describing the distribution of the variable.
- # @param options [Hash] Hash describing options for running the simulation. These are the defaults for all runs unless overriden within the run_* methods.
+ # @param options [Hash] Hash describing options for running the simulation. These are the defaults for all runs unless overriden within the run_* methods. Note if options is used, then a local runner.conf file will not be loaded.
# @option options [String] :max_datapoints Max number of datapoints to run
# @option options [String] :num_parallel Number of simulations to run in parallel at a time
# @option options [String] :run_simulations Set to true to run the simulations
# @option options [String] :verbose Set to true to receive extra information while running simulations
def initialize(dirname = Dir.pwd, bundle_without = [], options = {})
# DLM: I am not sure if we want to use the main root directory to create these bundles
- # had the idea of passing in a Gemfile name/alias and path to Gemfile, then doing the bundle in ~/OpenStudio/#{alias} or something like that?
+ # had the idea of passing in a Gemfile name/alias and path to Gemfile, then doing the bundle
+ # in ~/OpenStudio/#{alias} or something like that?
# if the dirname contains a runner.conf file, then use the config file to specify the parameters
- if File.exist?(File.join(dirname, OpenStudio::Extension::RunnerConfig::FILENAME)) && !options
+ if File.exist?(File.join(dirname, OpenStudio::Extension::RunnerConfig::FILENAME)) && options.empty?
puts 'Using runner options from runner.conf file'
runner_config = OpenStudio::Extension::RunnerConfig.new(dirname)
@options = runner_config.options
else
# use the passed values or defaults overriden by passed options
@@ -560,17 +563,17 @@
paths.each do |path|
Dir[path[:glob]].each do |file|
puts "Updating license in file #{file}"
f = File.read(file)
- if f =~ path[:regex]
+ if f.match?(path[:regex])
puts ' License found -- updating'
File.open(file, 'w') { |write| write << f.gsub(path[:regex], path[:license]) }
elsif f =~ /\(C\)/i || f =~ /\(Copyright\)/i
puts ' File already has copyright -- skipping'
else
puts ' No license found -- adding'
- if f =~ /#!/
+ 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(file, 'w') { |write| write << f.insert(0, path[:license] + "\n") }
end