Skip to content

Commit b575ea5

Browse files
authored
Merge pull request #4 from edquist/SOFTWARE-4751.osg_co_id-option
Add -c OSG_CO_ID option (SOFTWARE-4751)
2 parents c480819 + 126fd92 commit b575ea5

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

osg-comanage-project-usermap.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@
55
import json
66
import getopt
77
import collections
8+
import urllib.error
89
import urllib.request
910

1011

12+
SCRIPT = os.path.basename(__file__)
1113
ENDPOINT = "https://registry-test.cilogon.org/registry/"
14+
OSG_CO_ID = 8
1215

1316

14-
_usage = """\
15-
usage: [PASS=...] {script} [OPTIONS]
17+
_usage = f"""\
18+
usage: [PASS=...] {SCRIPT} [OPTIONS]
1619
1720
OPTIONS:
1821
-u USER[:PASS] specify USER and optionally PASS on command line
22+
-c OSG_CO_ID specify OSG CO ID (default = {OSG_CO_ID})
1923
-d passfd specify open fd to read PASS
2024
-f passfile specify path to file to open and read PASS
2125
-e ENDPOINT specify REST endpoint
26+
(default = {ENDPOINT})
2227
-o outfile specify output file (default: write to stdout)
2328
-h display this help text
2429
@@ -27,22 +32,20 @@
2732
2. -d passfd (read from fd)
2833
3. -f passfile (read from file)
2934
4. read from $PASS env var
30-
31-
ENDPOINT defaults to {ENDPOINT}
3235
"""
3336

3437
def usage(msg=None):
3538
if msg:
3639
print(msg + "\n", file=sys.stderr)
3740

38-
script = os.path.basename(__file__)
39-
print(_usage.format(script=script, ENDPOINT=ENDPOINT), file=sys.stderr)
41+
print(_usage, file=sys.stderr)
4042
sys.exit()
4143

4244

4345
class Options:
4446
endpoint = ENDPOINT
4547
user = "co_8.project_script"
48+
osg_co_id = OSG_CO_ID
4649
outfile = None
4750
authstr = None
4851

@@ -88,8 +91,7 @@ def call_api(target, **kw):
8891

8992

9093
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)
9395

9496

9597
# primary api calls
@@ -150,7 +152,7 @@ def get_co_person_osguser(pid):
150152

151153
def parse_options(args):
152154
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')
154156
except getopt.GetoptError:
155157
usage()
156158

@@ -162,11 +164,12 @@ def parse_options(args):
162164

163165
for op, arg in ops:
164166
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
170173

171174
user, passwd = getpw(options.user, passfd, passfile)
172175
options.authstr = mkauthstr(user, passwd)
@@ -216,5 +219,9 @@ def main(args):
216219

217220

218221
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)
220227

0 commit comments

Comments
 (0)