From 54e8e7b8dcb8c9ebda1f6840f6a86f1486fda52f Mon Sep 17 00:00:00 2001 From: meganomic <> Date: Sun, 3 Jan 2021 21:11:19 +0100 Subject: [PATCH] Add strftime config option --- glances/config.py | 7 ++++++- glances/plugins/glances_now.py | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/glances/config.py b/glances/config.py index 811dd5b3..1b08d995 100644 --- a/glances/config.py +++ b/glances/config.py @@ -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.""" diff --git a/glances/plugins/glances_now.py b/glances/plugins/glances_now.py index 254d71b8..77c05d21 100644 --- a/glances/plugins/glances_now.py +++ b/glances/plugins/glances_now.py @@ -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