Skip to content

Commit f91694f

Browse files
committed
html-report.py: use datetime module for timestamps
1 parent 13efa9a commit f91694f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

html-report.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
# Generates an HTML report of the release status of all
1010
# components in the SciJava BOM (org.scijava:pom-scijava).
1111

12-
import logging, re, subprocess
12+
import datetime, logging, re, subprocess
1313

1414
# -- Constants --
1515

1616
checkMark = "✔"
1717
xMark = "✕"
1818
repoBase = "https://maven.scijava.org"
19+
datetime0 = datetime.datetime(datetime.MINYEAR, 1, 1, 0, 0, 0)
1920

2021
# -- Data --
2122

@@ -68,16 +69,22 @@ def project_url(ga):
6869

6970
return ''
7071

72+
def ts2dt(timestamp):
73+
"""
74+
Converts timestamp string of the form YYYYMMDDhhmmss to a datetime object.
75+
"""
76+
if not timestamp: return datetime0
77+
m = re.match('(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)', timestamp)
78+
return datetime.datetime(*map(int, m.groups())) if m else datetime0
79+
7180
def version_timestamps(g, a, v):
7281
"""
7382
Gets timestamps for the last time a component was released.
7483
Returns a (releaseTimestamp, lastDeployed) pair.
7584
"""
7685
gav, releaseTimestamp, lastDeployed = subprocess.check_output(['./version-timestamps.sh', f'{g}:{a}:{v}']).decode().strip('\n\r').split(' ')
7786
assert gav == f'{g}:{a}:{v}'
78-
releaseTimestamp = int(releaseTimestamp) if releaseTimestamp else 0
79-
lastDeployed = int(lastDeployed) if lastDeployed else 0
80-
return releaseTimestamp, lastDeployed
87+
return ts2dt(releaseTimestamp), ts2dt(lastDeployed)
8188

8289
def badge(url):
8390
slug = None
@@ -101,7 +108,7 @@ def timestamp_override(g, a):
101108
such as that particular G:A:V not be present in the remote repository
102109
for any reason (in which case, this function returns 0).
103110
"""
104-
return int(timestamps.get(f'{g}:{a}', 0))
111+
return ts2dt(timestamps.get(f'{g}:{a}', None))
105112

106113
def release_link(g, a, v):
107114
return f"<a href=\"{repoBase}/#nexus-search;gav~{g}~{a}~{v}~~\">{v}</a>"
@@ -166,7 +173,7 @@ def release_link(g, a, v):
166173
lastVetted = max(releaseTimestamp, timestampOverride)
167174

168175
# Compute time difference; >24 hours means a new release is needed.
169-
if lastUpdated - lastVetted > 1000000:
176+
if lastUpdated - lastVetted > datetime.timedelta(days=1):
170177
# A SNAPSHOT was deployed more recently than the newest release.
171178
releaseStatus = "release-needed"
172179
releaseOK = xMark
@@ -212,7 +219,7 @@ def release_link(g, a, v):
212219
elif lastVetted == timestampOverride:
213220
# Last vetted manually via timestamps.txt.
214221
print(f"<td class=\"overridden\">{lastVetted}</td>")
215-
elif timestampOverride == 0:
222+
elif timestampOverride == datetime0:
216223
# Last vetted automatically via release artifact; no timestamp override.
217224
print(f"<td>{lastVetted}</td>")
218225
else:

0 commit comments

Comments
 (0)