fix: improve file investigation results (#7376)

This commit is contained in:
Robert Sparks 2024-05-06 08:45:36 -04:00 committed by GitHub
parent 000e6b7dca
commit bd25bc6034
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 7 deletions

View file

@ -906,13 +906,17 @@ def mtime(path):
"""Returns a datetime object representing mtime given a pathlib Path object"""
return datetime.datetime.fromtimestamp(path.stat().st_mtime).astimezone(ZoneInfo(settings.TIME_ZONE))
@register.filter
def mtime_is_epoch(path):
return path.stat().st_mtime == 0
@register.filter
def url_for_path(path):
"""Consructs a 'best' URL for web access to the given pathlib Path object.
Assumes that the path is into the Internet-Draft archive or the proceedings.
"""
if path.match(f"{settings.AGENDA_PATH}/**/*"):
if Path(settings.AGENDA_PATH) in path.parents:
return (
f"https://www.ietf.org/proceedings/{path.relative_to(settings.AGENDA_PATH)}"
)

View file

@ -1388,14 +1388,18 @@ def investigate_fragment(name_fragment):
can_verify = set()
for root in [settings.INTERNET_DRAFT_PATH, settings.INTERNET_DRAFT_ARCHIVE_DIR]:
can_verify.update(list(Path(root).glob(f"*{name_fragment}*")))
archive_verifiable_names = set([p.name for p in can_verify])
# Can also verify drafts in proceedings directories
can_verify.update(list(Path(settings.AGENDA_PATH).glob(f"**/*{name_fragment}*")))
# N.B. This reflects the assumption that the internet draft archive dir is in the
# a directory with other collections (at /a/ietfdata/draft/collections as this is written)
unverifiable_collections = set(
unverifiable_collections = set([
p for p in
Path(settings.INTERNET_DRAFT_ARCHIVE_DIR).parent.glob(f"**/*{name_fragment}*")
)
if p.name not in archive_verifiable_names
])
unverifiable_collections.difference_update(can_verify)
expected_names = set([p.name for p in can_verify.union(unverifiable_collections)])

View file

@ -23,12 +23,24 @@
<th scope="col" data-sort="name">Name</th>
<th scope="col" data-sort="modified">Last Modified On</th>
<th scope="col" data-sort="link">Link</th>
<th scope="col" data-sort="source">Source</th>
</tr>
</thead>
<tbody>
{% for path in results.can_verify %}
{% with url=path|url_for_path %}
<tr><td>{{path.name}}</td><td>{{path|mtime|date:"DATETIME_FORMAT"}}</td><td><a href="{{url}}">{{url}}</a></td></tr>
<tr>
<td>{{path.name}}</td>
<td>
{% if path|mtime_is_epoch %}
Timestamp has been lost (is Unix Epoch)
{% else %}
{{path|mtime|date:"DATETIME_FORMAT"}}
{% endif %}
</td>
<td><a href="{{url}}">{{url}}</a></td>
<td>{{path}}</td>
</tr>
{% endwith %}
{% endfor %}
</tbody>
@ -53,7 +65,13 @@
{% with url=path|url_for_path %}
<tr>
<td>{{path.name}}</td>
<td>{{path|mtime|date:"DATETIME_FORMAT"}}</td>
<td>
{% if path|mtime_is_epoch %}
Timestamp has been lost (is Unix Epoch)
{% else %}
{{path|mtime|date:"DATETIME_FORMAT"}}
{% endif %}
</td>
<td><a href="{{url}}">{{url}}</a></td>
<td>{{path}}</td>
</tr>
@ -77,7 +95,13 @@
{% with url=path|url_for_path %}
<tr>
<td>{{path.name}}</td>
<td>{{path|mtime|date:"DATETIME_FORMAT"}}</td>
<td>
{% if path|mtime_is_epoch %}
Timestamp has been lost (is Unix Epoch)
{% else %}
{{path|mtime|date:"DATETIME_FORMAT"}}
{% endif %}
</td>
<td><a href="{{url}}">{{url}}</a></td>
</tr>
{% endwith %}