Skip to content

Commit

Permalink
Be consistent about naming the ContactsData parameter "contacts_data"
Browse files Browse the repository at this point in the history
  • Loading branch information
matyasselmeci committed May 20, 2024
1 parent 3b2bd3e commit e0b1f43
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ def homepage():

@app.route('/map/iframe')
def map():
rgsummary = global_data.get_topology().get_resource_summary(contacts=None)
rgsummary = global_data.get_topology().get_resource_summary(contacts_data=None)

return _fix_unicode(render_template('iframe.html.j2', resourcegroups=rgsummary["ResourceSummary"]["ResourceGroup"]))

@app.route('/api/resource_group_summary')
def resource_summary():
data = global_data.get_topology().get_resource_summary(contacts=None)["ResourceSummary"]["ResourceGroup"]
data = global_data.get_topology().get_resource_summary(contacts_data=None)["ResourceSummary"]["ResourceGroup"]

return Response(
to_json_bytes(simplify_attr_list(data, namekey='GroupName', del_name=False)),
Expand Down Expand Up @@ -358,7 +358,7 @@ def miscresource_json():
"Site": rg.site.name,
"Facility": rg.site.facility.name,
"ResourceGroup": rg.name,
**resource.get_tree(contacts=contacts_)
**resource.get_tree(contacts_data=contacts_)
}

return Response(to_json_bytes(resources), mimetype='application/json')
Expand Down Expand Up @@ -1098,13 +1098,13 @@ def filter_value(filter_key):
return filters


def _get_xml_or_fail(getter_function, contacts_, args):
def _get_xml_or_fail(getter_function, contacts_data, args):
try:
filters = get_filters_from_args(args)
except InvalidArgumentsError as e:
return Response("Invalid arguments: " + str(e), status=400)
return Response(
to_xml_bytes(getter_function(contacts_, _get_authorized(), filters)),
to_xml_bytes(getter_function(contacts_data, _get_authorized(), filters)),
mimetype="text/xml"
)

Expand Down
4 changes: 2 additions & 2 deletions src/webapp/rg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def get_rgsummary_rgdowntime(indir, contacts_file=None, authorized=False, strict
topology = get_topology(indir, strict=strict)
filters = Filters()
filters.past_days = -1
return topology.get_resource_summary(contacts=contacts_data, authorized=authorized, filters=filters), \
topology.get_downtimes(contacts=contacts_data, authorized=authorized, filters=filters)
return topology.get_resource_summary(contacts_data=contacts_data, authorized=authorized, filters=filters), \
topology.get_downtimes(contacts_data=contacts_data, authorized=authorized, filters=filters)


def get_topology(indir="../topology", strict=False):
Expand Down
30 changes: 15 additions & 15 deletions src/webapp/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def get_stashcache_files(self, global_data, legacy):

return stashcache_files

def get_tree(self, contacts: Optional[ContactsData], authorized=False, filters: Filters = None) -> Optional[OrderedDict]:
def get_tree(self, contacts_data: Optional[ContactsData], authorized=False, filters: Filters = None) -> Optional[OrderedDict]:
if filters is None:
filters = Filters()

Expand Down Expand Up @@ -246,7 +246,7 @@ def get_tree(self, contacts: Optional[ContactsData], authorized=False, filters:
if "FQDNAliases" in self.data:
new_res["FQDNAliases"] = {"FQDNAlias": self.data["FQDNAliases"]}
if not is_null(self.data, "ContactLists"):
new_res["ContactLists"] = self._expand_contactlists(self.data["ContactLists"], authorized, contacts=contacts)
new_res["ContactLists"] = self._expand_contactlists(self.data["ContactLists"], authorized, contacts_data=contacts_data)
new_res["Name"] = self.name
if "WLCGInformation" in self.data and isinstance(self.data["WLCGInformation"], dict):
new_res["WLCGInformation"] = self._expand_wlcginformation(self.data["WLCGInformation"])
Expand Down Expand Up @@ -324,15 +324,15 @@ def _get_charturl(ownership):
("ChartURL", _get_charturl(voownership.items()))
])

