Skip to content

Commit

Permalink
YDA-6162: refactor some Python 2 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Feb 10, 2025
1 parent 12c9280 commit 78348d3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 35 deletions.
32 changes: 9 additions & 23 deletions groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Functions for group management and group queries."""

__copyright__ = 'Copyright (c) 2018-2024, Utrecht University'
__copyright__ = 'Copyright (c) 2018-2025, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import time
Expand Down Expand Up @@ -434,31 +434,17 @@ def internal_api_group_data(ctx: rule.Context) -> Dict:
'members': members
}

# order the resulting group_hierarchy and put System in as first category
cat_list = []
system_present = False
for cat in group_hierarchy:
if cat != 'System':
cat_list.append(cat)
else:
system_present = True
cat_list.sort()
if system_present:
cat_list.insert(0, 'System')

new_group_hierarchy = OrderedDict()
for cat in cat_list:
new_group_hierarchy[cat] = group_hierarchy[cat]

# Python 3 solution:
# Put System category as first category.
# if "System" in group_hierarchy:
# group_hierarchy.move_to_end("System", last=False)
# Order the group hierarchy and put System in as first category.
group_hierarchy.sort()
try:
group_hierarchy.move_to_end("System", last=False)
except KeyError:
pass

# Per category the group data has to be ordered by subcat asc as well
subcat_ordered_group_hierarchy = OrderedDict()
for cat in new_group_hierarchy:
subcats_data = new_group_hierarchy[cat]
for cat in group_hierarchy:
subcats_data = group_hierarchy[cat]
# order on subcat level per category
subcat_ordered_group_hierarchy[cat] = OrderedDict(sorted(subcats_data.items(), key=lambda x: x[0]))

Expand Down
4 changes: 1 addition & 3 deletions json_datacite.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Functions for transforming Yoda JSON to DataCite 4.4 JSON."""

__copyright__ = 'Copyright (c) 2019-2024, Utrecht University'
__copyright__ = 'Copyright (c) 2019-2025, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

from typing import Dict, List
Expand Down Expand Up @@ -299,8 +299,6 @@ def get_dates(combi: Dict) -> List:
"""Return list of dates in DataCite format."""

# Format last modified date for DataCite: https://support.datacite.org/docs/schema-optional-properties-v41#8-date
# Python 3: https://docs.python.org/3/library/datetime.html#datetime.date.fromisoformat
# last_modified_date = date.fromisoformat(last_modified_date)
last_modified_date = combi.get('System', {}).get('Last_Modified_Date')
last_modified_date = parser.parse(last_modified_date)
last_modified_date = last_modified_date.strftime('%Y-%m-%dT%H:%M:%S%z')
Expand Down
6 changes: 1 addition & 5 deletions json_landing_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Functions for transforming JSON to landingpage HTML."""

__copyright__ = 'Copyright (c) 2019-2024, Utrecht University'
__copyright__ = 'Copyright (c) 2019-2025, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

from datetime import datetime
Expand Down Expand Up @@ -198,12 +198,8 @@ def json_landing_page_create_json_landing_page(ctx: rule.Context,
license_uri = json_data["System"].get("License_URI", "")

# Format last modified and publication date.
# Python 3: https://docs.python.org/3/library/datetime.html#datetime.date.fromisoformat
# last_modified_date = date.fromisoformat(json_data['System']['Last_Modified_Date'])
last_modified_date_time = parser.parse(json_data["System"]["Last_Modified_Date"])
last_modified_date = last_modified_date_time.strftime("%Y-%m-%d %H:%M:%S%z")
# Python 3: https://docs.python.org/3/library/datetime.html#datetime.date.fromisoformat
# publication_date = date.fromisoformat(json_data['System']['Publication_Date'])
publication_date_time = parser.parse(json_data["System"]["Publication_Date"])
publication_date = publication_date_time.strftime("%Y-%m-%d %H:%M:%S%z")

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jsonschema==4.23.0
pathvalidate==0.29.1
requests_cache==0.5.2
irods-avu-json==2.2.0
python-dateutil==2.7.0
python-dateutil==2.9.0.post0
python-magic==0.4.27
deepdiff==8.0.1
persist-queue==0.8.1
Expand Down
4 changes: 1 addition & 3 deletions vault.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Functions to copy packages to the vault and manage permissions of vault packages."""

__copyright__ = 'Copyright (c) 2019-2024, Utrecht University'
__copyright__ = 'Copyright (c) 2019-2025, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import os
Expand Down Expand Up @@ -462,8 +462,6 @@ def api_vault_system_metadata(ctx: rule.Context, coll: str) -> api.Result:
)

for row in iter:
# Python 3: https://docs.python.org/3/library/datetime.html#datetime.date.fromisoformat
# modified_date = date.fromisoformat(row[0])
modified_date = parser.parse(row[0])
modified_date_time = modified_date.strftime('%Y-%m-%d %H:%M:%S%z')
system_metadata["Modified date"] = "{}".format(modified_date_time)
Expand Down

0 comments on commit 78348d3

Please sign in to comment.