Skip to content

Commit 575a016

Browse files
Updates from Jason review
Also "replace"-ed repoveprefix, since I think this script might be running on a machine with only python 3.6.8 (removeprefix needs 3.9)
1 parent 47ca49b commit 575a016

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

group_identifier_assigner.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
POST = "POST"
2121
DELETE = "DELETE"
2222

23-
OSPOOL_PATTERN_STR = "Yes-"
23+
OSPOOL_PROJECT_PREFIX_STR = "Yes-"
2424
PROJECT_GIDS_START = 200000
2525

2626
_usage = f"""\
@@ -153,10 +153,11 @@ def get_datalist(data, listname):
153153

154154

155155
def identifier_index(id_list, id_type):
156-
found_list = list((id["Type"] == id_type for id in id_list))
157-
if any(found_list):
158-
return found_list.index(True)
159-
return -1
156+
id_type_list = [id["Type"] for id in id_list]
157+
try:
158+
return id_type_list.index(id_type)
159+
except ValueError:
160+
return -1
160161

161162

162163
def identifier_matches(id_list, id_type, regex_string):
@@ -225,33 +226,36 @@ def main(args):
225226

226227
co_groups = get_osg_co_groups()["CoGroups"]
227228
highest_osggid = 0
229+
projects_to_assign_identifiers = []
228230

229231
for group in co_groups:
230232
gid = group["Id"]
231233
identifier_data = get_co_group_identifiers(gid)
232-
234+
233235
if identifier_data:
234236
identifier_list = identifier_data["Identifiers"]
235237

236238
project_id_index = identifier_index(identifier_list, "ospoolproject")
237239
if project_id_index != -1:
238-
project_id = identifier_list[project_id_index]["Identifier"]
239-
is_project = (re.compile(OSPOOL_PATTERN_STR + "*").match(project_id) is not None)
240+
project_id = str(identifier_list[project_id_index]["Identifier"])
241+
is_project = re.compile(OSPOOL_PROJECT_PREFIX_STR + "*").match(project_id) is not None
240242
else:
241243
is_project = False
242244

243245
osggid_index = identifier_index(identifier_list, "osggid")
244246
if osggid_index != -1:
245247
highest_osggid = max(highest_osggid, int(identifier_list[osggid_index]["Identifier"]))
246248
elif is_project is True:
247-
# for each, set a 'OSG GID' starting from 200000 and a 'OSG Group Name' that is the group name
248-
osggid_to_assign = max(highest_osggid + 1, options.project_gid_startval)
249-
highest_osggid = osggid_to_assign
250-
add_identifier_to_group(gid, type="osggid", identifier_name=osggid_to_assign)
251-
252-
project_name = project_id.removeprefix(OSPOOL_PATTERN_STR).lower()
253-
add_identifier_to_group(gid, type="osggroup", identifier_name=project_name)
254-
print(f"project {project_id}: added osggid {osggid_to_assign} and osg project name {project_name}")
249+
project_name = project_id.replace(OSPOOL_PROJECT_PREFIX_STR, "", 1).lower()
250+
projects_to_assign_identifiers.append(tuple([gid, project_name]))
251+
252+
for gid, project_name in projects_to_assign_identifiers:
253+
# for each, set a 'OSG GID' starting from 200000 and a 'OSG Group Name' that is the group name
254+
osggid_to_assign = max(highest_osggid + 1, options.project_gid_startval)
255+
highest_osggid = osggid_to_assign
256+
add_identifier_to_group(gid, type="osggid", identifier_name=osggid_to_assign)
257+
add_identifier_to_group(gid, type="osggroup", identifier_name=project_name)
258+
print(f"project {project_name}: added osggid {osggid_to_assign} and osg project name {project_name}")
255259

256260

257261
if __name__ == "__main__":

0 commit comments

Comments
 (0)