| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4c6c778 commit d7bea07
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,14 +20,14 @@ | |||
| 20 | 20 | from __future__ import division | |
| 21 | 21 | from __future__ import absolute_import | |
| 22 | 22 | import argparse | |
| 23 | - from inspect import getmro | ||
| 23 | + import inspect | ||
| 24 | 24 | import os | |
| 25 | 25 | import re | |
| 26 | 26 | import sys | |
| 27 | 27 | try: | |
| 28 | - from ConfigParser import ConfigParser | ||
| 28 | + import ConfigParser as configparser | ||
| 29 | 29 | except ImportError: | |
| 30 | - from configparser import ConfigParser | ||
| 30 | + import configparser | ||
| 31 | 31 | ||
| 32 | 32 | import gitlab | |
| 33 | 33 | ||
@@ -118,7 +118,7 @@ def populate_sub_parser_by_class(cls, sub_parser): | |||
| 118 | 118 | for arg in d['requiredAttrs']] | |
| 119 | 119 | ||
| 120 | 120 | ||
| 121 | - def do_auth(): | ||
| 121 | + def do_auth(gitlab_url, gitlab_token, ssl_verify, timeout): | ||
| 122 | 122 | try: | |
| 123 | 123 | gl = gitlab.Gitlab(gitlab_url, private_token=gitlab_token, | |
| 124 | 124 | ssl_verify=ssl_verify, timeout=timeout) | |
@@ -128,74 +128,74 @@ def do_auth(): | |||
| 128 | 128 | die("Could not connect to GitLab %s (%s)" % (gitlab_url, str(e))) | |
| 129 | 129 | ||
| 130 | 130 | ||
| 131 | - def get_id(cls): | ||
| 131 | + def get_id(cls, args): | ||
| 132 | 132 | try: | |
| 133 | - id = d.pop(cls.idAttr) | ||
| 133 | + id = args.pop(cls.idAttr) | ||
| 134 | 134 | except Exception: | |
| 135 | 135 | die("Missing --%s argument" % cls.idAttr.replace('_', '-')) | |
| 136 | 136 | ||
| 137 | 137 | return id | |
| 138 | 138 | ||
| 139 | 139 | ||
| 140 | - def do_create(cls, d): | ||
| 140 | + def do_create(cls, gl, what, args): | ||
| 141 | 141 | if not cls.canCreate: | |
| 142 | 142 | die("%s objects can't be created" % what) | |
| 143 | 143 | ||
| 144 | 144 | try: | |
| 145 | - o = cls(gl, d) | ||
| 145 | + o = cls(gl, args) | ||
| 146 | 146 | o.save() | |
| 147 | 147 | except Exception as e: | |
| 148 | 148 | die("Impossible to create object (%s)" % str(e)) | |
| 149 | 149 | ||
| 150 | 150 | return o | |
| 151 | 151 | ||
| 152 | 152 | ||
| 153 | - def do_list(cls, d): | ||
| 153 | + def do_list(cls, gl, what, args): | ||
| 154 | 154 | if not cls.canList: | |
| 155 | 155 | die("%s objects can't be listed" % what) | |
| 156 | 156 | ||
| 157 | 157 | try: | |
| 158 | - l = cls.list(gl, **d) | ||
| 158 | + l = cls.list(gl, **args) | ||
| 159 | 159 | except Exception as e: | |
| 160 | 160 | die("Impossible to list objects (%s)" % str(e)) | |
| 161 | 161 | ||
| 162 | 162 | return l | |
| 163 | 163 | ||
| 164 | 164 | ||
| 165 | - def do_get(cls, d): | ||
| 165 | + def do_get(cls, gl, what, args): | ||
| 166 | 166 | if not cls.canGet: | |
| 167 | 167 | die("%s objects can't be retrieved" % what) | |
| 168 | 168 | ||
| 169 | 169 | id = None | |
| 170 | 170 | if cls not in [gitlab.CurrentUser]: | |
| 171 | - id = get_id(cls) | ||
| 171 | + id = get_id(cls, args) | ||
| 172 | 172 | ||
| 173 | 173 | try: | |
| 174 | - o = cls(gl, id, **d) | ||
| 174 | + o = cls(gl, id, **args) | ||
| 175 | 175 | except Exception as e: | |
| 176 | 176 | die("Impossible to get object (%s)" % str(e)) | |
| 177 | 177 | ||
| 178 | 178 | return o | |
| 179 | 179 | ||
| 180 | 180 | ||
| 181 | - def do_delete(cls, d): | ||
| 181 | + def do_delete(cls, gl, what, args): | ||
| 182 | 182 | if not cls.canDelete: | |
| 183 | 183 | die("%s objects can't be deleted" % what) | |
| 184 | 184 | ||
| 185 | - o = do_get(cls, d) | ||
| 185 | + o = do_get(cls, args) | ||
| 186 | 186 | try: | |
| 187 | 187 | o.delete() | |
| 188 | 188 | except Exception as e: | |
| 189 | 189 | die("Impossible to destroy object (%s)" % str(e)) | |
| 190 | 190 | ||
| 191 | 191 | ||
| 192 | - def do_update(cls, d): | ||
| 192 | + def do_update(cls, gl, what, args): | ||
| 193 | 193 | if not cls.canUpdate: | |
| 194 | 194 | die("%s objects can't be updated" % what) | |
| 195 | 195 | ||
| 196 | - o = do_get(cls, d) | ||
| 196 | + o = do_get(cls, args) | ||
| 197 | 197 | try: | |
| 198 | - for k, v in d.items(): | ||
| 198 | + for k, v in args.items(): | ||
| 199 | 199 | o.__dict__[k] = v | |
| 200 | 200 | o.save() | |
| 201 | 201 | except Exception as e: | |
@@ -204,28 +204,28 @@ def do_update(cls, d): | |||
| 204 | 204 | return o | |
| 205 | 205 | ||
| 206 | 206 | ||
| 207 | - def do_project_search(d): | ||
| 207 | + def do_project_search(gl, what, args): | ||
| 208 | 208 | try: | |
| 209 | - return gl.search_projects(d['query']) | ||
| 209 | + return gl.search_projects(args['query']) | ||
| 210 | 210 | except Exception as e: | |
| 211 | 211 | die("Impossible to search projects (%s)" % str(e)) | |
| 212 | 212 | ||
| 213 | 213 | ||
| 214 | - def do_project_all(): | ||
| 214 | + def do_project_all(gl, what, args): | ||
| 215 | 215 | try: | |
| 216 | 216 | return gl.all_projects() | |
| 217 | 217 | except Exception as e: | |
| 218 | 218 | die("Impossible to list all projects (%s)" % str(e)) | |
| 219 | 219 | ||
| 220 | 220 | ||
| 221 | - def do_project_owned(): | ||
| 221 | + def do_project_owned(gl, what, args): | ||
| 222 | 222 | try: | |
| 223 | 223 | return gl.owned_projects() | |
| 224 | 224 | except Exception as e: | |
| 225 | 225 | die("Impossible to list owned projects (%s)" % str(e)) | |
| 226 | 226 | ||
| 227 | 227 | ||
| 228 | - if __name__ == "__main__": | ||
| 228 | + def main(): | ||
| 229 | 229 | ssl_verify = True | |
| 230 | 230 | timeout = 60 | |
| 231 | 231 | ||
@@ -247,7 +247,7 @@ def do_project_owned(): | |||
| 247 | 247 | classes = [] | |
| 248 | 248 | for cls in gitlab.__dict__.values(): | |
| 249 | 249 | try: | |
| 250 | - if gitlab.GitlabObject in getmro(cls): | ||
| 250 | + if gitlab.GitlabObject in inspect.getmro(cls): | ||
| 251 | 251 | classes.append(cls) | |
| 252 | 252 | except AttributeError: | |
| 253 | 253 | pass | |
@@ -261,15 +261,15 @@ def do_project_owned(): | |||
| 261 | 261 | populate_sub_parser_by_class(cls, object_subparsers) | |
| 262 | 262 | ||
| 263 | 263 | arg = parser.parse_args() | |
| 264 | - d = arg.__dict__ | ||
| 264 | + args = arg.__dict__ | ||
| 265 | 265 | ||
| 266 | 266 | # read the config | |
| 267 | - config = ConfigParser() | ||
| 267 | + config = configparser.ConfigParser() | ||
| 268 | 268 | config.read(['/etc/python-gitlab.cfg', | |
| 269 | 269 | os.path.expanduser('~/.python-gitlab.cfg')]) | |
| 270 | 270 | gitlab_id = arg.gitlab | |
| 271 | 271 | # conflicts with "gitlab" attribute from GitlabObject class | |
| 272 | - d.pop("gitlab") | ||
| 272 | + args.pop("gitlab") | ||
| 273 | 273 | verbose = arg.verbose | |
| 274 | 274 | action = arg.action | |
| 275 | 275 | what = arg.what | |
@@ -312,50 +312,46 @@ def do_project_owned(): | |||
| 312 | 312 | except Exception: | |
| 313 | 313 | die("Unknown object: %s" % what) | |
| 314 | 314 | ||
| 315 | - gl = do_auth() | ||
| 315 | + gl = do_auth(gitlab_url, gitlab_token, ssl_verify, timeout) | ||
| 316 | 316 | ||
| 317 | 317 | if action == CREATE or action == GET: | |
| 318 | - o = globals()['do_%s' % action.lower()](cls, d) | ||
| 318 | + o = globals()['do_%s' % action.lower()](cls, gl, what, args) | ||
| 319 | 319 | o.display(verbose) | |
| 320 | 320 | ||
| 321 | 321 | elif action == LIST: | |
| 322 | - for o in do_list(cls, d): | ||
| 322 | + for o in do_list(cls, gl, what, args): | ||
| 323 | 323 | o.display(verbose) | |
| 324 | 324 | print("") | |
| 325 | 325 | ||
| 326 | 326 | elif action == DELETE or action == UPDATE: | |
| 327 | - o = globals()['do_%s' % action.lower()](cls, d) | ||
| 327 | + o = globals()['do_%s' % action.lower()](cls, gl, what, args) | ||
| 328 | 328 | ||
| 329 | 329 | elif action == PROTECT or action == UNPROTECT: | |
| 330 | 330 | if cls != gitlab.ProjectBranch: | |
| 331 | 331 | die("%s objects can't be protected" % what) | |
| 332 | 332 | ||
| 333 | - o = do_get(cls, d) | ||
| 333 | + o = do_get(cls, gl, what, args) | ||
| 334 | 334 | getattr(o, action)() | |
| 335 | 335 | ||
| 336 | 336 | elif action == SEARCH: | |
| 337 | 337 | if cls != gitlab.Project: | |
| 338 | 338 | die("%s objects don't support this request" % what) | |
| 339 | 339 | ||
| 340 | - for o in do_project_search(d): | ||
| 340 | + for o in do_project_search(gl, what, args): | ||
| 341 | 341 | o.display(verbose) | |
| 342 | 342 | ||
| 343 | 343 | elif action == OWNED: | |
| 344 | 344 | if cls != gitlab.Project: | |
| 345 | 345 | die("%s objects don't support this request" % what) | |
| 346 | 346 | ||
| 347 | - for o in do_project_owned(): | ||
| 347 | + for o in do_project_owned(gl, what, args): | ||
| 348 | 348 | o.display(verbose) | |
| 349 | 349 | ||
| 350 | 350 | elif action == ALL: | |
| 351 | 351 | if cls != gitlab.Project: | |
| 352 | 352 | die("%s objects don't support this request" % what) | |
| 353 | 353 | ||
| 354 | - for o in do_project_all(): | ||
| 354 | + for o in do_project_all(gl, what, args): | ||
| 355 | 355 | o.display(verbose) | |
| 356 | 356 | ||
| 357 | - else: | ||
| 358 | - die("Unknown action: %s. Use \"gitlab -h %s\" to get details." % | ||
| 359 | - (action, what)) | ||
| 360 | - | ||
| 361 | 357 | sys.exit(0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,8 +20,12 @@ def get_version(): | |||
| 20 | 20 | license='LGPLv3', | |
| 21 | 21 | url='https://github.com/gpocentek/python-gitlab', | |
| 22 | 22 | packages=['gitlab'], | |
| 23 | - scripts=['bin/gitlab'], | ||
| 24 | 23 | install_requires=['requests', 'six'], | |
| 24 | + entry_points={ | ||
| 25 | + 'console_scripts': [ | ||
| 26 | + 'gitlab = gitlab.cli:main' | ||
| 27 | + ] | ||
| 28 | + }, | ||
| 25 | 29 | classifiers=[ | |
| 26 | 30 | 'Development Status :: 5 - Production/Stable', | |
| 27 | 31 | 'Environment :: Console', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ commands = | |||
| 15 | 15 | ||
| 16 | 16 | [testenv:pep8] | |
| 17 | 17 | commands = | |
| 18 | - flake8 {posargs} gitlab bin | ||
| 18 | + flake8 {posargs} gitlab/ | ||
| 19 | 19 | ||
| 20 | 20 | [testenv:venv] | |
| 21 | 21 | commands = {posargs} | |
| Back | FazBrowse Home | New Git URL |
0 commit comments