Răsfoiți Sursa

qvm-template: Fix date formats to "%Y-%m-%d %H:%M:%S"

WillyPillow 3 ani în urmă
părinte
comite
89895038b5

+ 6 - 9
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
 ------

+ 4 - 4
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'),

+ 10 - 7
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({