Test Failed
Push — develop ( 547062...054f8e )
by Nicolas
01:04 queued 12s
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, strftime
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
Unused localtime imported from time
Loading history...
23
24
from glances.globals import WINDOWS
0 ignored issues
show
Unused WINDOWS imported from glances.globals
Loading history...
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
    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
        # Add the time zone (issue #1249 / #1337 / #1598)
52
        if (len(tzname[1]) > 6):
0 ignored issues
show
Unused Code Coding Style introduced by
Unnecessary parens after u'if' keyword
Loading history...
53
            self.stats = strftime('%Y-%m-%d %H:%M:%S %z')
54
        else:
55
            self.stats = strftime('%Y-%m-%d %H:%M:%S %Z')
56
57
        return self.stats
58
59
    def msg_curse(self, args=None, max_width=None):
60
        """Return the string to display in the curse interface."""
61
        # Init the return message
62
        ret = []
63
64
        # Build the string message
65
        # 23 is the padding for the process list
66
        msg = '{:23}'.format(self.stats)
67
        ret.append(self.curse_add_line(msg))
68
69
        return ret
70