5
5
import json
6
6
import getopt
7
7
import collections
8
+ import urllib .error
8
9
import urllib .request
9
10
10
11
12
+ SCRIPT = os .path .basename (__file__ )
11
13
ENDPOINT = "https://registry-test.cilogon.org/registry/"
14
+ OSG_CO_ID = 8
12
15
13
16
14
- _usage = """\
15
- usage: [PASS=...] {script } [OPTIONS]
17
+ _usage = f """\
18
+ usage: [PASS=...] { SCRIPT } [OPTIONS]
16
19
17
20
OPTIONS:
18
21
-u USER[:PASS] specify USER and optionally PASS on command line
22
+ -c OSG_CO_ID specify OSG CO ID (default = { OSG_CO_ID } )
19
23
-d passfd specify open fd to read PASS
20
24
-f passfile specify path to file to open and read PASS
21
25
-e ENDPOINT specify REST endpoint
26
+ (default = { ENDPOINT } )
22
27
-o outfile specify output file (default: write to stdout)
23
28
-h display this help text
24
29
27
32
2. -d passfd (read from fd)
28
33
3. -f passfile (read from file)
29
34
4. read from $PASS env var
30
-
31
- ENDPOINT defaults to {ENDPOINT}
32
35
"""
33
36
34
37
def usage (msg = None ):
35
38
if msg :
36
39
print (msg + "\n " , file = sys .stderr )
37
40
38
- script = os .path .basename (__file__ )
39
- print (_usage .format (script = script , ENDPOINT = ENDPOINT ), file = sys .stderr )
41
+ print (_usage , file = sys .stderr )
40
42
sys .exit ()
41
43
42
44
43
45
class Options :
44
46
endpoint = ENDPOINT
45
47
user = "co_8.project_script"
48
+ osg_co_id = OSG_CO_ID
46
49
outfile = None
47
50
authstr = None
48
51
@@ -88,8 +91,7 @@ def call_api(target, **kw):
88
91
89
92
90
93
def get_osg_co_groups ():
91
- OSG_CO_ID = 8
92
- return call_api ("co_groups.json" , coid = OSG_CO_ID )
94
+ return call_api ("co_groups.json" , coid = options .osg_co_id )
93
95
94
96
95
97
# primary api calls
@@ -150,7 +152,7 @@ def get_co_person_osguser(pid):
150
152
151
153
def parse_options (args ):
152
154
try :
153
- ops , args = getopt .getopt (args , 'u:d:f:e:o:h' )
155
+ ops , args = getopt .getopt (args , 'u:c: d:f:e:o:h' )
154
156
except getopt .GetoptError :
155
157
usage ()
156
158
@@ -162,11 +164,12 @@ def parse_options(args):
162
164
163
165
for op , arg in ops :
164
166
if op == '-h' : usage ()
165
- if op == '-u' : options .user = arg
166
- if op == '-d' : passfd = int (arg )
167
- if op == '-f' : passfile = arg
168
- if op == '-e' : options .endpoint = arg
169
- if op == '-o' : options .outfile = arg
167
+ if op == '-u' : options .user = arg
168
+ if op == '-c' : options .osg_co_id = int (arg )
169
+ if op == '-d' : passfd = int (arg )
170
+ if op == '-f' : passfile = arg
171
+ if op == '-e' : options .endpoint = arg
172
+ if op == '-o' : options .outfile = arg
170
173
171
174
user , passwd = getpw (options .user , passfd , passfile )
172
175
options .authstr = mkauthstr (user , passwd )
@@ -216,5 +219,9 @@ def main(args):
216
219
217
220
218
221
if __name__ == "__main__" :
219
- main (sys .argv [1 :])
222
+ try :
223
+ main (sys .argv [1 :])
224
+ except urllib .error .HTTPError as e :
225
+ print (e , file = sys .stderr )
226
+ sys .exit (1 )
220
227
0 commit comments