Skip to content

Commit e931b7d

Browse files
committed
add -o outfile option (SOFTWARE-4751)
1 parent 17fc95e commit e931b7d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

osg-comanage-project-usermap.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-d passfd specify open fd to read PASS
2020
-f passfile specify path to file to open and read PASS
2121
-e ENDPOINT specify REST endpoint
22+
-o outfile specify output file (default: write to stdout)
2223
2324
PASS for USER is taken from the first of:
2425
1. -u USER:PASS
@@ -41,6 +42,7 @@ def usage(msg=None):
4142
class Options:
4243
endpoint = ENDPOINT
4344
user = "co_8.project_script"
45+
outfile = None
4446
authstr = None
4547

4648

@@ -151,6 +153,7 @@ def parse_options(args):
151153
if op == '-d': passfd = int(arg)
152154
if op == '-f': passfile = arg
153155
if op == '-e': options.endpoint = arg
156+
if op == '-o': options.outfile = arg
154157

155158
user, passwd = getpw(options.user, passfd, passfile)
156159
options.authstr = mkauthstr(user, passwd)
@@ -179,9 +182,17 @@ def get_osguser_groups():
179182
for pid, gids in pid_gids.items() }
180183

181184

182-
def print_usermap(osguser_groups):
185+
def print_usermap_to_file(osguser_groups, file):
183186
for osguser, groups in osguser_groups.items():
184-
print("* {} {}".format(osguser, ",".join(groups)))
187+
print("* {} {}".format(osguser, ",".join(groups)), file=file)
188+
189+
190+
def print_usermap(osguser_groups):
191+
if options.outfile:
192+
with open(options.outfile, "w") as w:
193+
print_usermap_to_file(osguser_groups, w)
194+
else:
195+
print_usermap_to_file(osguser_groups, sys.stdout)
185196

186197

187198
def main(args):

0 commit comments

Comments
 (0)