diff options
| author | Gauvain Pocentek <gauvain@pocentek.net> | 2013-06-22 09:59:01 +0200 |
|---|---|---|
| committer | Gauvain Pocentek <gauvain@pocentek.net> | 2013-06-22 09:59:01 +0200 |
| commit | 3b15c6d87e0a70f0769ecfd310a2ed3480abfe2b (patch) | |
| tree | fda6a1626b28eae79ae3fd70623372f1f0eec5ef | |
| parent | 41b6dbadcc7725248763515f77ae0f6bd4186dad (diff) | |
| download | gitlab-3b15c6d87e0a70f0769ecfd310a2ed3480abfe2b.tar.gz | |
gitlab: be less verbose by default
Provide a --fancy option to output more data on list/get/create queries.
| -rwxr-xr-x | gitlab | 23 | ||||
| -rw-r--r-- | gitlab.py | 22 |
2 files changed, 40 insertions, 5 deletions
@@ -73,11 +73,11 @@ def actionHelpList(cls): return (l) def usage(): - print("usage: gitlab [--help] [--gitlab=GITLAB] what action [options]") + print("usage: gitlab [--help] [--gitlab=GITLAB] [--fancy] what action [options]") print("") print("--gitlab=GITLAB: Specifies which python-gitlab.cfg configuration section should be used.") print(" If not defined, the default selection will be used.") - print("") + print("--fancy : More verbose output.") print("--help : Displays this message.") print("") print("Available `options` depend on which what/action couple is used.") @@ -104,6 +104,7 @@ def usage(): gitlab_id = None +verbose = False args = [] d = {} @@ -114,6 +115,9 @@ for arg in sys.argv[1:]: if arg == 'help': usage() sys.exit(0) + elif arg == 'fancy': + verbose = True + continue k, v = arg.split('=', 2) k = k.strip() @@ -183,7 +187,10 @@ if action == "create": except Exception as e: die("Impossible to create object (%s)" % str(e)) - o.pretty_print() + if verbose: + o.pretty_print() + else: + o.short_print() sys.exit(0) @@ -197,7 +204,10 @@ elif action == "list": die("Impossible to list objects (%s)" % str(e)) for o in l: - o.pretty_print() + if verbose: + o.pretty_print() + else: + o.short_print() print("") sys.exit(0) @@ -216,7 +226,10 @@ elif action == "get": except Exception as e: die("Impossible to get object (%s)" % str(e)) - o.pretty_print() + if verbose: + o.pretty_print() + else: + o.short_print() sys.exit(0) @@ -397,6 +397,7 @@ class GitlabObject(object): requiredCreateAttrs = [] optionalCreateAttrs = [] idAttr = 'id' + shortPrintAttr = None @classmethod def list(cls, gl, **kwargs): @@ -486,6 +487,14 @@ class GitlabObject(object): def __str__(self): return '%s => %s' % (type(self), str(self.__dict__)) + def short_print(self, depth=0): + id = self.__dict__[self.idAttr] + print("%s%s: %s" % (" " * depth * 2, self.idAttr, id)) + if self.shortPrintAttr: + print ("%s%s: %s" % (" " * depth * 2, + self.shortPrintAttr.replace('_', '-'), + self.__dict__[self.shortPrintAttr])) + def pretty_print(self, depth=0): id = self.__dict__[self.idAttr] print("%s%s: %s" % (" " * depth * 2, self.idAttr, id)) @@ -511,6 +520,7 @@ class GitlabObject(object): class User(GitlabObject): _url = '/users' + shortPrintAttr = 'username' requiredCreateAttrs = ['email', 'password', 'username', 'name'] optionalCreateAttrs = ['skype', 'linkedin', 'twitter', 'projects_limit', 'extern_uid', 'provider', 'bio'] @@ -539,6 +549,7 @@ class Group(GitlabObject): _url = '/groups' _constructorTypes = {'projects': 'Project'} requiredCreateAttrs = ['name', 'path'] + shortPrintAttr = 'name' def transfer_project(self, id): url = '/groups/%d/projects/%d?private_token=%s' % \ @@ -551,6 +562,7 @@ class Group(GitlabObject): class Hook(GitlabObject): _url = '/hooks' requiredCreateAttrs = ['url'] + shortPrintAttr = 'url' class Issue(GitlabObject): @@ -561,6 +573,7 @@ class Issue(GitlabObject): canDelete = False canUpdate = False canCreate = False + shortPrintAttr = 'title' class ProjectBranch(GitlabObject): @@ -599,6 +612,7 @@ class ProjectCommit(GitlabObject): canUpdate = False canCreate = False requiredListAttrs = ['project_id'] + shortPrintAttr = 'title' class ProjectKey(GitlabObject): @@ -614,6 +628,7 @@ class ProjectHook(GitlabObject): requiredListAttrs = ['project_id'] requiredGetAttrs = ['project_id'] requiredCreateAttrs = ['project_id', 'url'] + shortPrintAttr = 'url' class ProjectIssueNote(GitlabObject): @@ -636,6 +651,7 @@ class ProjectIssue(GitlabObject): requiredCreateAttrs = ['project_id', 'title'] optionalCreateAttrs = ['description', 'assignee_id', 'milestone_id', 'labels'] + shortPrintAttr = 'title' def Note(self, id=None, **kwargs): return self._getListOrObject(ProjectIssueNote, id, @@ -650,6 +666,7 @@ class ProjectMember(GitlabObject): requiredListAttrs = ['project_id'] requiredGetAttrs = ['project_id'] requiredCreateAttrs = ['project_id', 'user_id', 'access_level'] + shortPrintAttr = 'username' class ProjectNote(GitlabObject): @@ -664,11 +681,13 @@ class ProjectNote(GitlabObject): class ProjectTag(GitlabObject): _url = '/projects/%(project_id)s/repository/tags' + idAttr = 'name' canGet = False canDelete = False canUpdate = False canCreate = False requiredListAttrs = ['project_id'] + shortPrintAttr = 'name' class ProjectMergeRequestNote(GitlabObject): @@ -704,6 +723,7 @@ class ProjectMilestone(GitlabObject): requiredGetAttrs = ['project_id'] requiredCreateAttrs = ['project_id', 'title'] optionalCreateAttrs = ['description', 'due_date'] + shortPrintAttr = 'title' class ProjectSnippetNote(GitlabObject): @@ -723,6 +743,7 @@ class ProjectSnippet(GitlabObject): requiredGetAttrs = ['project_id'] requiredCreateAttrs = ['project_id', 'title', 'file_name', 'code'] optionalCreateAttrs = ['lifetime'] + shortPrintAttr = 'title' def Content(self): url = "/projects/%(project_id)s/snippets/%(snippet_id)s/raw" % \ @@ -750,6 +771,7 @@ class Project(GitlabObject): optionalCreateAttrs = ['default_branch', 'issues_enabled', 'wall_enabled', 'merge_requests_enabled', 'wiki_enabled', 'namespace_id'] + shortPrintAttr = 'path' def Branch(self, id=None, **kwargs): return self._getListOrObject(ProjectBranch, id, |
