mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Display date correctly
This commit is contained in:
parent
18c156a2c0
commit
830341a687
6 changed files with 26 additions and 27 deletions
|
@ -470,11 +470,6 @@ app:
|
|||
listlists:
|
||||
action_help: List registered application lists
|
||||
api: GET /appslists
|
||||
arguments:
|
||||
-H:
|
||||
full: --human-readable
|
||||
help: Return the lastUpdate with a human readable date
|
||||
action: store_true
|
||||
|
||||
### app_removelist()
|
||||
removelist:
|
||||
|
|
2
debian/control
vendored
2
debian/control
vendored
|
@ -11,7 +11,7 @@ Package: yunohost
|
|||
Architecture: all
|
||||
Depends: ${python:Depends}, ${misc:Depends}
|
||||
, moulinette (>= 2.7.1), ssowat (>= 2.7.1)
|
||||
, python-psutil, python-requests, python-dnspython, python-openssl
|
||||
, python-psutil, python-requests, python-dnspython, python-openssl, python-tz
|
||||
, python-apt, python-miniupnpc, python-dbus, python-jinja2
|
||||
, glances
|
||||
, dnsutils, bind9utils, unzip, git, curl, cron, wget, jq
|
||||
|
|
|
@ -37,6 +37,7 @@ import pwd
|
|||
import grp
|
||||
from collections import OrderedDict
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
from moulinette import msignals, m18n, msettings
|
||||
from moulinette.core import MoulinetteError
|
||||
|
@ -67,7 +68,7 @@ re_app_instance_name = re.compile(
|
|||
)
|
||||
|
||||
|
||||
def app_listlists(human_readable=False):
|
||||
def app_listlists():
|
||||
"""
|
||||
List fetched lists
|
||||
|
||||
|
@ -84,13 +85,10 @@ def app_listlists(human_readable=False):
|
|||
# Get the list
|
||||
appslist_list = _read_appslist_list()
|
||||
|
||||
# Human readable date
|
||||
if human_readable:
|
||||
for app in appslist_list:
|
||||
now_for_humans = datetime.datetime.fromtimestamp(
|
||||
appslist_list[app].get("lastUpdate"))
|
||||
appslist_list[app]["lastUpdate"] = now_for_humans.strftime(
|
||||
'%Y-%m-%d %H:%M:%S')
|
||||
for app in appslist_list:
|
||||
last_update = datetime.datetime.utcfromtimestamp(
|
||||
appslist_list[app].get("lastUpdate"))
|
||||
appslist_list[app]["lastUpdate"] = last_update.replace(tzinfo=pytz.utc)
|
||||
|
||||
return appslist_list
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import os
|
|||
import yaml
|
||||
import errno
|
||||
import collections
|
||||
import pytz
|
||||
|
||||
from datetime import datetime
|
||||
from logging import FileHandler, getLogger, Formatter
|
||||
|
@ -100,7 +101,7 @@ def log_list(category=[], limit=None):
|
|||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
entry["started_at"] = log_datetime
|
||||
entry["started_at"] = log_datetime.replace(tzinfo=pytz.utc)
|
||||
|
||||
result[category].append(entry)
|
||||
|
||||
|
@ -182,6 +183,10 @@ def log_display(path, number=50, share=False):
|
|||
metadata = yaml.safe_load(md_file)
|
||||
infos['metadata_path'] = md_path
|
||||
infos['metadata'] = metadata
|
||||
if 'started_at' in infos['metadata']:
|
||||
infos['metadata']['started_at'] = infos['metadata']['started_at'].replace(tzinfo=pytz.utc)
|
||||
if 'ended_at' in infos['metadata']:
|
||||
infos['metadata']['ended_at'] = infos['metadata']['ended_at'].replace(tzinfo=pytz.utc)
|
||||
if 'log_path' in metadata:
|
||||
log_path = metadata['log_path']
|
||||
except yaml.YAMLError:
|
||||
|
@ -316,7 +321,8 @@ class OperationLogger(object):
|
|||
"""
|
||||
|
||||
if self.started_at is None:
|
||||
self.started_at = datetime.now()
|
||||
self.started_at = datetime.utcnow()
|
||||
self.started_at = self.started_at.replace(tzinfo=pytz.utc)
|
||||
self.flush()
|
||||
self._register_log()
|
||||
|
||||
|
@ -408,7 +414,8 @@ 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.ended_at = self.ended_at.replace(tzinfo=pytz.utc)
|
||||
self._error = error
|
||||
self._success = error is None
|
||||
if self.logger is not None:
|
||||
|
|
|
@ -283,7 +283,7 @@ def monitor_system(units=None, human_readable=False):
|
|||
elif u == 'process':
|
||||
result[u] = json.loads(glances.getProcessCount())
|
||||
elif u == 'uptime':
|
||||
result[u] = (str(datetime.now() - datetime.fromtimestamp(psutil.boot_time())).split('.')[0])
|
||||
result[u] = (str(datetime.utcnow() - datetime.utcfromtimestamp(psutil.boot_time())).split('.')[0])
|
||||
elif u == 'infos':
|
||||
result[u] = json.loads(glances.getSystem())
|
||||
else:
|
||||
|
|
|
@ -31,6 +31,7 @@ import subprocess
|
|||
import errno
|
||||
import shutil
|
||||
import hashlib
|
||||
import pytz
|
||||
|
||||
from difflib import unified_diff
|
||||
from datetime import datetime
|
||||
|
@ -248,10 +249,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 +271,14 @@ 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)
|
||||
result[name]['active_at'] = result[name]['active_at'].replace(tzinfo=pytz.utc)
|
||||
else:
|
||||
result[name]['active_at'] = "unknown"
|
||||
|
||||
if len(names) == 1:
|
||||
return result[names[0]]
|
||||
|
@ -293,7 +292,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:
|
||||
|
|
Loading…
Add table
Reference in a new issue