def configure_app(**kwargs): """Builds up the settings using the same method as logan""" sys_args = sys.argv args, command, command_args = parse_args(sys_args[1:]) parser = OptionParser() parser.add_option('--config', metavar='CONFIG') (options, logan_args) = parser.parse_args(args) config_path = options.config logan_configure(config_path=config_path, **kwargs)
def run_app(**kwargs): sys_args = sys.argv # The established command for running this program runner_name = os.path.basename(sys_args[0]) args, command, command_args = parse_args(sys_args[1:]) if not command: print "usage: %s [--config=/path/to/settings.py] [command] [options]" % runner_name sys.exit(1) default_config_path = kwargs.get('default_config_path') parser = OptionParser() # The ``init`` command is reserved for initializing configuration if command == 'init': (options, opt_args) = parser.parse_args() settings_initializer = kwargs.get('settings_initializer') config_path = os.path.expanduser(' '.join(opt_args[1:]) or default_config_path) if os.path.exists(config_path): resp = None while resp not in ('Y', 'n'): resp = raw_input( 'File already exists at %r, overwrite? [nY] ' % config_path) if resp == 'n': print "Aborted!" return try: create_default_settings(config_path, settings_initializer) except OSError, e: raise e.__class__, 'Unable to write default settings file to %r' % config_path print "Configuration file created at %r" % config_path return
def run_app(**kwargs): sys_args = sys.argv # The established command for running this program runner_name = os.path.basename(sys_args[0]) args, command, command_args = parse_args(sys_args[1:]) if not command: print "usage: %s [--config=/path/to/settings.py] [command] [options]" % runner_name sys.exit(1) default_config_path = kwargs.get('default_config_path') parser = OptionParser() # The ``init`` command is reserved for initializing configuration if command == 'init': (options, opt_args) = parser.parse_args() settings_initializer = kwargs.get('settings_initializer') config_path = os.path.expanduser(' '.join(opt_args[1:]) or default_config_path) if os.path.exists(config_path): resp = None while resp not in ('Y', 'n'): resp = raw_input('File already exists at %r, overwrite? [nY] ' % config_path) if resp == 'n': print "Aborted!" return try: create_default_settings(config_path, settings_initializer) except OSError, e: raise e.__class__, 'Unable to write default settings file to %r' % config_path print "Configuration file created at %r" % config_path return
def test_mixed_args(self): result = parse_args(['-f', 'foo', '--foo', '--bar']) self.assertEquals(result, (['-f'], 'foo', ['--foo', '--bar']))
def test_no_base_args(self): result = parse_args(['foo', '--foo', '--bar']) self.assertEquals(result, ([], 'foo', ['--foo', '--bar']))
def test_no_command_args(self): result = parse_args(['--foo', '--bar', 'foo']) self.assertEquals(result, (['--foo', '--bar'], 'foo', []))
def test_no_args(self): result = parse_args([]) self.assertEquals(result, ([], None, []))