|
20 | 20 | POST = "POST" |
21 | 21 | DELETE = "DELETE" |
22 | 22 |
|
23 | | -OSPOOL_PATTERN_STR = "Yes-" |
| 23 | +OSPOOL_PROJECT_PREFIX_STR = "Yes-" |
24 | 24 | PROJECT_GIDS_START = 200000 |
25 | 25 |
|
26 | 26 | _usage = f"""\ |
@@ -153,10 +153,11 @@ def get_datalist(data, listname): |
153 | 153 |
|
154 | 154 |
|
155 | 155 | 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 |
160 | 161 |
|
161 | 162 |
|
162 | 163 | def identifier_matches(id_list, id_type, regex_string): |
@@ -225,33 +226,36 @@ def main(args): |
225 | 226 |
|
226 | 227 | co_groups = get_osg_co_groups()["CoGroups"] |
227 | 228 | highest_osggid = 0 |
| 229 | + projects_to_assign_identifiers = [] |
228 | 230 |
|
229 | 231 | for group in co_groups: |
230 | 232 | gid = group["Id"] |
231 | 233 | identifier_data = get_co_group_identifiers(gid) |
232 | | - |
| 234 | + |
233 | 235 | if identifier_data: |
234 | 236 | identifier_list = identifier_data["Identifiers"] |
235 | 237 |
|
236 | 238 | project_id_index = identifier_index(identifier_list, "ospoolproject") |
237 | 239 | 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 |
240 | 242 | else: |
241 | 243 | is_project = False |
242 | 244 |
|
243 | 245 | osggid_index = identifier_index(identifier_list, "osggid") |
244 | 246 | if osggid_index != -1: |
245 | 247 | highest_osggid = max(highest_osggid, int(identifier_list[osggid_index]["Identifier"])) |
246 | 248 | 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}") |
255 | 259 |
|
256 | 260 |
|
257 | 261 | if __name__ == "__main__": |
|
0 commit comments