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

Commit23753df

Browse files
author
Gauvain Pocentek
committed
Merge branch 'master' into debian
2 parentsef44b84 +39a4a20 commit23753df

File tree

2 files changed

+113
-22
lines changed

2 files changed

+113
-22
lines changed

‎README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,34 +95,41 @@ The first argument is the object type on which we will act, the second one is
9595
the action:
9696

9797
`````
98-
gitlabProject list
98+
gitlabproject list
9999
`````
100100

101-
The usable objects are those which inherits GitlabObject (yes, the source is
102-
the doc ATM), and the actions are list, get, create, update, delete.
101+
Get help with:
102+
103+
`````
104+
# global help
105+
gitlab --help
106+
107+
# object help
108+
gitlab project help
109+
`````
103110

104111
Some examples:
105112

106113
`````bash
107114
# list all the projects:
108-
gitlabProject list
115+
gitlabproject list
109116

110117
# get a specific project (id 2):
111-
gitlabProject get --id=2
118+
gitlabproject get --id=2
112119

113120
# get a list of snippets for this project:
114-
gitlabProjectIssue list --project_id=2
121+
gitlabproject-issue list --project_id=2
115122

116123
# delete a Snippet (id 3):
117-
gitlabProjectSnippet delete --id=3 --project_id=2
124+
gitlabproject-snippet delete --id=3 --project_id=2
118125

119126
# update a Snippet:
120-
gitlabProjectSnippet update --id=4 --project_id=2 --code="My New Code"
127+
gitlabproject-snippet update --id=4 --project_id=2 --code="My New Code"
121128

122129
# create a Snippet:
123-
gitlabProjectSnippet create --project_id=2
130+
gitlabproject-snippet create --project_id=2
124131
Impossible to create object (Missing attribute(s): title, file_name, code)
125132

126133
# oops, let's add the attributes:
127-
gitlabProjectSnippet create --project_id=2 --title="the title" --file_name="the name" --code="the code"
134+
gitlabproject-snippet create --project_id=2 --title="the title" --file_name="the name" --code="the code"
128135
`````

‎gitlab

Lines changed: 96 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,105 @@
1818

1919
importos
2020
importsys
21+
importre
2122

2223
try:
2324
fromConfigParserimportConfigParser
2425
except:
2526
fromconfigparserimportConfigParser
2627

27-
frominspectimportgetmro
28+
frominspectimportgetmro,getmembers,isclass
2829

2930
importgitlab
3031

32+
camel_re=re.compile('(.)([A-Z])')
33+
3134
defdie(msg):
3235
sys.stderr.write(msg+"\n")
3336
sys.exit(1)
3437

38+
defwhatToCls(what):
39+
return"".join([s.capitalize()forsinwhat.split("-")])
40+
41+
defclsToWhat(cls):
42+
returncamel_re.sub(r'\1-\2',cls.__name__).lower()
43+
44+
defactionHelpList(cls):
45+
l= []
46+
foractionin'list','get','create','update','delete':
47+
attr='can'+action.capitalize()
48+
try:
49+
y=cls.__dict__[attr]
50+
except:
51+
y=gitlab.GitlabObject.__dict__[attr]
52+
ifnoty:
53+
continue
54+
55+
detail=''
56+
ifaction=='list':
57+
detail=" ".join(["--%s=ARG"%xforxincls.requiredListAttrs])
58+
elifactionin ['get','delete']:
59+
detail="--id=ARG "
60+
detail+=" ".join(["--%s=ARG"%xforxincls.requiredGetAttrs])
61+
elifaction=='create':
62+
detail=" ".join(["--%s=ARG"%xforxincls.requiredCreateAttrs])
63+
ifdetail:
64+
detail+=" "
65+
detail+=" ".join(["[--%s=ARG]"%xforxincls.optionalCreateAttrs])
66+
elifaction=='update':
67+
detail=" ".join(["[--%s=ARG]"%xforxincls.requiredCreateAttrs])
68+
ifdetail:
69+
detail+=" "
70+
detail+=" ".join(["[--%s=ARG]"%xforxincls.optionalCreateAttrs])
71+
l.append("%s %s"% (action,detail))
72+
73+
return (l)
74+
75+
defusage():
76+
print("usage: gitlab [--help] [--gitlab=GITLAB] what action [options]")
77+
print("")
78+
print("--gitlab=GITLAB: Specifies which python-gitlab.cfg configuration section should be used.")
79+
print(" If not defined, the default selection will be used.")
80+
print("")
81+
print("--help : Displays this message.")
82+
print("")
83+
print("Available `options` depend on which what/action couple is used.")
84+
print("If `action` is\"help\", available actions and options will be listed for `what`.")
85+
print("")
86+
print("Available `what` values are:")
87+
88+
classes= []
89+
forname,oingetmembers(gitlab):
90+
ifnotisclass(o):
91+
continue
92+
ifgitlab.GitlabObjectingetmro(o)ando!=gitlab.GitlabObject:
93+
classes.append(o)
94+
95+
defs(a,b):
96+
ifa.__name__<b.__name__:
97+
return-1
98+
elifa.__name__>b.__name__:
99+
return1
100+
101+
classes.sort(cmp=s)
102+
forclsinclasses:
103+
print(" %s"%clsToWhat(cls))
104+
105+
35106
gitlab_id=None
36107

37108
args= []
38109
d= {}
39110
forarginsys.argv[1:]:
40111
ifarg.startswith('--'):
112+
arg=arg[2:]
113+
114+
ifarg=='help':
115+
usage()
116+
sys.exit(0)
117+
41118
k,v=arg.split('=',2)
42-
k=k[2:].strip()
119+
k=k.strip()
43120
v=v.strip()
44121

45122
ifk=='gitlab':
@@ -66,29 +143,36 @@ try:
66143
except:
67144
die("Impossible to get gitlab informations from configuration (%s)"%gitlab_id)
68145

69-
try:
70-
gl=gitlab.Gitlab(gitlab_url,private_token=gitlab_token)
71-
gl.auth()
72-
except:
73-
die("Could not connect to GitLab (%s)"%gitlab_url)
74-
75146
try:
76147
what=args.pop(0)
77148
action=args.pop(0)
78149
except:
79150
die("Missing arguments")
80151

81-
ifactionnotin ['get','list','update','create','delete']:
82-
die("Unknown action: %s"%action)
152+
ifactionnotin ['get','list','update','create','delete','help']:
153+
die("Unknown action: %s. Use\"gitlab %s help\" to get details."% (action,what))
83154

84155
try:
85-
cls=gitlab.__dict__[what]
156+
cls=gitlab.__dict__[whatToCls(what)]
86157
except:
87158
die("Unknown object: %s"%what)
88159

89160
ifgitlab.GitlabObjectnotingetmro(cls):
90161
die("Unknown object: %s"%what)
91162

163+
ifaction=="help":
164+
print("%s options:"%what)
165+
foriteminactionHelpList(cls):
166+
print(" %s %s"% (what,item))
167+
168+
sys.exit(0)
169+
170+
try:
171+
gl=gitlab.Gitlab(gitlab_url,private_token=gitlab_token)
172+
gl.auth()
173+
except:
174+
die("Could not connect to GitLab (%s)"%gitlab_url)
175+
92176
ifaction=="create":
93177
ifnotcls.canCreate:
94178
die("%s objects can't be created"%what)
@@ -114,7 +198,7 @@ elif action == "list":
114198

115199
foroinl:
116200
o.pretty_print()
117-
print
201+
print("")
118202

119203
sys.exit(0)
120204

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp