# HG changeset patch # User Marcin Kuzminski # Date 1341669656 -7200 # Node ID 94a92bd832c5a11fec2e035a9471a07be007d08c # Parent 94ae02ca5f00b3c67c4e28b581fd15eb3b5e818c added --config option into rhodecode-api script for optional path for config diff -r 94ae02ca5f00 -r 94a92bd832c5 rhodecode/bin/rhodecode_api.py --- a/rhodecode/bin/rhodecode_api.py Sat Jul 07 17:13:31 2012 +0000 +++ b/rhodecode/bin/rhodecode_api.py Sat Jul 07 16:00:56 2012 +0200 @@ -54,8 +54,9 @@ """ - def __init__(self, autoload=True, autocreate=False, config=None): - self._conf_name = CONFIG_NAME + def __init__(self, config_location=None, autoload=True, autocreate=False, + config=None): + self._conf_name = CONFIG_NAME if not config_location else config_location self._conf = {} if autocreate: self.make_config(config) @@ -83,9 +84,16 @@ :param config: :type config: """ + update = False + if os.path.exists(self._conf_name): + update = True with open(self._conf_name, 'wb') as f: json.dump(config, f, indent=4) - sys.stdout.write('Updated conf\n') + + if update: + sys.stdout.write('Updated config in %s\n' % self._conf_name) + else: + sys.stdout.write('Created new config in %s\n' % self._conf_name) def update_config(self, new_config): """ @@ -166,8 +174,11 @@ def argparser(argv): - usage = ("rhodecode_api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] " - "_create_config or METHOD ...") + usage = ( + "rhodecode_api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] " + " [--config=CONFIG] " + "_create_config or METHOD ..." + ) parser = argparse.ArgumentParser(description='RhodeCode API cli', usage=usage) @@ -176,6 +187,7 @@ group = parser.add_argument_group('config') group.add_argument('--apikey', help='api access key') group.add_argument('--apihost', help='api host') + group.add_argument('--config', help='config file') group = parser.add_argument_group('API') group.add_argument('method', metavar='METHOD', type=str, @@ -207,12 +219,12 @@ if args.method == '_create_config': if not api_credentials_given: raise parser.error('_create_config requires --apikey and --apihost') - conf = RcConf(autocreate=True, config={'apikey': args.apikey, + conf = RcConf(config_location=args.config, + autocreate=True, config={'apikey': args.apikey, 'apihost': args.apihost}) - sys.stdout.write('Create new config in %s\n' % CONFIG_NAME) if not conf: - conf = RcConf(autoload=True) + conf = RcConf(config_location=args.config, autoload=True) if not conf: if not api_credentials_given: parser.error('Could not find config file and missing '