Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit82a88a7

Browse files
author
Gauvain Pocentek
committed
Add a tox configuration file
Run pep8 tests only for now, and fix pep8 errors.
1 parent99cc43a commit82a88a7

File tree

3 files changed

+127
-78
lines changed

3 files changed

+127
-78
lines changed

‎gitlab

Lines changed: 68 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from __future__importprint_function,division,absolute_import
19+
from __future__importprint_function
20+
from __future__importdivision
21+
from __future__importabsolute_import
2022
importargparse
23+
frominspectimportgetmro
2124
importos
22-
importsys
2325
importre
24-
importgitlab
25-
frominspectimportgetmro
26+
importsys
2627
try:
2728
fromConfigParserimportConfigParser
28-
except:
29+
exceptImportError:
2930
fromconfigparserimportConfigParser
3031

32+
importgitlab
33+
3134
camel_re=re.compile('(.)([A-Z])')
3235
LIST='list'
3336
GET='get'
@@ -44,12 +47,10 @@ EXTRA_ACTION = [PROTECT, UNPROTECT, SEARCH, OWNED, ALL]
4447

4548
extra_actions= {
4649
gitlab.ProjectBranch: {PROTECT: {'requiredAttrs': ['id','project-id']},
47-
UNPROTECT: {'requiredAttrs': ['id','project-id']}
48-
},
50+
UNPROTECT: {'requiredAttrs': ['id','project-id']}},
4951
gitlab.Project: {SEARCH: {'requiredAttrs': ['query']},
5052
OWNED: {'requiredAttrs': []},
51-
ALL: {'requiredAttrs': []}
52-
},
53+
ALL: {'requiredAttrs': []}},
5354
}
5455

5556

@@ -77,36 +78,51 @@ def populate_sub_parser_by_class(cls, sub_parser):
7778
attr='can'+action_name.capitalize()
7879
try:
7980
y=cls.__dict__[attr]
80-
except:
81+
exceptAttributeError:
8182
y=gitlab.GitlabObject.__dict__[attr]
8283
ifnoty:
8384
continue
8485
sub_parser_action=sub_parser_class.add_parser(action_name)
85-
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),required=True)forxincls.requiredUrlAttrs]
86+
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),
87+
required=True)
88+
forxincls.requiredUrlAttrs]
89+
8690
ifaction_name==LIST:
87-
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),required=True)forxincls.requiredListAttrs]
91+
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),
92+
required=True)
93+
forxincls.requiredListAttrs]
8894
sub_parser_action.add_argument("--page",required=False)
8995
sub_parser_action.add_argument("--per-page",required=False)
96+
9097
elifaction_namein [GET,DELETE]:
9198
ifclsnotin [gitlab.CurrentUser]:
9299
sub_parser_action.add_argument("--id",required=True)
93-
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),required=True)forxincls.requiredGetAttrs]
100+
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),
101+
required=True)
102+
forxincls.requiredGetAttrs]
103+
94104
elifaction_name==CREATE:
95-
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),required=True)forxin
96-
cls.requiredCreateAttrs]
97-
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),required=False)forxin
98-
cls.optionalCreateAttrs]
105+
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),
106+
required=True)
107+
forxincls.requiredCreateAttrs]
108+
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),
109+
required=False)
110+
forxincls.optionalCreateAttrs]
111+
99112
elifaction_name==UPDATE:
100-
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),required=True)forxin
101-
cls.requiredCreateAttrs]
102-
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),required=False)forxin
103-
cls.optionalCreateAttrs]
113+
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),
114+
required=True)
115+
forxincls.requiredCreateAttrs]
116+
[sub_parser_action.add_argument("--%s"%x.replace('_','-'),
117+
required=False)
118+
forxincls.optionalCreateAttrs]
104119

105120
ifclsinextra_actions:
106121
foraction_nameinsorted(extra_actions[cls]):
107122
sub_parser_action=sub_parser_class.add_parser(action_name)
108123
d=extra_actions[cls][action_name]
109-
[sub_parser_action.add_argument("--%s"%arg,required=True)forargind['requiredAttrs']]
124+
[sub_parser_action.add_argument("--%s"%arg,required=True)
125+
forargind['requiredAttrs']]
110126

111127

