29
29
-f passfile specify path to file to open and read PASS
30
30
-e ENDPOINT specify REST endpoint
31
31
(default = { ENDPOINT } )
32
- -o outfile specify output file (default: write to stdout)
33
32
-h display this help text
34
33
35
34
PASS for USER is taken from the first of:
@@ -51,7 +50,6 @@ class Options:
51
50
endpoint = ENDPOINT
52
51
user = "co_8.project_script"
53
52
osg_co_id = OSG_CO_ID
54
- outfile = None
55
53
authstr = None
56
54
57
55
@@ -147,29 +145,12 @@ def get(data):
147
145
148
146
# api call results massagers
149
147
150
- def get_osg_co_groups__map ():
151
- #print("get_osg_co_groups__map()")
152
- data = get_osg_co_groups () | get_datalist ("CoGroups" )
153
- return { g ["Id" ]: g ["Name" ] for g in data }
154
148
155
149
156
- def co_group_is_ospool (gid ):
157
- #print(f"co_group_is_ospool({gid})")
158
- data = get_co_group_identifiers (gid ) | get_datalist ("Identifiers" )
159
- return any ( i ["Type" ] == "ospoolproject" for i in data )
160
150
161
151
162
- def get_co_group_members__pids (gid ):
163
- #print(f"get_co_group_members__pids({gid})")
164
- data = get_co_group_members (gid ) | get_datalist ("CoGroupMembers" )
165
- return [ m ["Person" ]["Id" ] for m in data ]
166
152
167
153
168
- def get_co_person_osguser (pid ):
169
- #print(f"get_co_person_osguser({pid})")
170
- data = get_co_person_identifiers (pid ) | get_datalist ("Identifiers" )
171
- typemap = { i ["Type" ]: i ["Identifier" ] for i in data }
172
- return typemap .get ("osguser" )
173
154
174
155
175
156
def parse_options (args ):
@@ -191,53 +172,16 @@ def parse_options(args):
191
172
if op == '-d' : passfd = int (arg )
192
173
if op == '-f' : passfile = arg
193
174
if op == '-e' : options .endpoint = arg
194
- if op == '-o' : options .outfile = arg
195
175
196
176
user , passwd = getpw (options .user , passfd , passfile )
197
177
options .authstr = mkauthstr (user , passwd )
198
178
199
179
200
- def gid_pids_to_osguser_pid_gids (gid_pids , pid_osguser ):
201
- pid_gids = collections .defaultdict (set )
202
-
203
- for gid in gid_pids :
204
- for pid in gid_pids [gid ]:
205
- if pid_osguser [pid ] is not None :
206
- pid_gids [pid ].add (gid )
207
-
208
- return pid_gids
209
-
210
-
211
- def get_osguser_groups ():
212
- groups = get_osg_co_groups__map ()
213
- ospool_gids = filter (co_group_is_ospool , groups )
214
- gid_pids = { gid : get_co_group_members__pids (gid ) for gid in ospool_gids }
215
- all_pids = set ( pid for gid in gid_pids for pid in gid_pids [gid ] )
216
- pid_osguser = { pid : get_co_person_osguser (pid ) for pid in all_pids }
217
- pid_gids = gid_pids_to_osguser_pid_gids (gid_pids , pid_osguser )
218
-
219
- return { pid_osguser [pid ]: sorted (map (groups .get , gids ))
220
- for pid , gids in pid_gids .items () }
221
-
222
-
223
- def print_usermap_to_file (osguser_groups , file ):
224
- for osguser , groups in sorted (osguser_groups .items ()):
225
- print ("* {} {}" .format (osguser , "," .join (groups )), file = file )
226
-
227
-
228
- def print_usermap (osguser_groups ):
229
- if options .outfile :
230
- with open (options .outfile , "w" ) as w :
231
- print_usermap_to_file (osguser_groups , w )
232
- else :
233
- print_usermap_to_file (osguser_groups , sys .stdout )
234
180
235
181
236
182
def main (args ):
237
183
parse_options (args )
238
184
239
- osguser_groups = get_osguser_groups ()
240
- print_usermap (osguser_groups )
241
185
242
186
243
187
if __name__ == "__main__" :
0 commit comments