mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-20 15:52:16 +03:00
Merge pull request #1785 from meganomic/strftime
Add option to set the strftime format
This commit is contained in:
commit
5330d03077
@ -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):
|
||||
@ -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')
|
||||
|
@ -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):
|
||||
|
@ -41,6 +41,12 @@ class Plugin(GlancesPlugin):
|
||||
# Set the message position
|
||||
self.align = 'bottom'
|
||||
|
||||
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."""
|
||||
self.stats = ''
|
||||
@ -49,10 +55,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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user