From e531d099a17cfea1a231026aa490d3098c0fd3f2 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Tue, 28 Dec 2010 16:08:37 +0100 Subject: [PATCH] "con" tag management. --- ccserver/ccserver.py | 5 ++--- ccserver/client.py | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/ccserver/ccserver.py b/ccserver/ccserver.py index 9c29ff0..958e6f2 100644 --- a/ccserver/ccserver.py +++ b/ccserver/ccserver.py @@ -130,16 +130,15 @@ class CCServer(object): if login in self._connected: client = self._connected[login] + tags['con'] = client.get_uptime() try: tags.update(client.connection.call('get_tags', tuple(requested_tags))) except Exception as err: logging.error('Error while calling get_tags on ' '%s: %s' % (client.login, err)) - else: - tags['status'] = 'online' else: - tags['status'] = 'offline' + tags['con'] = 'offline' # Apply all user specified tags: tags.update(conf['tags']) diff --git a/ccserver/client.py b/ccserver/client.py index 52ece0d..207c37f 100644 --- a/ccserver/client.py +++ b/ccserver/client.py @@ -1,6 +1,8 @@ #!/usr/bin/env python #coding=utf8 +from datetime import datetime + class CCClient(object): ''' Represent a single client connected to the server. @@ -20,20 +22,15 @@ class CCClient(object): # The connection of the client (public attribute): self.connection = connection - def get_tags(self, tags=None): - ''' - Get the tags of the object. + # The date of connection of the client: + self._connection_date = datetime.now() - :param tags: the list of tags to fetch, or None for all + def get_uptime(self): ''' + Get the uptime of the client connection in seconds. - # Get the tags from the server - tags = self.connection.call('get_tags', tags) - # Add the static tags: - tags['a'] = self.login - tags['hv'] = self.login - tags['role'] = self.role - # Update it with the locally defined tags: - tags.update(self.server.conf.show(self.login)['tags']) - - return tags + :return: uptime of the client + ''' + + dt = datetime.now() - self._connection_date + return dt.seconds + dt.days * 86400 -- GitLab