112128
defdo_auth():
@@ -115,14 +131,14 @@ def do_auth():
115131
ssl_verify=ssl_verify,timeout=timeout)
116132
gl.auth()
117133
returngl
118-
except:
119-
die("Could not connect to GitLab (%s)"%gitlab_url)
134+
exceptExceptionase:
135+
die("Could not connect to GitLab%s(%s)"%(gitlab_url,str(e)))
120136

121137

122138
defget_id():
123139
try:
124140
id=d.pop('id')
125-
except:
141+
exceptException:
126142
die("Missing --id argument")
127143

128144
returnid
@@ -219,34 +235,42 @@ def do_project_owned():
219235
if__name__=="__main__":
220236
ssl_verify=True
221237
timeout=60
222-
parser=argparse.ArgumentParser(description='Useful GitLab Command Line Interface')
223-
parser.add_argument("-v","--verbosity","--fancy",help="increase output verbosity",action="store_true")
238+
parser=argparse.ArgumentParser(
239+
description='GitLab API Command Line Interface')
240+
parser.add_argument("-v","--verbosity","--fancy",
241+
help="increase output verbosity",
242+
action="store_true")
224243
parser.add_argument("--gitlab",metavar='gitlab',
225-
help="Specifies which python-gitlab.cfg configuration section should be used. "
226-
"If not defined, the default selection will be used.",required=False)
244+
help=("Specifies which python-gitlab.cfg "
245+
"configuration section should be used. "
246+
"If not defined, the default selection "
247+
"will be used."),
248+
required=False)
227249
subparsers=parser.add_subparsers(
228250
dest='what',
229251
title="positional argument",
230252
description='GitLab object',
231253
help='GitLab object'
232254
)
233-
#populate argparse for all Gitlab Object
255+
256+
# populate argparse for all Gitlab Object
234257
forclsingitlab.__dict__.values():
235258
try:
236259
ifgitlab.GitlabObjectingetmro(cls):
237260
sub_parser=subparsers.add_parser(clsToWhat(cls))
238261
populate_sub_parser_by_class(cls,sub_parser)
239-
except:
262+
exceptException:
240263
pass
241264

242265
arg=parser.parse_args()
243266
d=arg.__dict__
267+
244268
# read the config
245269
config=ConfigParser()
246270
config.read(['/etc/python-gitlab.cfg',
247271
os.path.expanduser('~/.python-gitlab.cfg')])
248272
gitlab_id=arg.gitlab
249-
#conflicts with "gitlab" attributewith GitlabObject class
273+
#conflicts with "gitlab" attributefrom GitlabObject class
250274
d.pop("gitlab")
251275
verbose=arg.verbosity
252276
action=arg.action
@@ -255,38 +279,39 @@ if __name__ == "__main__":
255279
ifgitlab_idisNone:
256280
try:
257281
gitlab_id=config.get('global','default')
258-
except:
259-
die("Impossible to get the gitlab id (not specified in config file)")
282+
exceptException:
283+
die("Impossible to get the gitlab id "
284+
"(not specified in config file)")
260285

261286
try:
262287
gitlab_url=config.get(gitlab_id,'url')
263288
gitlab_token=config.get(gitlab_id,'private_token')
264-
except:
265-
die("Impossible to get gitlab informations from configuration(%s)"%
266-
gitlab_id)
289+
exceptException:
290+
die("Impossible to get gitlab informations from configuration"
291+
"(%s)"%gitlab_id)
267292

268293
try:
269294
ssl_verify=config.getboolean('global','ssl_verify')
270-
except:
295+
exceptException:
271296
pass
272297
try:
273298
ssl_verify=config.getboolean(gitlab_id,'ssl_verify')
274-
except:
299+
exceptException:
275300
pass
276301

277302
try:
278303
timeout=config.getint('global','timeout')
279-
except:
304+
exceptException:
280305
pass
281306
try:
282307
timeout=config.getint(gitlab_id,'timeout')
283-
except:
308+
exceptException:
284309
pass
285310

286311
cls=None
287312
try:
288313
cls=gitlab.__dict__[whatToCls(what)]
289-
except:
314+
exceptException:
290315
die("Unknown object: %s"%what)
291316

292317
gl=do_auth()
@@ -335,4 +360,4 @@ if __name__ == "__main__":
335360
die("Unknown action: %s. Use\"gitlab -h %s\" to get details."%
336361
(action,what))
337362

338-
sys.exit(0)
363+
sys.exit(0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp