Skip to content

Commit e5821e6

Browse files
author
Gauvain Pocentek
committed
cli.py: make internal functions private
1 parent 572cfa9 commit e5821e6

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

gitlab/cli.py

+30-30
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@
5151
}
5252

5353

54-
def die(msg):
54+
def _die(msg):
5555
sys.stderr.write(msg + "\n")
5656
sys.exit(1)
5757

5858

59-
def whatToCls(what):
59+
def _what_to_cls(what):
6060
return "".join([s.capitalize() for s in what.split("-")])
6161

6262

63-
def clsToWhat(cls):
63+
def _cls_to_what(cls):
6464
return camel_re.sub(r'\1-\2', cls.__name__).lower()
6565

6666

67-
def populate_sub_parser_by_class(cls, sub_parser):
67+
def _populate_sub_parser_by_class(cls, sub_parser):
6868
for action_name in ACTIONS:
6969
attr = 'can' + action_name.capitalize()
7070
if not getattr(cls, attr):
@@ -132,80 +132,80 @@ def do_auth(gitlab_id, config_files):
132132
gl.auth()
133133
return gl
134134
except Exception as e:
135-
die(str(e))
135+
_die(str(e))
136136

137137

138-
def get_id(cls, args):
138+
def _get_id(cls, args):
139139
try:
140140
id = args.pop(cls.idAttr)
141141
except Exception:
142-
die("Missing --%s argument" % cls.idAttr.replace('_', '-'))
142+
_die("Missing --%s argument" % cls.idAttr.replace('_', '-'))
143143

144144
return id
145145

146146

147147
def do_create(cls, gl, what, args):
148148
if not cls.canCreate:
149-
die("%s objects can't be created" % what)
149+
_die("%s objects can't be created" % what)
150150

151151
try:
152152
o = cls.create(gl, args)
153153
except Exception as e:
154-
die("Impossible to create object (%s)" % str(e))
154+
_die("Impossible to create object (%s)" % str(e))
155155

156156
return o
157157

158158

159159
def do_list(cls, gl, what, args):
160160
if not cls.canList:
161-
die("%s objects can't be listed" % what)
161+
_die("%s objects can't be listed" % what)
162162

163163
try:
164164
l = cls.list(gl, **args)
165165
except Exception as e:
166-
die("Impossible to list objects (%s)" % str(e))
166+
_die("Impossible to list objects (%s)" % str(e))
167167

168168
return l
169169

170170

171171
def do_get(cls, gl, what, args):
172172
if cls.canGet is False:
173-
die("%s objects can't be retrieved" % what)
173+
_die("%s objects can't be retrieved" % what)
174174

175175
id = None
176176
if cls not in [gitlab.CurrentUser] and cls.getRequiresId:
177-
id = get_id(cls, args)
177+
id = _get_id(cls, args)
178178

179179
try:
180180
o = cls.get(gl, id, **args)
181181
except Exception as e:
182-
die("Impossible to get object (%s)" % str(e))
182+
_die("Impossible to get object (%s)" % str(e))
183183

184184
return o
185185

186186

187187
def do_delete(cls, gl, what, args):
188188
if not cls.canDelete:
189-
die("%s objects can't be deleted" % what)
189+
_die("%s objects can't be deleted" % what)
190190

191191
o = do_get(cls, gl, what, args)
192192
try:
193193
o.delete()
194194
except Exception as e:
195-
die("Impossible to destroy object (%s)" % str(e))
195+
_die("Impossible to destroy object (%s)" % str(e))
196196

197197

198198
def do_update(cls, gl, what, args):
199199
if not cls.canUpdate:
200-
die("%s objects can't be updated" % what)
200+
_die("%s objects can't be updated" % what)
201201

202202
o = do_get(cls, gl, what, args)
203203
try:
204204
for k, v in args.items():
205205
o.__dict__[k] = v
206206
o.save()
207207
except Exception as e:
208-
die("Impossible to update object (%s)" % str(e))
208+
_die("Impossible to update object (%s)" % str(e))
209209

210210
return o
211211

@@ -214,28 +214,28 @@ def do_group_search(gl, what, args):
214214
try:
215215
return gl.groups.search(args['query'])
216216
except Exception as e:
217-
die("Impossible to search projects (%s)" % str(e))
217+
_die("Impossible to search projects (%s)" % str(e))
218218

219219

220220
def do_project_search(gl, what, args):
221221
try:
222222
return gl.projects.search(args['query'])
223223
except Exception as e:
224-
die("Impossible to search projects (%s)" % str(e))
224+
_die("Impossible to search projects (%s)" % str(e))
225225

226226

227227
def do_project_all(gl, what, args):
228228
try:
229229
return gl.projects.all()
230230
except Exception as e:
231-
die("Impossible to list all projects (%s)" % str(e))
231+
_die("Impossible to list all projects (%s)" % str(e))
232232

233233

234234
def do_project_owned(gl, what, args):
235235
try:
236236
return gl.projects.owned()
237237
except Exception as e:
238-
die("Impossible to list owned projects (%s)" % str(e))
238+
_die("Impossible to list owned projects (%s)" % str(e))
239239

240240

241241
def main():
@@ -268,12 +268,12 @@ def main():
268268
classes.sort(key=operator.attrgetter("__name__"))
269269

270270
for cls in classes:
271-
arg_name = clsToWhat(cls)
271+
arg_name = _cls_to_what(cls)
272272
object_group = subparsers.add_parser(arg_name)
273273

274274
object_subparsers = object_group.add_subparsers(
275275
dest='action', help="Action to execute.")
276-
populate_sub_parser_by_class(cls, object_subparsers)
276+
_populate_sub_parser_by_class(cls, object_subparsers)
277277
object_subparsers.required = True
278278

279279
arg = parser.parse_args()
@@ -294,9 +294,9 @@ def main():
294294

295295
cls = None
296296
try:
297-
cls = gitlab.__dict__[whatToCls(what)]
297+
cls = gitlab.__dict__[_what_to_cls(what)]
298298
except Exception:
299-
die("Unknown object: %s" % what)
299+
_die("Unknown object: %s" % what)
300300

301301
gl = do_auth(gitlab_id, config_files)
302302

@@ -314,7 +314,7 @@ def main():
314314

315315
elif action == PROTECT or action == UNPROTECT:
316316
if cls != gitlab.ProjectBranch:
317-
die("%s objects can't be protected" % what)
317+
_die("%s objects can't be protected" % what)
318318

319319
o = do_get(cls, gl, what, args)
320320
getattr(o, action)()
@@ -326,21 +326,21 @@ def main():
326326
elif cls == gitlab.Group:
327327
l = do_group_search(gl, what, args)
328328
else:
329-
die("%s objects don't support this request" % what)
329+
_die("%s objects don't support this request" % what)
330330

331331
for o in l:
332332
o.display(verbose)
333333

334334
elif action == OWNED:
335335
if cls != gitlab.Project:
336-
die("%s objects don't support this request" % what)
336+
_die("%s objects don't support this request" % what)
337337

338338
for o in do_project_owned(gl, what, args):
339339
o.display(verbose)
340340

341341
elif action == ALL:
342342
if cls != gitlab.Project:
343-
die("%s objects don't support this request" % what)
343+
_die("%s objects don't support this request" % what)
344344

345345
for o in do_project_all(gl, what, args):
346346
o.display(verbose)

0 commit comments

Comments
 (0)