From 54e8e7b8dcb8c9ebda1f6840f6a86f1486fda52f Mon Sep 17 00:00:00 2001 From: meganomic <> Date: Sun, 3 Jan 2021 21:11:19 +0100 Subject: [PATCH 1/2] 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 From eea6e46edc3718078b7a416321731e3e0e8359e4 Mon Sep 17 00:00:00 2001 From: meganomic <> Date: Mon, 4 Jan 2021 11:56:08 +0100 Subject: [PATCH 2/2] Add commandline option for strftime_format. Set check_updates in config because otherwise outdated fails since it isn't set even though there is a 'global' --- glances/config.py | 15 ++++++++++----- glances/main.py | 3 +++ glances/plugins/glances_now.py | 8 +++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/glances/config.py b/glances/config.py index 1b08d995..7c79958d 100644 --- a/glances/config.py +++ b/glances/config.py @@ -153,6 +153,16 @@ class Config(object): self._loaded_config_file = config_file break + # Globals + if not self.parser.has_section('global'): + self.parser.add_section('global') + self.set_default('global', 'strftime_format', '') + + # check_update + if not self.parser.has_section('global'): + self.parser.add_section('global') + self.set_default('global', 'check_update', 'false') + # Quicklook if not self.parser.has_section('quicklook'): self.parser.add_section('quicklook') @@ -224,11 +234,6 @@ 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/main.py b/glances/main.py index 3004aa66..75587823 100644 --- a/glances/main.py +++ b/glances/main.py @@ -254,6 +254,9 @@ Examples of use: # Globals options parser.add_argument('--disable-check-update', action='store_true', default=False, dest='disable_check_update', help='disable online Glances version ckeck') + parser.add_argument('--strftime', dest='strftime_format', default='', + help='strftime format string for displaying current date in standalone mode') + return parser def parse_args(self): diff --git a/glances/plugins/glances_now.py b/glances/plugins/glances_now.py index 77c05d21..d3edb839 100644 --- a/glances/plugins/glances_now.py +++ b/glances/plugins/glances_now.py @@ -41,9 +41,11 @@ 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'] + if args.strftime_format: + self.strftime = args.strftime_format + elif config is not None: + if 'global' in config.as_dict(): + self.strftime = config.as_dict()['global']['strftime_format'] def reset(self): """Reset/init the stats."""