def test_read_valid_file(self): c = ConfigBlock.from_file( os.path.join(TEST_DATA_DIR, 'test_config-valid_file.txt')) nose.tools.assert_equal(len(c.available_keys()), 25) nose.tools.assert_equal(c.get_value('foo:bar'), 'baz') nose.tools.assert_equal(c.get_value('foo:things'), 'stuff') nose.tools.assert_equal(c.get_value('foo:sublevel:value'), 'cool things and stuff') nose.tools.assert_equal(c.get_value('second_block:has'), 'a value with spaces') nose.tools.assert_equal(c.get_value('second_block:more'), 'has a trailing comment') # relativepath value, interpreted against dir containing config file nose.tools.assert_equal( c.get_value('second_block:file'), os.path.join(TEST_DATA_DIR, 'options/test_Data.txt')) nose.tools.assert_equal(c.get_value('global_var'), '3.14159') nose.tools.assert_equal(c.get_value('global_var2'), '1.12') # Test read-only marking syntax nose.tools.assert_true(c.is_read_only('global_var')) nose.tools.assert_false(c.is_read_only('global_var2')) # Test variable reference parsing nose.tools.assert_equal(c.get_value('home'), os.path.join(os.environ['HOME'], 'homer')) nose.tools.assert_equal(c.get_value('config'), '3.14159') nose.tools.assert_equal(c.get_value('config2'), 'baz') nose.tools.assert_equal(c.get_value('local'), 'new value') # another relativepath value nose.tools.assert_equal(c.get_value('config_file'), os.path.join(TEST_DATA_DIR, 'inputs.txt'))
def cli_main(): """ Returns: 0 - Success 1 - Configuration invalid 2 - Tracking failed """ import optparse logging.getLogger().setLevel(logging.INFO) log = logging.getLogger("cli_main") parser = optparse.OptionParser() parser.add_option("-c", "--config", help="Path to the configuration file to use.") parser.add_option("-o", "--output-config", help="Output a configuration file for the current " "configuration to the specified file path.") opts, args = parser.parse_args() if opts.config: opts.config = os.path.abspath(os.path.expanduser(opts.config)) if opts.output_config: opts.output_config = os.path.abspath( os.path.expanduser(opts.output_config)) tft = TrackFeaturesTool() if opts.config: log.info("Setting configuration file: %s", opts.config) tft.set_configuration(ConfigBlock.from_file(opts.config)) if opts.output_config: log.info("Writing output configuration file: %s", opts.output_config) tft.get_configuration().write(opts.output_config) if not tft.validate_configuration(): log.warning("Current configuration insufficient for running the " "tool") return 0 # Error out if current configuration not valid if not tft.validate_configuration(): log.error("Current configuration insufficient for running the tool") return 1 if tft.track_images(): return 0 else: return 2
def cli_main(): """ Returns: 0 - Success 1 - Configuration invalid 2 - Tracking failed """ import optparse logging.getLogger().setLevel(logging.INFO) log = logging.getLogger("cli_main") parser = optparse.OptionParser() parser.add_option("-c", "--config", help="Path to the configuration file to use.") parser.add_option("-o", "--output-config", help="Output a configuration file for the current " "configuration to the specified file path.") opts, args = parser.parse_args() if opts.config: opts.config = os.path.abspath(os.path.expanduser(opts.config)) if opts.output_config: opts.output_config = os.path.abspath(os.path.expanduser(opts.output_config)) tft = TrackFeaturesTool() if opts.config: log.info("Setting configuration file: %s", opts.config) tft.set_configuration(ConfigBlock.from_file(opts.config)) if opts.output_config: log.info("Writing output configuration file: %s", opts.output_config) tft.get_configuration().write(opts.output_config) if not tft.validate_configuration(): log.warning("Current configuration insufficient for running the " "tool") return 0 # Error out if current configuration not valid if not tft.validate_configuration(): log.error("Current configuration insufficient for running the tool") return 1 if tft.track_images(): return 0 else: return 2