51
51
}
52
52
53
53
54
- def die (msg ):
54
+ def _die (msg ):
55
55
sys .stderr .write (msg + "\n " )
56
56
sys .exit (1 )
57
57
58
58
59
- def whatToCls (what ):
59
+ def _what_to_cls (what ):
60
60
return "" .join ([s .capitalize () for s in what .split ("-" )])
61
61
62
62
63
- def clsToWhat (cls ):
63
+ def _cls_to_what (cls ):
64
64
return camel_re .sub (r'\1-\2' , cls .__name__ ).lower ()
65
65
66
66
67
- def populate_sub_parser_by_class (cls , sub_parser ):
67
+ def _populate_sub_parser_by_class (cls , sub_parser ):
68
68
for action_name in ACTIONS :
69
69
attr = 'can' + action_name .capitalize ()
70
70
if not getattr (cls , attr ):
@@ -132,80 +132,80 @@ def do_auth(gitlab_id, config_files):
132
132
gl .auth ()
133
133
return gl
134
134
except Exception as e :
135
- die (str (e ))
135
+ _die (str (e ))
136
136
137
137
138
- def get_id (cls , args ):
138
+ def _get_id (cls , args ):
139
139
try :
140
140
id = args .pop (cls .idAttr )
141
141
except Exception :
142
- die ("Missing --%s argument" % cls .idAttr .replace ('_' , '-' ))
142
+ _die ("Missing --%s argument" % cls .idAttr .replace ('_' , '-' ))
143
143
144
144
return id
145
145
146
146
147
147
def do_create (cls , gl , what , args ):
148
148
if not cls .canCreate :
149
- die ("%s objects can't be created" % what )
149
+ _die ("%s objects can't be created" % what )
150
150
151
151
try :
152
152
o = cls .create (gl , args )
153
153
except Exception as e :
154
- die ("Impossible to create object (%s)" % str (e ))
154
+ _die ("Impossible to create object (%s)" % str (e ))
155
155
156
156
return o
157
157
158
158
159
159
def do_list (cls , gl , what , args ):
160
160
if not cls .canList :
161
- die ("%s objects can't be listed" % what )
161
+ _die ("%s objects can't be listed" % what )
162
162
163
163
try :
164
164
l = cls .list (gl , ** args )
165
165
except Exception as e :
166
- die ("Impossible to list objects (%s)" % str (e ))
166
+ _die ("Impossible to list objects (%s)" % str (e ))
167
167
168
168
return l
169
169
170
170
171
171
def do_get (cls , gl , what , args ):
172
172
if cls .canGet is False :
173
- die ("%s objects can't be retrieved" % what )
173
+ _die ("%s objects can't be retrieved" % what )
174
174
175
175
id = None
176
176
if cls not in [gitlab .CurrentUser ] and cls .getRequiresId :
177
- id = get_id (cls , args )
177
+ id = _get_id (cls , args )
178
178
179
179
try :
180
180
o = cls .get (gl , id , ** args )
181
181
except Exception as e :
182
- die ("Impossible to get object (%s)" % str (e ))
182
+ _die ("Impossible to get object (%s)" % str (e ))
183
183
184
184
return o
185
185
186
186
187
187
def do_delete (cls , gl , what , args ):
188
188
if not cls .canDelete :
189
- die ("%s objects can't be deleted" % what )
189
+ _die ("%s objects can't be deleted" % what )
190
190
191
191
o = do_get (cls , gl , what , args )
192
192
try :
193
193
o .delete ()
194
194
except Exception as e :
195
- die ("Impossible to destroy object (%s)" % str (e ))
195
+ _die ("Impossible to destroy object (%s)" % str (e ))
196
196
197
197
198
198
def do_update (cls , gl , what , args ):
199
199
if not cls .canUpdate :
200
- die ("%s objects can't be updated" % what )
200
+ _die ("%s objects can't be updated" % what )
201
201
202
202
o = do_get (cls , gl , what , args )
203
203
try :
204
204
for k , v in args .items ():
205
205
o .__dict__ [k ] = v
206
206
o .save ()
207
207
except Exception as e :
208
- die ("Impossible to update object (%s)" % str (e ))
208
+ _die ("Impossible to update object (%s)" % str (e ))
209
209
210
210
return o
211
211
@@ -214,28 +214,28 @@ def do_group_search(gl, what, args):
214
214
try :
215
215
return gl .groups .search (args ['query' ])
216
216
except Exception as e :
217
- die ("Impossible to search projects (%s)" % str (e ))
217
+ _die ("Impossible to search projects (%s)" % str (e ))
218
218
219
219
220
220
def do_project_search (gl , what , args ):
221
221
try :
222
222
return gl .projects .search (args ['query' ])
223
223
except Exception as e :
224
- die ("Impossible to search projects (%s)" % str (e ))
224
+ _die ("Impossible to search projects (%s)" % str (e ))
225
225
226
226
227
227
def do_project_all (gl , what , args ):
228
228
try :
229
229
return gl .projects .all ()
230
230
except Exception as e :
231
- die ("Impossible to list all projects (%s)" % str (e ))
231
+ _die ("Impossible to list all projects (%s)" % str (e ))
232
232
233
233
234
234
def do_project_owned (gl , what , args ):
235
235
try :
236
236
return gl .projects .owned ()
237
237
except Exception as e :
238
- die ("Impossible to list owned projects (%s)" % str (e ))
238
+ _die ("Impossible to list owned projects (%s)" % str (e ))
239
239
240
240
241
241
def main ():
@@ -268,12 +268,12 @@ def main():
268
268
classes .sort (key = operator .attrgetter ("__name__" ))
269
269
270
270
for cls in classes :
271
- arg_name = clsToWhat (cls )
271
+ arg_name = _cls_to_what (cls )
272
272
object_group = subparsers .add_parser (arg_name )
273
273
274
274
object_subparsers = object_group .add_subparsers (
275
275
dest = 'action' , help = "Action to execute." )
276
- populate_sub_parser_by_class (cls , object_subparsers )
276
+ _populate_sub_parser_by_class (cls , object_subparsers )
277
277
object_subparsers .required = True
278
278
279
279
arg = parser .parse_args ()
@@ -294,9 +294,9 @@ def main():
294
294
295
295
cls = None
296
296
try :
297
- cls = gitlab .__dict__ [whatToCls (what )]
297
+ cls = gitlab .__dict__ [_what_to_cls (what )]
298
298
except Exception :
299
- die ("Unknown object: %s" % what )
299
+ _die ("Unknown object: %s" % what )
300
300
301
301
gl = do_auth (gitlab_id , config_files )
302
302
@@ -314,7 +314,7 @@ def main():
314
314
315
315
elif action == PROTECT or action == UNPROTECT :
316
316
if cls != gitlab .ProjectBranch :
317
- die ("%s objects can't be protected" % what )
317
+ _die ("%s objects can't be protected" % what )
318
318
319
319
o = do_get (cls , gl , what , args )
320
320
getattr (o , action )()
@@ -326,21 +326,21 @@ def main():
326
326
elif cls == gitlab .Group :
327
327
l = do_group_search (gl , what , args )
328
328
else :
329
- die ("%s objects don't support this request" % what )
329
+ _die ("%s objects don't support this request" % what )
330
330
331
331
for o in l :
332
332
o .display (verbose )
333
333
334
334
elif action == OWNED :
335
335
if cls != gitlab .Project :
336
- die ("%s objects don't support this request" % what )
336
+ _die ("%s objects don't support this request" % what )
337
337
338
338
for o in do_project_owned (gl , what , args ):
339
339
o .display (verbose )
340
340
341
341
elif action == ALL :
342
342
if cls != gitlab .Project :
343
- die ("%s objects don't support this request" % what )
343
+ _die ("%s objects don't support this request" % what )
344
344
345
345
for o in do_project_all (gl , what , args ):
346
346
o .display (verbose )
0 commit comments