Skip to content

Commit

Permalink
fix: improve file investigation results (#7376)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks committed May 6, 2024
1 parent 000e6b7 commit bd25bc6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
6 changes: 5 additions & 1 deletion ietf/doc/templatetags/ietf_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
)
Expand Down
10 changes: 7 additions & 3 deletions ietf/doc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
30 changes: 27 additions & 3 deletions ietf/templates/doc/investigate.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,24 @@ <h2>These can be authenticated</h2>
<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>
Expand All @@ -53,7 +65,13 @@ <h2>These are in the archive, but cannot be authenticated</h2>
{% 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>
Expand All @@ -77,7 +95,13 @@ <h2>These are unexpected and we do not know what their origin is. These cannot b
{% 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 %}
Expand Down

0 comments on commit bd25bc6

Please sign in to comment.