Add strftime config option

This commit is contained in:
meganomic 2021-01-03 21:11:19 +01:00
parent 627ef431f9
commit 54e8e7b8dc
2 changed files with 17 additions and 4 deletions

View File

@ -107,7 +107,7 @@ class Config(object):
# Re patern for optimize research of `foo`
self.re_pattern = re.compile(r'(\`.+?\`)')
self.parser = ConfigParser()
self.parser = ConfigParser(interpolation=None)
self.read()
def config_file_paths(self):
@ -224,6 +224,11 @@ class Config(object):
self.set_default_cwc('processlist', 'cpu')
self.set_default_cwc('processlist', 'mem')
# Now
if not self.parser.has_section('strftime'):
self.parser.add_section('strftime')
self.set_default('strftime', 'format', '')
@property
def loaded_config_file(self):
"""Return the loaded configuration file."""

View File

@ -41,6 +41,10 @@ class Plugin(GlancesPlugin):
# Set the message position
self.align = 'bottom'
if config is not None:
if 'strftime' in config.as_dict():
self.strftime = config.as_dict()['strftime']['format']
def reset(self):
"""Reset/init the stats."""
self.stats = ''
@ -49,10 +53,14 @@ class Plugin(GlancesPlugin):
"""Update current date/time."""
# Had to convert it to string because datetime is not JSON serializable
# Add the time zone (issue #1249 / #1337 / #1598)
if (len(tzname[1]) > 6):
self.stats = strftime('%Y-%m-%d %H:%M:%S %z')
if self.strftime:
self.stats = strftime(self.strftime)
else:
self.stats = strftime('%Y-%m-%d %H:%M:%S %Z')
if (len(tzname[1]) > 6):
self.stats = strftime('%Y-%m-%d %H:%M:%S %z')
else:
self.stats = strftime('%Y-%m-%d %H:%M:%S %Z')
return self.stats