##// END OF EJS Templates
added --config option into rhodecode-api script for optional path for...
marcink -
r2571:94a92bd8 beta
parent child Browse files
Show More
@@ -54,8 +54,9 class RcConf(object):
54 54
55 55 """
56 56
57 def __init__(self, autoload=True, autocreate=False, config=None):
58 self._conf_name = CONFIG_NAME
57 def __init__(self, config_location=None, autoload=True, autocreate=False,
58 config=None):
59 self._conf_name = CONFIG_NAME if not config_location else config_location
59 60 self._conf = {}
60 61 if autocreate:
61 62 self.make_config(config)
@@ -83,9 +84,16 class RcConf(object):
83 84 :param config:
84 85 :type config:
85 86 """
87 update = False
88 if os.path.exists(self._conf_name):
89 update = True
86 90 with open(self._conf_name, 'wb') as f:
87 91 json.dump(config, f, indent=4)
88 sys.stdout.write('Updated conf\n')
92
93 if update:
94 sys.stdout.write('Updated config in %s\n' % self._conf_name)
95 else:
96 sys.stdout.write('Created new config in %s\n' % self._conf_name)
89 97
90 98 def update_config(self, new_config):
91 99 """
@@ -166,8 +174,11 def api_call(apikey, apihost, format, me
166 174
167 175
168 176 def argparser(argv):
169 usage = ("rhodecode_api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
170 "_create_config or METHOD <key:val> <key2:val> ...")
177 usage = (
178 "rhodecode_api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
179 " [--config=CONFIG] "
180 "_create_config or METHOD <key:val> <key2:val> ..."
181 )
171 182
172 183 parser = argparse.ArgumentParser(description='RhodeCode API cli',
173 184 usage=usage)
@@ -176,6 +187,7 def argparser(argv):
176 187 group = parser.add_argument_group('config')
177 188 group.add_argument('--apikey', help='api access key')
178 189 group.add_argument('--apihost', help='api host')
190 group.add_argument('--config', help='config file')
179 191
180 192 group = parser.add_argument_group('API')
181 193 group.add_argument('method', metavar='METHOD', type=str,
@@ -207,12 +219,12 def main(argv=None):
207 219 if args.method == '_create_config':
208 220 if not api_credentials_given:
209 221 raise parser.error('_create_config requires --apikey and --apihost')
210 conf = RcConf(autocreate=True, config={'apikey': args.apikey,
222 conf = RcConf(config_location=args.config,
223 autocreate=True, config={'apikey': args.apikey,
211 224 'apihost': args.apihost})
212 sys.stdout.write('Create new config in %s\n' % CONFIG_NAME)
213 225
214 226 if not conf:
215 conf = RcConf(autoload=True)
227 conf = RcConf(config_location=args.config, autoload=True)
216 228 if not conf:
217 229 if not api_credentials_given:
218 230 parser.error('Could not find config file and missing '
General Comments 0
You need to be logged in to leave comments. Login now