1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of Glances. |
4
|
|
|
# |
5
|
|
|
# Copyright (C) 2019 Nicolargo <[email protected]> |
6
|
|
|
# |
7
|
|
|
# Glances is free software; you can redistribute it and/or modify |
8
|
|
|
# it under the terms of the GNU Lesser General Public License as published by |
9
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
# (at your option) any later version. |
11
|
|
|
# |
12
|
|
|
# Glances is distributed in the hope that it will be useful, |
13
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
# GNU Lesser General Public License for more details. |
16
|
|
|
# |
17
|
|
|
# You should have received a copy of the GNU Lesser General Public License |
18
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
|
20
|
|
|
"""Now (current date) plugin.""" |
21
|
|
|
|
22
|
|
|
from time import tzname, localtime, strftime |
|
|
|
|
23
|
|
|
|
24
|
|
|
from glances.globals import WINDOWS |
|
|
|
|
25
|
|
|
from glances.plugins.glances_plugin import GlancesPlugin |
|
|
|
|
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class Plugin(GlancesPlugin): |
29
|
|
|
"""Plugin to get the current date/time. |
30
|
|
|
|
31
|
|
|
stats is (string) |
32
|
|
|
""" |
33
|
|
|
|
34
|
|
|
def __init__(self, args=None, config=None): |
35
|
|
|
"""Init the plugin.""" |
36
|
|
|
super(Plugin, self).__init__(args=args, config=config) |
37
|
|
|
|
38
|
|
|
# We want to display the stat in the curse interface |
39
|
|
|
self.display_curse = True |
40
|
|
|
|
41
|
|
|
# Set the message position |
42
|
|
|
self.align = 'bottom' |
43
|
|
|
|
44
|
|
|
if args.strftime_format: |
45
|
|
|
self.strftime = args.strftime_format |
46
|
|
|
elif config is not None: |
47
|
|
|
if 'global' in config.as_dict(): |
48
|
|
|
self.strftime = config.as_dict()['global']['strftime_format'] |
49
|
|
|
|
50
|
|
|
def reset(self): |
51
|
|
|
"""Reset/init the stats.""" |
52
|
|
|
self.stats = '' |
53
|
|
|
|
54
|
|
|
def update(self): |
55
|
|
|
"""Update current date/time.""" |
56
|
|
|
# Had to convert it to string because datetime is not JSON serializable |
57
|
|
|
# Add the time zone (issue #1249 / #1337 / #1598) |
58
|
|
|
|
59
|
|
|
if self.strftime: |
60
|
|
|
self.stats = strftime(self.strftime) |
61
|
|
|
else: |
62
|
|
|
if (len(tzname[1]) > 6): |
|
|
|
|
63
|
|
|
self.stats = strftime('%Y-%m-%d %H:%M:%S %z') |
64
|
|
|
else: |
65
|
|
|
self.stats = strftime('%Y-%m-%d %H:%M:%S %Z') |
66
|
|
|
|
67
|
|
|
return self.stats |
68
|
|
|
|
69
|
|
|
def msg_curse(self, args=None, max_width=None): |
70
|
|
|
"""Return the string to display in the curse interface.""" |
71
|
|
|
# Init the return message |
72
|
|
|
ret = [] |
73
|
|
|
|
74
|
|
|
# Build the string message |
75
|
|
|
# 23 is the padding for the process list |
76
|
|
|
msg = '{:23}'.format(self.stats) |
77
|
|
|
ret.append(self.curse_add_line(msg)) |
78
|
|
|
|
79
|
|
|
return ret |
80
|
|
|
|