##// 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):
57 def __init__(self, config_location=None, autoload=True, autocreate=False,
58 self._conf_name = CONFIG_NAME
58 config=None):
59 self._conf_name = CONFIG_NAME if not config_location else config_location
59 self._conf = {}
60 self._conf = {}
60 if autocreate:
61 if autocreate:
61 self.make_config(config)
62 self.make_config(config)
@@ -83,9 +84,16 class RcConf(object):
83 :param config:
84 :param config:
84 :type config:
85 :type config:
85 """
86 """
87 update = False
88 if os.path.exists(self._conf_name):
89 update = True
86 with open(self._conf_name, 'wb') as f:
90 with open(self._conf_name, 'wb') as f:
87 json.dump(config, f, indent=4)
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 def update_config(self, new_config):
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 def argparser(argv):
176 def argparser(argv):
169 usage = ("rhodecode_api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
177 usage = (
170 "_create_config or METHOD <key:val> <key2:val> ...")
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 parser = argparse.ArgumentParser(description='RhodeCode API cli',
183 parser = argparse.ArgumentParser(description='RhodeCode API cli',
173 usage=usage)
184 usage=usage)
@@ -176,6 +187,7 def argparser(argv):
176 group = parser.add_argument_group('config')
187 group = parser.add_argument_group('config')
177 group.add_argument('--apikey', help='api access key')
188 group.add_argument('--apikey', help='api access key')
178 group.add_argument('--apihost', help='api host')
189 group.add_argument('--apihost', help='api host')
190 group.add_argument('--config', help='config file')
179
191
180 group = parser.add_argument_group('API')
192 group = parser.add_argument_group('API')
181 group.add_argument('method', metavar='METHOD', type=str,
193 group.add_argument('method', metavar='METHOD', type=str,
@@ -207,12 +219,12 def main(argv=None):
207 if args.method == '_create_config':
219 if args.method == '_create_config':
208 if not api_credentials_given:
220 if not api_credentials_given:
209 raise parser.error('_create_config requires --apikey and --apihost')
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 'apihost': args.apihost})
224 'apihost': args.apihost})
212 sys.stdout.write('Create new config in %s\n' % CONFIG_NAME)
213
225
214 if not conf:
226 if not conf:
215 conf = RcConf(autoload=True)
227 conf = RcConf(config_location=args.config, autoload=True)
216 if not conf:
228 if not conf:
217 if not api_credentials_given:
229 if not api_credentials_given:
218 parser.error('Could not find config file and missing '
230 parser.error('Could not find config file and missing '
General Comments 0
You need to be logged in to leave comments. Login now