Skip to content

Commit ccc05a3

Browse files
committed
add new options / CLI handling (SOFTWARE-5057)
1 parent f3d763f commit ccc05a3

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

group_fixup.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@
3131
-f passfile specify path to file to open and read PASS
3232
-e ENDPOINT specify REST endpoint
3333
(default = {ENDPOINT})
34+
-a show all UnixCluster autogroups, not just misnamed ones
35+
-i COGroupId show fixup info for a specific CO Group
36+
-x COGroupId run UnixCluster Group fixups for given CO Group Id
3437
-h display this help text
3538
39+
Run without options to display misnamed UnixCluster autogroups.
40+
Run with -a to include UnixCluster autogroups with fixed names, too.
41+
Run with -i to display only a given CO Group.
42+
Run with -x to fixup a given CO Group.
43+
3644
PASS for USER is taken from the first of:
3745
1. -u USER:PASS
3846
2. -d passfd (read from fd)
@@ -49,10 +57,13 @@ def usage(msg=None):
4957

5058

5159
class Options:
52-
endpoint = ENDPOINT
60+
endpoint = ENDPOINT
5361
osg_co_id = OSG_CO_ID
5462
user = USER
55-
authstr = None
63+
authstr = None
64+
fix_gid = None
65+
info_gid = None
66+
showall = False
5667

5768

5869
options = Options()
@@ -281,7 +292,7 @@ def fixup_unixcluster_group(gid):
281292

282293
def parse_options(args):
283294
try:
284-
ops, args = getopt.getopt(args, 'u:c:d:f:e:o:h')
295+
ops, args = getopt.getopt(args, 'u:c:d:f:e:x:i:ah')
285296
except getopt.GetoptError:
286297
usage()
287298

@@ -298,22 +309,33 @@ def parse_options(args):
298309
if op == '-d': passfd = int(arg)
299310
if op == '-f': passfile = arg
300311
if op == '-e': options.endpoint = arg
312+
if op == '-x': options.fix_gid = int(arg)
313+
if op == '-i': options.info_gid = int(arg)
314+
if op == '-a': options.showall = True
301315

302316
user, passwd = getpw(options.user, passfd, passfile)
303317
options.authstr = mkauthstr(user, passwd)
304318

305319

306-
307-
308320
def main(args):
309321
parse_options(args)
310322

323+
if options.fix_gid:
324+
return fixup_unixcluster_group(options.fix_gid)
325+
elif options.showall:
326+
show_all_unixcluster_groups()
327+
elif options.info_gid:
328+
show_one_unixcluster_group(options.info_gid)
329+
else:
330+
show_misnamed_unixcluster_groups()
331+
332+
return 0
311333

312334

313335
if __name__ == "__main__":
314336
try:
315-
main(sys.argv[1:])
316-
except urllib.error.HTTPError as e:
337+
sys.exit(main(sys.argv[1:]))
338+
except (RuntimeError, urllib.error.HTTPError) as e:
317339
print(e, file=sys.stderr)
318340
sys.exit(1)
319341

0 commit comments

Comments
 (0)