glances_now.py 1.8 KB
Newer Older
A
Alessio Sergi 已提交
1 2
# -*- coding: utf-8 -*-
#
3
# This file is part of Glances.
A
Alessio Sergi 已提交
4
#
5
# Copyright (C) 2015 Nicolargo <nicolas@nicolargo.com>
A
Alessio Sergi 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#
# Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Glances is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime

N
Nicolas Hennion 已提交
22
from glances.plugins.glances_plugin import GlancesPlugin
A
Alessio Sergi 已提交
23 24 25


class Plugin(GlancesPlugin):
A
PEP 257  
Alessio Sergi 已提交
26 27

    """Plugin to get the current date/time.
A
Alessio Sergi 已提交
28 29 30 31

    stats is (string)
    """

32
    def __init__(self, args=None):
A
PEP 257  
Alessio Sergi 已提交
33
        """Init the plugin."""
A
Alessio Sergi 已提交
34
        super(Plugin, self).__init__(args=args)
A
Alessio Sergi 已提交
35 36 37

        # We want to display the stat in the curse interface
        self.display_curse = True
N
Nicolargo 已提交
38

A
Alessio Sergi 已提交
39
        # Set the message position
40
        self.align = 'bottom'
A
Alessio Sergi 已提交
41

42
    def update(self):
A
PEP 257  
Alessio Sergi 已提交
43
        """Update current date/time."""
A
Alessio Sergi 已提交
44
        # Had to convert it to string because datetime is not JSON serializable
A
Alessio Sergi 已提交
45
        self.stats = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
A
Alessio Sergi 已提交
46 47 48 49

        return self.stats

    def msg_curse(self, args=None):
A
PEP 257  
Alessio Sergi 已提交
50
        """Return the string to display in the curse interface."""
A
Alessio Sergi 已提交
51 52 53 54 55
        # Init the return message
        ret = []

        # Build the string message
        # 23 is the padding for the process list
56
        msg = '{:23}'.format(self.stats)
A
Alessio Sergi 已提交
57 58 59
        ret.append(self.curse_add_line(msg))

        return ret