From 89895038b5c301c5eefa4a2b5ed83e7df534b74d Mon Sep 17 00:00:00 2001 From: WillyPillow Date: Sun, 6 Sep 2020 23:57:42 +0800 Subject: [PATCH] qvm-template: Fix date formats to "%Y-%m-%d %H:%M:%S" --- doc/manpages/qvm-template.rst | 15 ++++++--------- qubesadmin/tests/tools/qvm_template.py | 8 ++++---- qubesadmin/tools/qvm_template.py | 17 ++++++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/doc/manpages/qvm-template.rst b/doc/manpages/qvm-template.rst index cbc8d25..406f237 100644 --- a/doc/manpages/qvm-template.rst +++ b/doc/manpages/qvm-template.rst @@ -252,9 +252,8 @@ Options Where ``STATUS`` can be one of ``"installed"``, ``"available"``, ``"extra"``, or ``"upgradable"``. - The fields ``buildtime`` and ``installtime`` are in ISO 8601 format. - For example, one can parse them in Python with - ``datetime.fromisoformat()``. + The fields ``buildtime`` and ``installtime`` are in ``%Y-%m-%d + %H:%M:%S`` format in UTC. The field ``{evr}`` contains version information in the form of ``{epoch}:{version}-{release}``. @@ -313,9 +312,8 @@ Options Where ``{status}`` can be one of ``installed``, ``available``, ``extra``, or ``upgradable``. - The fields ``{buildtime}`` and ``{installtime}`` are in ISO 8601 format. - For example, one can parse them in Python with - ``datetime.fromisoformat()``. + The fields ``buildtime`` and ``installtime`` are in ``%Y-%m-%d + %H:%M:%S`` format in UTC. Newlines in the ``{description}`` field are replaced with pipe characters (``|``) for easier processing. @@ -353,9 +351,8 @@ Options Where ``STATUS`` can be one of ``"installed"``, ``"available"``, ``"extra"``, or ``"upgradable"``. - The fields ``buildtime`` and ``installtime`` are in ISO 8601 format. - For example, one can parse them in Python using - `datetime.fromisoformat()`. + The fields ``buildtime`` and ``installtime`` are in ``%Y-%m-%d + %H:%M:%S`` format in UTC. search ------ diff --git a/qubesadmin/tests/tools/qvm_template.py b/qubesadmin/tests/tools/qvm_template.py index 99691a5..3ffabfa 100644 --- a/qubesadmin/tests/tools/qvm_template.py +++ b/qubesadmin/tests/tools/qvm_template.py @@ -149,8 +149,8 @@ class TC_00_qvm_template(qubesadmin.tests.QubesTestCase): mock_rename, mock_remove): self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = b'0\0' - build_time = '2020-09-01 14:30:00+00:00' # 1598970600 - install_time = '2020-09-01 15:30:00.508230+00:00' + build_time = '2020-09-01 14:30:00' # 1598970600 + install_time = '2020-09-01 15:30:00' for key, val in [ ('name', 'test-vm'), ('epoch', '2'), @@ -280,8 +280,8 @@ class TC_00_qvm_template(qubesadmin.tests.QubesTestCase): mock_rename, mock_remove): self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = b'0\0' - build_time = '2020-09-01 14:30:00+00:00' # 1598970600 - install_time = '2020-09-01 15:30:00.508230+00:00' + build_time = '2020-09-01 14:30:00' # 1598970600 + install_time = '2020-09-01 15:30:00' for key, val in [ ('name', 'test-vm'), ('epoch', '2'), diff --git a/qubesadmin/tools/qvm_template.py b/qubesadmin/tools/qvm_template.py index fcc3fdc..e3876cd 100644 --- a/qubesadmin/tools/qvm_template.py +++ b/qubesadmin/tools/qvm_template.py @@ -35,6 +35,7 @@ PACKAGE_NAME_PREFIX = 'qubes-template-' CACHE_DIR = os.path.join(xdg.BaseDirectory.xdg_cache_home, 'qvm-template') UNVERIFIED_SUFFIX = '.unverified' LOCK_FILE = '/var/tmp/qvm-template.lck' +DATE_FMT = '%Y-%m-%d %H:%M:%S' def qubes_release() -> str: """Return the Qubes release.""" @@ -287,7 +288,7 @@ def query_local(vm: qubesadmin.vm.QubesVM) -> Template: vm.features['template-release'], vm.features['template-reponame'], vm.get_disk_utilization(), - datetime.datetime.fromisoformat(vm.features['template-buildtime']), + datetime.datetime.strptime(vm.features['template-buildtime'], DATE_FMT), vm.features['template-license'], vm.features['template-url'], vm.features['template-summary'], @@ -922,11 +923,13 @@ def install( package_hdr[rpm.RPMTAG_RELEASE] tpl.features['template-reponame'] = reponame tpl.features['template-buildtime'] = \ - str(datetime.datetime.fromtimestamp( - int(package_hdr[rpm.RPMTAG_BUILDTIME]), - tz=datetime.timezone.utc)) + datetime.datetime.fromtimestamp( + int(package_hdr[rpm.RPMTAG_BUILDTIME]), + tz=datetime.timezone.utc) \ + .strftime(DATE_FMT) tpl.features['template-installtime'] = \ - str(datetime.datetime.today(tz=datetime.timezone.utc)) + datetime.datetime.today( + tz=datetime.timezone.utc).strftime(DATE_FMT) tpl.features['template-license'] = \ package_hdr[rpm.RPMTAG_LICENSE] tpl.features['template-url'] = \ @@ -1011,8 +1014,8 @@ def list_templates(args: argparse.Namespace, name, epoch, version, release, reponame, dlsize, \ buildtime, licence, url, summary, description = data dlsize = str(dlsize) - buildtime = str(buildtime) - install_time = str(install_time) if install_time else '' + buildtime = buildtime.strftime(DATE_FMT) + install_time = install_time.strftime(DATE_FMT) if install_time else '' if replace_newline: description = description.replace('\n', '|') output.append({