Skip to content

Commit 7ecd941

Browse files
committed
update CLI handling and usage (SOFTWARE-5058)
1 parent 4791b3c commit 7ecd941

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

create_project.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
_usage = f"""\
25-
usage: [PASS=...] {SCRIPT} [OPTIONS]
25+
usage: [PASS=...] {SCRIPT} [OPTIONS] COGroupNameOrId ProjectName
2626
2727
OPTIONS:
2828
-u USER[:PASS] specify USER and optionally PASS on command line
@@ -31,15 +31,10 @@
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
3734
-h display this help text
3835
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.
36+
Adds an identifier of type ospoolproject named Yes-ProjectName to
37+
a COGroup based on its Name or CO Group Id.
4338
4439
PASS for USER is taken from the first of:
4540
1. -u USER:PASS
@@ -61,9 +56,9 @@ class Options:
6156
osg_co_id = OSG_CO_ID
6257
user = USER
6358
authstr = None
64-
fix_gid = None
65-
info_gid = None
66-
showall = False
59+
gid = None
60+
gname = None
61+
project = None
6762

6863

6964
options = Options()
@@ -327,12 +322,19 @@ def fixup_unixcluster_group(gid):
327322

328323
def parse_options(args):
329324
try:
330-
ops, args = getopt.getopt(args, 'u:c:d:f:e:x:i:ah')
325+
ops, args = getopt.getopt(args, 'u:c:d:f:e:h')
331326
except getopt.GetoptError:
332327
usage()
333328

334-
if args:
335-
usage("Extra arguments: %s" % repr(args))
329+
if len(args) != 2:
330+
usage()
331+
332+
cogroup, project = args
333+
if re.fullmatch(r'\d+', cogroup):
334+
options.gid = int(cogroup)
335+
else:
336+
options.gname = cogroup
337+
options.project = project
336338

337339
passfd = None
338340
passfile = None
@@ -344,9 +346,6 @@ def parse_options(args):
344346
if op == '-d': passfd = int(arg)
345347
if op == '-f': passfile = arg
346348
if op == '-e': options.endpoint = arg
347-
if op == '-x': options.fix_gid = int(arg)
348-
if op == '-i': options.info_gid = int(arg)
349-
if op == '-a': options.showall = True
350349

351350
user, passwd = getpw(options.user, passfd, passfile)
352351
options.authstr = mkauthstr(user, passwd)
@@ -355,21 +354,18 @@ def parse_options(args):
355354
def main(args):
356355
parse_options(args)
357356

358-
if options.fix_gid:
359-
return fixup_unixcluster_group(options.fix_gid)
360-
elif options.showall:
361-
show_all_unixcluster_groups()
362-
elif options.info_gid:
363-
show_one_unixcluster_group(options.info_gid)
364-
else:
365-
show_misnamed_unixcluster_groups()
357+
if options.gname:
358+
options.gid = gname_to_gid(options.gname)
366359

367-
return 0
360+
add_project_identifier_to_group(options.gid, options.project)
361+
362+
# no exceptions, must have worked
363+
print(":thumbsup:")
368364

369365

370366
if __name__ == "__main__":
371367
try:
372-
sys.exit(main(sys.argv[1:]))
368+
main(sys.argv[1:])
373369
except (RuntimeError, urllib.error.HTTPError) as e:
374370
print(e, file=sys.stderr)
375371
sys.exit(1)

0 commit comments

Comments
 (0)