From 6a6995c98a4568f2e4347b195c79094aa129772f Mon Sep 17 00:00:00 2001 From: Tomas Zigo <50632337+tmszi@users.noreply.github.com> Date: Mon, 10 Oct 2022 04:32:39 +0200 Subject: [PATCH] utils: fix date and time format retrieved from the module source dir (#2595) Same date and time format `"%A %b %d %H:%M:%S %Y"` (example Wednesday Oct 05 06:42:36 2022) inside manual page for all use cases: 1. Core modules compiled from Git repository, with date and time retrievied from the last commit. 2. Core modules compiled from tarball without Git repository and without applied official patch core_modules_with_last_commit.patch, with date and time retrievied from the module source directory. 3. Core modules compiled from tarball without Git repository and with applied official patch core_modules_with_last_commit.patch, with date and time retrievied from the core_modules_with_last_commit.json file. 4. Official addons with date and time retrievied from the last commit via GitHub REST API. 5. Unofficial addons with date and time retrievied from the module source directory. --- utils/mkhtml.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/utils/mkhtml.py b/utils/mkhtml.py index f39abbf168b..f7d9054dc16 100644 --- a/utils/mkhtml.py +++ b/utils/mkhtml.py @@ -26,7 +26,6 @@ import json import pathlib import subprocess -import time from html.parser import HTMLParser @@ -152,18 +151,22 @@ def download_git_commit(url, response_format, *args, **kwargs): ) -def get_default_git_log(src_dir): +def get_default_git_log(src_dir, datetime_format="%A %b %d %H:%M:%S %Y"): """Get default Git commit and commit date, when getting commit from local Git, local JSON file and remote GitHub REST API server wasn't successfull. :param str src_dir: addon source dir + :param str datetime_format: output commit datetime format + e.g. Sunday Jan 16 23:09:35 2022 :return dict: dict which store last commit and commnit date """ return { "commit": "unknown", - "date": time.ctime(os.path.getmtime(src_dir)), + "date": datetime.fromtimestamp(os.path.getmtime(src_dir)).strftime( + datetime_format + ), } @@ -266,7 +269,7 @@ def format_git_commit_date_from_rest_api( :param str commit_datetime: commit datetime :param str datetime_format: output commit datetime format - e.g. Sun Jan 16 23:09:35 2022 + e.g. Sunday Jan 16 23:09:35 2022 :return str: output formatted commit datetime """ @@ -283,7 +286,7 @@ def format_git_commit_date_from_local_git( :param str commit_datetime: commit datetime :param str datetime_format: output commit datetime format - e.g. Sun Jan 16 23:09:35 2022 + e.g. Sunday Jan 16 23:09:35 2022 :return str: output formatted commit datetime """