From 94f71d6f8fc7301dfd470ccf2fee27e078321a78 Mon Sep 17 00:00:00 2001 From: mjfernez Date: Sun, 13 Mar 2022 15:21:11 -0400 Subject: Pull changes from mjfer.net This commit adds the changes from the mjfer.net which enable using git as the file last update tracker --- view_functions.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'view_functions.py') diff --git a/view_functions.py b/view_functions.py index 3de8687..4163c2e 100644 --- a/view_functions.py +++ b/view_functions.py @@ -3,8 +3,8 @@ view_functions.py - defines functions called by views to display the correct dat about files and paths. """ import os -from time import ctime -from siteconfig import siteconfig +import subprocess +from siteconfig import siteconfig, config def default_context(): @@ -20,7 +20,18 @@ def default_context(): def file_last_modified(path): - return ctime(os.stat(path).st_mtime) + git_time = f"git log -n1 --pretty=%aD {path}".split() + try: + mod_time = subprocess.check_output( + git_time, cwd=config.BASE_DIR + ) + except: + # File is not in the git log, no biggie, just blank the date + return None + + # Git outputs in RFC2822 format + return mod_time.decode('ascii').strip() + def index_dir(path): """ -- cgit v1.2.3