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 pwd
|
||||||
import grp
|
import grp
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
import datetime
|
||||||
|
|
||||||
from moulinette import msignals, m18n, msettings
|
from moulinette import msignals, m18n, msettings
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
|
@ -80,6 +81,10 @@ def app_listlists():
|
||||||
# Get the list
|
# Get the list
|
||||||
appslist_list = _read_appslist_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
|
return appslist_list
|
||||||
|
|
||||||
|
|
||||||
|
@ -1755,8 +1760,7 @@ def _get_app_status(app_id, format_date=False):
|
||||||
if not v:
|
if not v:
|
||||||
status[f] = '-'
|
status[f] = '-'
|
||||||
else:
|
else:
|
||||||
status[f] = time.strftime(m18n.n('format_datetime_short'),
|
status[f] = datetime.utcfromtimestamp(v)
|
||||||
time.gmtime(v))
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import csv
|
import csv
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from datetime import datetime
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
@ -299,7 +300,7 @@ class BackupManager():
|
||||||
(string) A backup name created from current date 'YYMMDD-HHMMSS'
|
(string) A backup name created from current date 'YYMMDD-HHMMSS'
|
||||||
"""
|
"""
|
||||||
# FIXME: case where this name already exist
|
# 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):
|
def _init_work_dir(self):
|
||||||
"""Initialize preparation directory
|
"""Initialize preparation directory
|
||||||
|
@ -859,7 +860,7 @@ class RestoreManager():
|
||||||
raise MoulinetteError(errno.EIO, m18n.n('backup_invalid_archive'))
|
raise MoulinetteError(errno.EIO, m18n.n('backup_invalid_archive'))
|
||||||
else:
|
else:
|
||||||
logger.debug("restoring from backup '%s' created on %s", self.name,
|
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):
|
def _postinstall_if_needed(self):
|
||||||
"""
|
"""
|
||||||
|
@ -2266,8 +2267,7 @@ def backup_info(name, with_details=False, human_readable=False):
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
'path': archive_file,
|
'path': archive_file,
|
||||||
'created_at': time.strftime(m18n.n('format_datetime_short'),
|
'created_at': datetime.utcfromtimestamp(info['created_at']),
|
||||||
time.gmtime(info['created_at'])),
|
|
||||||
'description': info['description'],
|
'description': info['description'],
|
||||||
'size': size,
|
'size': size,
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ def _certificate_install_selfsigned(domain_list, force=False):
|
||||||
args={'force': force})
|
args={'force': force})
|
||||||
|
|
||||||
# Paths of files and folder we'll need
|
# 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" % (
|
new_cert_folder = "%s/%s-history/%s-selfsigned" % (
|
||||||
CERT_FOLDER, domain, date_tag)
|
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...")
|
logger.debug("Saving the key and signed certificate...")
|
||||||
|
|
||||||
# Create corresponding directory
|
# 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:
|
if staging:
|
||||||
folder_flag = "staging"
|
folder_flag = "staging"
|
||||||
|
@ -674,7 +674,7 @@ def _get_status(domain):
|
||||||
cert_subject = cert.get_subject().CN
|
cert_subject = cert.get_subject().CN
|
||||||
cert_issuer = cert.get_issuer().CN
|
cert_issuer = cert.get_issuer().CN
|
||||||
valid_up_to = datetime.strptime(cert.get_notAfter(), "%Y%m%d%H%M%SZ")
|
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():
|
if cert_issuer == _name_self_CA():
|
||||||
CA_type = {
|
CA_type = {
|
||||||
|
@ -819,7 +819,7 @@ def _backup_current_cert(domain):
|
||||||
|
|
||||||
cert_folder_domain = os.path.join(CERT_FOLDER, 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)
|
backup_folder = "%s-backups/%s" % (cert_folder_domain, date_tag)
|
||||||
|
|
||||||
shutil.copytree(cert_folder_domain, backup_folder)
|
shutil.copytree(cert_folder_domain, backup_folder)
|
||||||
|
|
|
@ -316,7 +316,7 @@ class OperationLogger(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.started_at is None:
|
if self.started_at is None:
|
||||||
self.started_at = datetime.now()
|
self.started_at = datetime.utcnow()
|
||||||
self.flush()
|
self.flush()
|
||||||
self._register_log()
|
self._register_log()
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ class OperationLogger(object):
|
||||||
return
|
return
|
||||||
if error is not None and not isinstance(error, basestring):
|
if error is not None and not isinstance(error, basestring):
|
||||||
error = str(error)
|
error = str(error)
|
||||||
self.ended_at = datetime.now()
|
self.ended_at = datetime.utcnow()
|
||||||
self._error = error
|
self._error = error
|
||||||
self._success = error is None
|
self._success = error is None
|
||||||
if self.logger is not None:
|
if self.logger is not None:
|
||||||
|
|
|
@ -248,10 +248,7 @@ def service_status(names=[]):
|
||||||
'status': "unknown",
|
'status': "unknown",
|
||||||
'loaded': "unknown",
|
'loaded': "unknown",
|
||||||
'active': "unknown",
|
'active': "unknown",
|
||||||
'active_at': {
|
'active_at': "unknown",
|
||||||
"timestamp": "unknown",
|
|
||||||
"human": "unknown",
|
|
||||||
},
|
|
||||||
'description': "Error: failed to get information for this service, it doesn't exists for systemd",
|
'description': "Error: failed to get information for this service, it doesn't exists for systemd",
|
||||||
'service_file_path': "unknown",
|
'service_file_path': "unknown",
|
||||||
}
|
}
|
||||||
|
@ -273,13 +270,13 @@ def service_status(names=[]):
|
||||||
'status': str(status.get("SubState", "unknown")),
|
'status': str(status.get("SubState", "unknown")),
|
||||||
'loaded': "enabled" if str(status.get("LoadState", "unknown")) == "loaded" else str(status.get("LoadState", "unknown")),
|
'loaded': "enabled" if str(status.get("LoadState", "unknown")) == "loaded" else str(status.get("LoadState", "unknown")),
|
||||||
'active': str(status.get("ActiveState", "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,
|
'description': description,
|
||||||
'service_file_path': str(status.get("FragmentPath", "unknown")),
|
'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:
|
if len(names) == 1:
|
||||||
return result[names[0]]
|
return result[names[0]]
|
||||||
|
@ -933,7 +930,7 @@ def _process_regen_conf(system_conf, new_conf=None, save=True):
|
||||||
"""
|
"""
|
||||||
if save:
|
if save:
|
||||||
backup_path = os.path.join(BACKUP_CONF_DIR, '{0}-{1}'.format(
|
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)
|
backup_dir = os.path.dirname(backup_path)
|
||||||
|
|
||||||
if not os.path.isdir(backup_dir):
|
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.
|
# addition but we'll see if this is a common need.
|
||||||
# Another solution would be to use etckeeper and integrate those
|
# Another solution would be to use etckeeper and integrate those
|
||||||
# modification inside of it and take advantage of its git history
|
# 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)
|
_save_settings(settings, location=old_settings_backup_path)
|
||||||
|
|
||||||
for value in settings.values():
|
for value in settings.values():
|
||||||
|
|
Loading…
Add table
Reference in a new issue