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:
|
listlists:
|
||||||
action_help: List registered application lists
|
action_help: List registered application lists
|
||||||
api: GET /appslists
|
api: GET /appslists
|
||||||
arguments:
|
|
||||||
-H:
|
|
||||||
full: --human-readable
|
|
||||||
help: Return the lastUpdate with a human readable date
|
|
||||||
action: store_true
|
|
||||||
|
|
||||||
### app_removelist()
|
### app_removelist()
|
||||||
removelist:
|
removelist:
|
||||||
|
|
2
debian/control
vendored
2
debian/control
vendored
|
@ -11,7 +11,7 @@ Package: yunohost
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: ${python:Depends}, ${misc:Depends}
|
Depends: ${python:Depends}, ${misc:Depends}
|
||||||
, moulinette (>= 2.7.1), ssowat (>= 2.7.1)
|
, 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
|
, python-apt, python-miniupnpc, python-dbus, python-jinja2
|
||||||
, glances
|
, glances
|
||||||
, dnsutils, bind9utils, unzip, git, curl, cron, wget, jq
|
, dnsutils, bind9utils, unzip, git, curl, cron, wget, jq
|
||||||
|
|
|
@ -37,6 +37,7 @@ import pwd
|
||||||
import grp
|
import grp
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import datetime
|
import datetime
|
||||||
|
import pytz
|
||||||
|
|
||||||
from moulinette import msignals, m18n, msettings
|
from moulinette import msignals, m18n, msettings
|
||||||
from moulinette.core import MoulinetteError
|
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
|
List fetched lists
|
||||||
|
|
||||||
|
@ -84,13 +85,10 @@ def app_listlists(human_readable=False):
|
||||||
# Get the list
|
# Get the list
|
||||||
appslist_list = _read_appslist_list()
|
appslist_list = _read_appslist_list()
|
||||||
|
|
||||||
# Human readable date
|
for app in appslist_list:
|
||||||
if human_readable:
|
last_update = datetime.datetime.utcfromtimestamp(
|
||||||
for app in appslist_list:
|
appslist_list[app].get("lastUpdate"))
|
||||||
now_for_humans = datetime.datetime.fromtimestamp(
|
appslist_list[app]["lastUpdate"] = last_update.replace(tzinfo=pytz.utc)
|
||||||
appslist_list[app].get("lastUpdate"))
|
|
||||||
appslist_list[app]["lastUpdate"] = now_for_humans.strftime(
|
|
||||||
'%Y-%m-%d %H:%M:%S')
|
|
||||||
|
|
||||||
return appslist_list
|
return appslist_list
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import os
|
||||||
import yaml
|
import yaml
|
||||||
import errno
|
import errno
|
||||||
import collections
|
import collections
|
||||||
|
import pytz
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from logging import FileHandler, getLogger, Formatter
|
from logging import FileHandler, getLogger, Formatter
|
||||||
|
@ -100,7 +101,7 @@ def log_list(category=[], limit=None):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
entry["started_at"] = log_datetime
|
entry["started_at"] = log_datetime.replace(tzinfo=pytz.utc)
|
||||||
|
|
||||||
result[category].append(entry)
|
result[category].append(entry)
|
||||||
|
|
||||||
|
@ -182,6 +183,10 @@ def log_display(path, number=50, share=False):
|
||||||
metadata = yaml.safe_load(md_file)
|
metadata = yaml.safe_load(md_file)
|
||||||
infos['metadata_path'] = md_path
|
infos['metadata_path'] = md_path
|
||||||
infos['metadata'] = metadata
|
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:
|
if 'log_path' in metadata:
|
||||||
log_path = metadata['log_path']
|
log_path = metadata['log_path']
|
||||||
except yaml.YAMLError:
|
except yaml.YAMLError:
|
||||||
|
@ -316,7 +321,8 @@ 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.started_at = self.started_at.replace(tzinfo=pytz.utc)
|
||||||
self.flush()
|
self.flush()
|
||||||
self._register_log()
|
self._register_log()
|
||||||
|
|
||||||
|
@ -408,7 +414,8 @@ 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.ended_at = self.ended_at.replace(tzinfo=pytz.utc)
|
||||||
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:
|
||||||
|
|
|
@ -283,7 +283,7 @@ def monitor_system(units=None, human_readable=False):
|
||||||
elif u == 'process':
|
elif u == 'process':
|
||||||
result[u] = json.loads(glances.getProcessCount())
|
result[u] = json.loads(glances.getProcessCount())
|
||||||
elif u == 'uptime':
|
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':
|
elif u == 'infos':
|
||||||
result[u] = json.loads(glances.getSystem())
|
result[u] = json.loads(glances.getSystem())
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -31,6 +31,7 @@ import subprocess
|
||||||
import errno
|
import errno
|
||||||
import shutil
|
import shutil
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import pytz
|
||||||
|
|
||||||
from difflib import unified_diff
|
from difflib import unified_diff
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -248,10 +249,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 +271,14 @@ 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)
|
||||||
|
result[name]['active_at'] = result[name]['active_at'].replace(tzinfo=pytz.utc)
|
||||||
|
else:
|
||||||
|
result[name]['active_at'] = "unknown"
|
||||||
|
|
||||||
if len(names) == 1:
|
if len(names) == 1:
|
||||||
return result[names[0]]
|
return result[names[0]]
|
||||||
|
@ -293,7 +292,7 @@ def _get_service_information_from_systemd(service):
|
||||||
|
|
||||||
d = dbus.SystemBus()
|
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')
|
manager = dbus.Interface(systemd, 'org.freedesktop.systemd1.Manager')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue