src/cli/openstudio_cli.rb
# Executes code to update and compute arguments for measures
#
# @param [Array] sub_argv Options passed to the e command from the user input
# @return [Fixnum] Return status
#
Executes code to update and compute arguments for measures
Executes code to update and compute arguments for measures
def execute(sub_argv)
    $logger.info "Update, sub_argv = #{sub_argv}"
    options = {}
    options[:keep] = false
    opts = OptionParser.new do |o|
      o.banner = 'Usage: openstudio update [options] PATH'
      o.separator ''
      o.separator 'Options:'
      o.separator ''
      o.on('-k', '--keep', 'Keep original files') do
        options[:keep] = true
      end
    end
    argv = parse_options(opts, sub_argv)
    return 0 if argv == nil
    $logger.debug("Measure command: #{argv.inspect} #{options.inspect}")
    if argv == []
      $logger.error 'No path provided'
      return 1
    end
    path = File.expand_path(argv[0])
    $logger.debug("Path to examine is #{path}")
    paths = []
    if File.file?(path)
      $logger.debug("Path is regular file")
      paths << path
    else
      $logger.debug("Path is directory")
      Dir.glob(path + "/*.osm").each do |path|
        paths << path
      end
    end
    vt = OpenStudio::OSVersion::VersionTranslator.new
    result = 0
    paths.each do |path|
      if options[:keep]
        FileUtils.cp(path, path + ".orig")
      end
      model = vt.loadModel(path)
      if model.empty?
        $logger.error("Could not read model at #{path}")
        result = 1
        next
      end
      model.get.save(path, true)
    end
    result
  end
def execute ( sub_argv ) $logger . info "Update, sub_argv = #{sub_argv}" options = { } options [ :keep ] = false opts = OptionParser . new do | o | o . banner = 'Usage: openstudio update [options] PATH' o . separator '' o . separator 'Options:' o . separator '' o . on ( '-k' , '--keep' , 'Keep original files' ) do options [ :keep ] = true end end argv = parse_options ( opts , sub_argv ) return 0 if argv == nil $logger . debug ( "Measure command: #{argv.inspect} #{options.inspect}" ) if argv == [ ] $logger . error 'No path provided' return 1 end path = File . expand_path ( argv [ 0 ] ) $logger . debug ( "Path to examine is #{path}" ) paths = [ ] if File . file? ( path ) $logger . debug ( "Path is regular file" ) paths << path else $logger . debug ( "Path is directory" ) Dir . glob ( path + "/*.osm" ) . each do | path | paths << path end end vt = OpenStudio :: OSVersion :: VersionTranslator . new result = 0 paths . each do | path | if options [ :keep ] FileUtils . cp ( path , path + ".orig" ) end model = vt . loadModel ( path ) if model . empty? $logger . error ( "Could not read model at #{path}" ) result = 1 next end model . get . save ( path , true ) end result end
Executes code to update and compute arguments for measures
Executes code to update and compute arguments for measures
# Parse the options
None
Fixnum
sub_argv
<not_specific>
<not_specific>
sub_argv Options passed to the e command from the user input
sub_argv Options passed to the e command from the user input