Skip to content

Commit

Permalink
YDA-5956: remove unnecessary try-except blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Oct 8, 2024
1 parent 02fef14 commit 4536c69
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,13 @@ def getGroupsData(ctx):
attr = row[1]
value = row[2]

# Create/update group with this information.
try:
group = groups[name]
except Exception:
group = {
"name": name,
"managers": [],
"members": [],
"read": [],
"invited": []
}
groups[name] = group
group = groups.setdefault(name, {
"name": name,
"managers": [],
"members": [],
"read": [],
"invited": []
})

if attr in ["schema_id", "data_classification", "category", "subcategory"]:
group[attr] = value
Expand Down Expand Up @@ -95,26 +90,17 @@ def getGroupsData(ctx):
if name.startswith("read-"):
# Match read-* group with research-* or initial-* group.
name = name[5:]
try:
# Attempt to add to read list of research group.
group = groups["research-" + name]
group["read"].append(user)
except Exception:
try:
# Attempt to add to read list of initial group.
group = groups["initial-" + name]
for prefix in ("research-", "initial-"):
group = groups.get(prefix + name)
if group:
group["read"].append(user)
except Exception:
pass
break
elif not name.startswith("vault-"):
try:
# Ordinary group.
group = groups[name]
group = groups.get(name)
if group:
group["members"].append(user)
except KeyError:
pass

# Third query: obtain list of invited SRAM users
# Third query: obtain list of invited SRAM users.
if config.enable_sram:
iter = genquery.row_iterator(
"META_USER_ATTR_VALUE, USER_NAME, USER_ZONE",
Expand All @@ -124,11 +110,9 @@ def getGroupsData(ctx):
for row in iter:
name = row[0]
user = row[1] + "#" + row[2]
try:
group = groups[name]
group = groups.get(name)
if group:
group["invited"].append(user)
except KeyError:
pass

return groups.values()

Expand Down

0 comments on commit 4536c69

Please sign in to comment.