mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #552 from kir0ul/enh-human-readable-date
[enh] Human readable date
This commit is contained in:
commit
bf676c2fd8
6 changed files with 24 additions and 23 deletions
|
@ -36,6 +36,7 @@ import glob
|
|||
import pwd
|
||||
import grp
|
||||
from collections import OrderedDict
|
||||
import datetime
|
||||
|
||||
from moulinette import msignals, m18n, msettings
|
||||
from moulinette.core import MoulinetteError
|
||||
|
@ -80,6 +81,10 @@ def app_listlists():
|
|||
# Get the list
|
||||
appslist_list = _read_appslist_list()
|
||||
|
||||
for app in appslist_list:
|
||||
appslist_list[app]["lastUpdate"] = datetime.datetime.utcfromtimestamp(
|
||||
appslist_list[app].get("lastUpdate"))
|
||||
|
||||
return appslist_list
|
||||
|
||||
|
||||
|
@ -1755,8 +1760,7 @@ def _get_app_status(app_id, format_date=False):
|
|||
if not v:
|
||||
status[f] = '-'
|
||||
else:
|
||||
status[f] = time.strftime(m18n.n('format_datetime_short'),
|
||||
time.gmtime(v))
|
||||
status[f] = datetime.utcfromtimestamp(v)
|
||||
return status
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ import shutil
|
|||
import subprocess
|
||||
import csv
|
||||
import tempfile
|
||||
from datetime import datetime
|
||||
from glob import glob
|
||||
from collections import OrderedDict
|
||||
|
||||
|
@ -299,7 +300,7 @@ class BackupManager():
|
|||
(string) A backup name created from current date 'YYMMDD-HHMMSS'
|
||||
"""
|
||||
# FIXME: case where this name already exist
|
||||
return time.strftime('%Y%m%d-%H%M%S')
|
||||
return time.strftime('%Y%m%d-%H%M%S', time.gmtime())
|
||||
|
||||
def _init_work_dir(self):
|
||||
"""Initialize preparation directory
|
||||
|
@ -859,7 +860,7 @@ class RestoreManager():
|
|||
raise MoulinetteError(errno.EIO, m18n.n('backup_invalid_archive'))
|
||||
else:
|
||||
logger.debug("restoring from backup '%s' created on %s", self.name,
|
||||
time.ctime(self.info['created_at']))
|
||||
datetime.utcfromtimestamp(self.info['created_at']))
|
||||
|
||||
def _postinstall_if_needed(self):
|
||||
"""
|
||||
|
@ -2266,8 +2267,7 @@ def backup_info(name, with_details=False, human_readable=False):
|
|||
|
||||
result = {
|
||||
'path': archive_file,
|
||||
'created_at': time.strftime(m18n.n('format_datetime_short'),
|
||||
time.gmtime(info['created_at'])),
|
||||
'created_at': datetime.utcfromtimestamp(info['created_at']),
|
||||
'description': info['description'],
|
||||
'size': size,
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ def _certificate_install_selfsigned(domain_list, force=False):
|
|||
args={'force': force})
|
||||
|
||||
# Paths of files and folder we'll need
|
||||
date_tag = datetime.now().strftime("%Y%m%d.%H%M%S")
|
||||
date_tag = datetime.utcnow().strftime("%Y%m%d.%H%M%S")
|
||||
new_cert_folder = "%s/%s-history/%s-selfsigned" % (
|
||||
CERT_FOLDER, domain, date_tag)
|
||||
|
||||
|
@ -587,7 +587,7 @@ def _fetch_and_enable_new_certificate(domain, staging=False, no_checks=False):
|
|||
logger.debug("Saving the key and signed certificate...")
|
||||
|
||||
# Create corresponding directory
|
||||
date_tag = datetime.now().strftime("%Y%m%d.%H%M%S")
|
||||
date_tag = datetime.utcnow().strftime("%Y%m%d.%H%M%S")
|
||||
|
||||
if staging:
|
||||
folder_flag = "staging"
|
||||
|
@ -674,7 +674,7 @@ def _get_status(domain):
|
|||
cert_subject = cert.get_subject().CN
|
||||
cert_issuer = cert.get_issuer().CN
|
||||
valid_up_to = datetime.strptime(cert.get_notAfter(), "%Y%m%d%H%M%SZ")
|
||||
days_remaining = (valid_up_to - datetime.now()).days
|
||||
days_remaining = (valid_up_to - datetime.utcnow()).days
|
||||
|
||||
if cert_issuer == _name_self_CA():
|
||||
CA_type = {
|
||||
|
@ -819,7 +819,7 @@ def _backup_current_cert(domain):
|
|||
|
||||
cert_folder_domain = os.path.join(CERT_FOLDER, domain)
|
||||
|
||||
date_tag = datetime.now().strftime("%Y%m%d.%H%M%S")
|
||||
date_tag = datetime.utcnow().strftime("%Y%m%d.%H%M%S")
|
||||
backup_folder = "%s-backups/%s" % (cert_folder_domain, date_tag)
|
||||
|
||||
shutil.copytree(cert_folder_domain, backup_folder)
|
||||
|
|
|
@ -316,7 +316,7 @@ class OperationLogger(object):
|
|||
"""
|
||||
|
||||
if self.started_at is None:
|
||||
self.started_at = datetime.now()
|
||||
self.started_at = datetime.utcnow()
|
||||
self.flush()
|
||||
self._register_log()
|
||||
|
||||
|
@ -408,7 +408,7 @@ class OperationLogger(object):
|
|||
return
|
||||
if error is not None and not isinstance(error, basestring):
|
||||
error = str(error)
|
||||
self.ended_at = datetime.now()
|
||||
self.ended_at = datetime.utcnow()
|
||||
self._error = error
|
||||
self._success = error is None
|
||||
if self.logger is not None:
|
||||
|
|
|
@ -248,10 +248,7 @@ def service_status(names=[]):
|
|||
'status': "unknown",
|
||||
'loaded': "unknown",
|
||||
'active': "unknown",
|
||||
'active_at': {
|
||||
"timestamp": "unknown",
|
||||
"human": "unknown",
|
||||
},
|
||||
'active_at': "unknown",
|
||||
'description': "Error: failed to get information for this service, it doesn't exists for systemd",
|
||||
'service_file_path': "unknown",
|
||||
}
|
||||
|
@ -273,13 +270,13 @@ def service_status(names=[]):
|
|||
'status': str(status.get("SubState", "unknown")),
|
||||
'loaded': "enabled" if str(status.get("LoadState", "unknown")) == "loaded" else str(status.get("LoadState", "unknown")),
|
||||
'active': str(status.get("ActiveState", "unknown")),
|
||||
'active_at': {
|
||||
"timestamp": str(status.get("ActiveEnterTimestamp", "unknown")),
|
||||
"human": datetime.fromtimestamp(status["ActiveEnterTimestamp"] / 1000000).strftime("%F %X") if "ActiveEnterTimestamp" in status else "unknown",
|
||||
},
|
||||
'description': description,
|
||||
'service_file_path': str(status.get("FragmentPath", "unknown")),
|
||||
}
|
||||
if "ActiveEnterTimestamp" in status:
|
||||
result[name]['active_at'] = datetime.utcfromtimestamp(status["ActiveEnterTimestamp"] / 1000000)
|
||||
else:
|
||||
result[name]['active_at'] = "unknown"
|
||||
|
||||
if len(names) == 1:
|
||||
return result[names[0]]
|
||||
|
@ -293,7 +290,7 @@ def _get_service_information_from_systemd(service):
|
|||
|
||||
d = dbus.SystemBus()
|
||||
|
||||
systemd = d.get_object('org.freedesktop.systemd1','/org/freedesktop/systemd1')
|
||||
systemd = d.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
|
||||
manager = dbus.Interface(systemd, 'org.freedesktop.systemd1.Manager')
|
||||
|
||||
try:
|
||||
|
@ -933,7 +930,7 @@ def _process_regen_conf(system_conf, new_conf=None, save=True):
|
|||
"""
|
||||
if save:
|
||||
backup_path = os.path.join(BACKUP_CONF_DIR, '{0}-{1}'.format(
|
||||
system_conf.lstrip('/'), time.strftime("%Y%m%d.%H%M%S")))
|
||||
system_conf.lstrip('/'), datetime.utcnow().strftime("%Y%m%d.%H%M%S")))
|
||||
backup_dir = os.path.dirname(backup_path)
|
||||
|
||||
if not os.path.isdir(backup_dir):
|
||||
|
|
|
@ -155,7 +155,7 @@ def settings_reset_all():
|
|||
# addition but we'll see if this is a common need.
|
||||
# Another solution would be to use etckeeper and integrate those
|
||||
# modification inside of it and take advantage of its git history
|
||||
old_settings_backup_path = SETTINGS_PATH_OTHER_LOCATION % datetime.now().strftime("%F_%X")
|
||||
old_settings_backup_path = SETTINGS_PATH_OTHER_LOCATION % datetime.utcnow().strftime("%F_%X")
|
||||
_save_settings(settings, location=old_settings_backup_path)
|
||||
|
||||
for value in settings.values():
|
||||
|
|
Loading…
Add table
Reference in a new issue