qvm-template-gui: change date format to '%d %b %Y'

Make it always include month as a word, to less overwhelm the user with
a table full of numbers.
This commit is contained in:
Marek Marczykowski-Górecki 2021-04-03 17:19:05 +02:00
parent 099bbe99aa
commit 6c9514c034
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -1,5 +1,6 @@
import asyncio import asyncio
import collections import collections
from datetime import datetime
import itertools import itertools
import json import json
import os import os
@ -17,6 +18,9 @@ from . import utils
BASE_CMD = ['qvm-template', '--enablerepo=*', '--yes'] BASE_CMD = ['qvm-template', '--enablerepo=*', '--yes']
# singleton for "no date"
ZERO_DATE = datetime.utcfromtimestamp(0)
# pylint: disable=too-few-public-methods,inherit-non-class # pylint: disable=too-few-public-methods,inherit-non-class
class Template(typing.NamedTuple): class Template(typing.NamedTuple):
status: str status: str
@ -24,8 +28,8 @@ class Template(typing.NamedTuple):
evr: str evr: str
reponame: str reponame: str
size: int size: int
buildtime: str buildtime: datetime
installtime: str installtime: typing.Optional[datetime]
#licence: str #licence: str
#url: str #url: str
#summary: str #summary: str
@ -49,14 +53,20 @@ class Template(typing.NamedTuple):
@staticmethod @staticmethod
def build(status, entry): def build(status, entry):
cli_format = '%Y-%m-%d %H:%M:%S'
buildtime = datetime.strptime(entry['buildtime'], cli_format)
if entry['installtime']:
installtime = datetime.strptime(entry['installtime'], cli_format)
else:
installtime = ZERO_DATE
return Template( return Template(
status, status,
entry['name'], entry['name'],
'%s:%s-%s' % (entry['epoch'], entry['version'], entry['release']), '%s:%s-%s' % (entry['epoch'], entry['version'], entry['release']),
entry['reponame'], entry['reponame'],
int(entry['size']) // 1000000, int(entry['size']) // 1000000,
entry['buildtime'], buildtime,
entry['installtime'], installtime,
#entry['license'], #entry['license'],
#entry['url'], #entry['url'],
entry['description'], entry['description'],
@ -159,15 +169,20 @@ class TemplateModel(PyQt5.QtCore.QAbstractItemModel):
def data(self, index, role=PyQt5.QtCore.Qt.DisplayRole): def data(self, index, role=PyQt5.QtCore.Qt.DisplayRole):
if index.isValid(): if index.isValid():
data = self.children[index.row()][index.column()]
if role == PyQt5.QtCore.Qt.DisplayRole: if role == PyQt5.QtCore.Qt.DisplayRole:
return self.children[index.row()][index.column()] if data is ZERO_DATE:
return ''
if isinstance(data, datetime):
return data.strftime('%d %b %Y')
return data
if role == PyQt5.QtCore.Qt.FontRole: if role == PyQt5.QtCore.Qt.FontRole:
font = PyQt5.QtGui.QFont() font = PyQt5.QtGui.QFont()
tpl = self.children[index.row()] tpl = self.children[index.row()]
font.setBold(tpl.status != tpl.default_status) font.setBold(tpl.status != tpl.default_status)
return font return font
if role == PyQt5.QtCore.Qt.TextAlignmentRole: if role == PyQt5.QtCore.Qt.TextAlignmentRole:
if isinstance(self.children[index.row()][index.column()], int): if isinstance(data, int):
return PyQt5.QtCore.Qt.AlignRight return PyQt5.QtCore.Qt.AlignRight
return PyQt5.QtCore.Qt.AlignLeft return PyQt5.QtCore.Qt.AlignLeft
return None return None