def _expand_contactlists(self, contactlists: Dict, authorized: bool, contacts: Optional[ContactsData]) -> Dict:
def _expand_contactlists(self, contactlists: Dict, authorized: bool, contacts_data: Optional[ContactsData]) -> Dict:
"""Return the data structure for an expanded ContactLists for a single Resource."""
new_contactlists = []
for contact_type, contact_data in contactlists.items():
contact_data = expand_attr_list(contact_data, "ContactRank", ["Name", "ID", "ContactRank"], ignore_missing=True)
for contact in contact_data:
for contact_type, contact_info in contactlists.items():
contact_info = expand_attr_list(contact_info, "ContactRank", ["Name", "ID", "ContactRank"], ignore_missing=True)
for contact in contact_info:
contact_id = contact.pop("ID", None) # ID is for internal use - don't put it in the results
if contacts and contact_id in contacts.users_by_id:
user = contacts.users_by_id[contact_id] # type: User
if contacts_data and contact_id in contacts_data.users_by_id:
user = contacts_data.users_by_id[contact_id] # type: User
contact["CILogonID"] = user.cilogon_id
if authorized:
contact["Email"] = user.email
Expand All @@ -343,7 +343,7 @@ def _expand_contactlists(self, contactlists: Dict, authorized: bool, contacts: O
contact["DN"] = dns[0]
contact.move_to_end("ContactRank", last=True)
new_contactlists.append(
OrderedDict([("ContactType", contact_type), ("Contacts", {"Contact": contact_data})]))
OrderedDict([("ContactType", contact_type), ("Contacts", {"Contact": contact_info})]))
return {"ContactList": new_contactlists}

@staticmethod
Expand Down Expand Up @@ -396,7 +396,7 @@ def resources(self):
def itb(self):
return not self.production

def get_tree(self, contacts: Optional[ContactsData], authorized=False, filters: Filters = None) -> Optional[OrderedDict]:
def get_tree(self, contacts_data: Optional[ContactsData], authorized=False, filters: Filters = None) -> Optional[OrderedDict]:
if filters is None:
filters = Filters()
for filter_list, attribute in [(filters.facility_id, self.site.facility.id),
Expand All @@ -412,7 +412,7 @@ def get_tree(self, contacts: Optional[ContactsData], authorized=False, filters:
filtered_resources = []
for res in self.resources:
try:
tree = res.get_tree(contacts, authorized, filters)
tree = res.get_tree(contacts_data, authorized, filters)
if tree:
filtered_resources.append(tree)
except (AttributeError, KeyError, ValueError) as err:
Expand Down Expand Up @@ -690,24 +690,24 @@ def get_resource_group_list(self):
"""
return self.rgs.values()

def get_resource_summary(self, contacts: Optional[ContactsData], authorized=False, filters: Filters = None) -> Dict:
def get_resource_summary(self, contacts_data: Optional[ContactsData], authorized=False, filters: Filters = None) -> Dict:
if filters is None:
filters = Filters()
rglist = []
for rgkey in sorted(self.rgs.keys(), key=lambda x: x[1].lower()):
rgval = self.rgs[rgkey]
assert isinstance(rgval, ResourceGroup)
rgtree = rgval.get_tree(contacts, authorized, filters)
rgtree = rgval.get_tree(contacts_data, authorized, filters)
if rgtree:
rglist.append(rgtree)
return {"ResourceSummary":
{"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:schemaLocation": RGSUMMARY_SCHEMA_URL,
"ResourceGroup": rglist}}

def get_downtimes(self, contacts: Optional[ContactsData], authorized=False, filters: Filters = None) -> Dict:
def get_downtimes(self, contacts_data: Optional[ContactsData], authorized=False, filters: Filters = None) -> Dict:
_ = authorized
_ = contacts
_ = contacts_data
if filters is None:
filters = Filters()

Expand Down
2 changes: 1 addition & 1 deletion src/webapp/vo_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def main(argv):
if args.contacts:
contacts_data = get_contacts_data(args.contacts)
xml = to_xml(
get_vos_data(args.indir, strict=args.strict).get_tree(contacts=contacts_data, authorized=True))
get_vos_data(args.indir, strict=args.strict).get_tree(contacts_data=contacts_data, authorized=True))
if args.outfile:
with open(args.outfile, "w") as fh:
fh.write(xml)
Expand Down
4 changes: 2 additions & 2 deletions src/webapp/vos_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def get_expansion(self, contacts_data: Optional[ContactsData], authorized=False,

return expanded_vo_list

def get_tree(self, contacts: Optional[ContactsData], authorized=False, filters: Filters = None) -> Dict:
def get_tree(self, contacts_data: Optional[ContactsData], authorized=False, filters: Filters = None) -> Dict:
if not filters:
filters = Filters()
expanded_vo_list = []
for vo_name in sorted(self.vos.keys(), key=lambda x: x.lower()):
try:
expanded_vo_data = self._expand_vo(vo_name, contacts_data=contacts, authorized=authorized,
expanded_vo_data = self._expand_vo(vo_name, contacts_data=contacts_data, authorized=authorized,
filters=filters)
if expanded_vo_data:
if 'DataFederations' in expanded_vo_data:
Expand Down

0 comments on commit e0b1f43

Please sign in to comment.