MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / execute

Method execute

ruby/engine/openstudio_cli.rb:1613–1674  ·  view source on GitHub ↗

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

(sub_argv)

Source from the content-addressed store, hash-verified

1611 # @return [Fixnum] Return status
1612 #
1613 def execute(sub_argv)
1614
1615 $logger.info "Update, sub_argv = #{sub_argv}"
1616
1617 options = {}
1618 options[:keep] = false
1619
1620 opts = OptionParser.new do |o|
1621 o.banner = 'Usage: openstudio update [options] PATH'
1622 o.separator ''
1623 o.separator 'Options:'
1624 o.separator ''
1625
1626 o.on('-k', '--keep', 'Keep original files') do
1627 options[:keep] = true
1628 end
1629 end
1630
1631 # Parse the options
1632 argv = parse_options(opts, sub_argv)
1633 return 0 if argv == nil
1634
1635 $logger.debug("Measure command: #{argv.inspect} #{options.inspect}")
1636
1637 if argv == []
1638 $logger.error 'No path provided'
1639 return 1
1640 end
1641 path = File.expand_path(argv[0])
1642
1643 $logger.debug("Path to examine is #{path}")
1644
1645 paths = []
1646 if File.file?(path)
1647 $logger.debug("Path is regular file")
1648 paths << path
1649 else
1650 $logger.debug("Path is directory")
1651 Dir.glob(path + "/*.osm").each do |path|
1652 paths << path
1653 end
1654 end
1655
1656 vt = OpenStudio::OSVersion::VersionTranslator.new
1657
1658 result = 0
1659 paths.each do |path|
1660 if options[:keep]
1661 FileUtils.cp(path, path + ".orig")
1662 end
1663
1664 model = vt.loadModel(path)
1665 if model.empty?
1666 $logger.error("Could not read model at #{path}")
1667 result = 1
1668 next
1669 end
1670 model.get.save(path, true)

Callers

nothing calls this directly

Calls 11

parse_optionsFunction · 0.85
infoMethod · 0.80
debugMethod · 0.80
expand_pathMethod · 0.80
file?Method · 0.80
globMethod · 0.80
cpMethod · 0.80
errorMethod · 0.45
loadModelMethod · 0.45
saveMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected