Skip to content

Commit 5d5e0f7

Browse files
author
Gauvain Pocentek
committed
flake8 fixes
1 parent d4803f9 commit 5d5e0f7

File tree

2 files changed

+53
-33
lines changed

2 files changed

+53
-33
lines changed

gitlab

+50-25
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,28 @@ import gitlab
3232
camel_re = re.compile('(.)([A-Z])')
3333

3434
extra_actions = {
35-
gitlab.ProjectBranch: {
36-
'protect': {'requiredAttrs': ['id', 'project-id']},
37-
'unprotect': {'requiredAttrs': ['id', 'project-id']}
38-
},
39-
gitlab.Project: {
40-
'search': {'requiredAttrs': ['query']},
41-
'owned': {'requiredAttrs': []},
42-
'all': {'requiredAttrs': []}
43-
},
35+
gitlab.ProjectBranch: {'protect': {'requiredAttrs': ['id', 'project-id']},
36+
'unprotect': {'requiredAttrs': ['id', 'project-id']}
37+
},
38+
gitlab.Project: {'search': {'requiredAttrs': ['query']},
39+
'owned': {'requiredAttrs': []},
40+
'all': {'requiredAttrs': []}
41+
},
4442
}
4543

44+
4645
def die(msg):
4746
sys.stderr.write(msg + "\n")
4847
sys.exit(1)
4948

49+
5050
def whatToCls(what):
5151
return "".join([s.capitalize() for s in what.split("-")])
5252

53+
5354
def clsToWhat(cls):
54-
return camel_re.sub(r'\1-\2', cls.__name__).lower()
55+
return camel_re.sub(r'\1-\2', cls.__name__).lower()
56+
5557

5658
def actionHelpList(cls):
5759
l = []
@@ -66,39 +68,48 @@ def actionHelpList(cls):
6668

6769
detail = ''
6870
if action == 'list':
69-
detail = " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredListAttrs])
71+
detail = " ".join(["--%s=ARG" % x.replace('_', '-')
72+
for x in cls.requiredListAttrs])
7073
if detail:
7174
detail += " "
7275
detail += "--page=ARG --per-page=ARG"
7376
elif action in ['get', 'delete']:
7477
if cls not in [gitlab.CurrentUser]:
7578
detail = "--id=ARG "
76-
detail += " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredGetAttrs])
79+
detail += " ".join(["--%s=ARG" % x.replace('_', '-')
80+
for x in cls.requiredGetAttrs])
7781
elif action == 'create':
78-
detail = " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredCreateAttrs])
82+
detail = " ".join(["--%s=ARG" % x.replace('_', '-')
83+
for x in cls.requiredCreateAttrs])
7984
if detail:
8085
detail += " "
81-
detail += " ".join(["[--%s=ARG]" % x.replace('_', '-') for x in cls.optionalCreateAttrs])
86+
detail += " ".join(["[--%s=ARG]" % x.replace('_', '-')
87+
for x in cls.optionalCreateAttrs])
8288
elif action == 'update':
83-
detail = " ".join(["[--%s=ARG]" % x.replace('_', '-') for x in cls.requiredCreateAttrs])
89+
detail = " ".join(["[--%s=ARG]" % x.replace('_', '-')
90+
for x in cls.requiredCreateAttrs])
8491
if detail:
8592
detail += " "
86-
detail += " ".join(["[--%s=ARG]" % x.replace('_', '-') for x in cls.optionalCreateAttrs])
93+
detail += " ".join(["[--%s=ARG]" % x.replace('_', '-')
94+
for x in cls.optionalCreateAttrs])
8795
l.append("%s %s" % (action, detail))
8896

89-
if extra_actions.has_key(cls):
97+
if cls in extra_actions:
9098
for action in sorted(extra_actions[cls]):
9199
d = extra_actions[cls][action]
92100
detail = " ".join(["--%s=ARG" % arg for arg in d['requiredAttrs']])
93101
l.append("%s %s" % (action, detail))
94102

95103
return (l)
96104

105+
97106
def usage():
98-
print("usage: gitlab [--help|-h] [--fancy|--verbose|-v] [--gitlab=GITLAB] WHAT ACTION [options]")
107+
print("usage: gitlab [--help|-h] [--fancy|--verbose|-v] [--gitlab=GITLAB] "
108+
"WHAT ACTION [options]")
99109
print("")
100110
print("--gitlab=GITLAB")
101-
print(" Specifies which python-gitlab.cfg configuration section should be used.")
111+
print(" Specifies which python-gitlab.cfg configuration section should "
112+
"be used.")
102113
print(" If not defined, the default selection will be used.")
103114
print("")
104115
print("--fancy, --verbose, -v")
@@ -108,7 +119,8 @@ def usage():
108119
print(" Displays this message.")
109120
print("")
110121
print("Available `options` depend on which WHAT/ACTION couple is used.")
111-
print("If `ACTION` is \"help\", available actions and options will be listed for `ACTION`.")
122+
print("If `ACTION` is \"help\", available actions and options will be "
123+
"listed for `ACTION`.")
112124
print("")
113125
print("Available `WHAT` values are:")
114126

@@ -129,15 +141,18 @@ def usage():
129141
for cls in classes:
130142
print(" %s" % clsToWhat(cls))
131143

144+
132145
def do_auth():
133146
try:
134-
gl = gitlab.Gitlab(gitlab_url, private_token=gitlab_token, ssl_verify=ssl_verify)
147+
gl = gitlab.Gitlab(gitlab_url, private_token=gitlab_token,
148+
ssl_verify=ssl_verify)
135149
gl.auth()
136150
except:
137151
die("Could not connect to GitLab (%s)" % gitlab_url)
138152

139153
return gl
140154

155+
141156
def get_id():
142157
try:
143158
id = d.pop('id')
@@ -146,6 +161,7 @@ def get_id():
146161

147162
return id
148163

164+
149165
def do_create(cls, d):
150166
if not cls.canCreate:
151167
die("%s objects can't be created" % what)
@@ -158,6 +174,7 @@ def do_create(cls, d):
158174

159175
return o
160176

177+
161178
def do_list(cls, d):
162179
if not cls.canList:
163180
die("%s objects can't be listed" % what)
@@ -169,6 +186,7 @@ def do_list(cls, d):
169186

170187
return l
171188

189+
172190
def do_get(cls, d):
173191
if not cls.canGet:
174192
die("%s objects can't be retrieved" % what)
@@ -184,6 +202,7 @@ def do_get(cls, d):
184202

185203
return o
186204

205+
187206
def do_delete(cls, d):
188207
if not cls.canDelete:
189208
die("%s objects can't be deleted" % what)
@@ -194,6 +213,7 @@ def do_delete(cls, d):
194213
except Exception as e:
195214
die("Impossible to destroy object (%s)" % str(e))
196215

216+
197217
def do_update(cls, d):
198218
if not cls.canUpdate:
199219
die("%s objects can't be updated" % what)
@@ -208,22 +228,25 @@ def do_update(cls, d):
208228

209229
return o
210230

231+
211232
def do_project_search(d):
212233
try:
213234
return gl.search_projects(d['query'])
214-
except:
235+
except Exception as e:
215236
die("Impossible to search projects (%s)" % str(e))
216237

238+
217239
def do_project_all():
218240
try:
219241
return gl.all_projects()
220242
except Exception as e:
221243
die("Impossible to list all projects (%s)" % str(e))
222244

245+
223246
def do_project_owned():
224247
try:
225248
return gl.owned_projects()
226-
except:
249+
except Exception as e:
227250
die("Impossible to list owned projects (%s)" % str(e))
228251

229252

@@ -294,7 +317,8 @@ try:
294317
gitlab_url = config.get(gitlab_id, 'url')
295318
gitlab_token = config.get(gitlab_id, 'private_token')
296319
except:
297-
die("Impossible to get gitlab informations from configuration (%s)" % gitlab_id)
320+
die("Impossible to get gitlab informations from configuration (%s)" %
321+
gitlab_id)
298322

299323
try:
300324
ssl_verify = config.getboolean('global', 'ssl_verify')
@@ -383,6 +407,7 @@ elif action == "all":
383407
o.display(verbose)
384408

385409
else:
386-
die("Unknown action: %s. Use \"gitlab %s help\" to get details." % (action, what))
410+
die("Unknown action: %s. Use \"gitlab %s help\" to get details." %
411+
(action, what))
387412

388413
sys.exit(0)

gitlab.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def _sanitize(value):
468468

469469

470470
def _sanitize_dict(src):
471-
return {k:_sanitize(v) for k, v in src.items()}
471+
return {k: _sanitize(v) for k, v in src.items()}
472472

473473

474474
class GitlabObject(object):
@@ -761,8 +761,8 @@ class ProjectCommit(GitlabObject):
761761
shortPrintAttr = 'title'
762762

763763
def diff(self):
764-
url = '/projects/%(project_id)s/repository/commits/%(commit_id)s/diff' % \
765-
{'project_id': self.project_id, 'commit_id': self.id}
764+
url = ('/projects/%(project_id)s/repository/commits/%(commit_id)s/diff'
765+
% {'project_id': self.project_id, 'commit_id': self.id})
766766
r = self.gitlab.rawGet(url)
767767
if r.status_code == 200:
768768
return r.json()
@@ -978,11 +978,6 @@ def Event(self, id=None, **kwargs):
978978
project_id=self.id,
979979
**kwargs)
980980

981-
def File(self, id=None, **kwargs):
982-
return self._getListOrObject(ProjectFile, id,
983-
project_id=self.id,
984-
**kwargs)
985-
986981
def Hook(self, id=None, **kwargs):
987982
return self._getListOrObject(ProjectHook, id,
988983
project_id=self.id,

0 commit comments

Comments
 (0)