Test Failed
Push — develop ( d7cf39...faa4bd )
by Nicolas
04:34 queued 10s
created

glances/plugins/glances_now.py (4 issues)

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
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
23
from datetime import datetime
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
24
25
from glances.plugins.glances_plugin import GlancesPlugin
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
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
    def reset(self):
45
        """Reset/init the stats."""
46
        self.stats = ''
47
48
    def update(self):
49
        """Update current date/time."""
50
        # Had to convert it to string because datetime is not JSON serializable
51
        self.stats = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
52
        # Add the time zone (issue #1249 and issue #1337)
53
        if 'tmzone' in localtime():
54
            self.stats += ' {}'.format(localtime().tm_zone)
55
        elif len(tzname) > 0:
0 ignored issues
show
Do not use len(SEQUENCE) as condition value
Loading history...
56
            self.stats += ' {}'.format(tzname[1])
57
58
        return self.stats
59
60
    def msg_curse(self, args=None, max_width=None):
61
        """Return the string to display in the curse interface."""
62
        # Init the return message
63
        ret = []
64
65
        # Build the string message
66
        # 23 is the padding for the process list
67
        msg = '{:23}'.format(self.stats)
68
        ret.append(self.curse_add_line(msg))
69
70
        return ret
71