source: epoptes/trunk/fuentes/epoptes/daemon/uiconnection.py @ 295

Last change on this file since 295 was 295, checked in by mabarracus, 4 years ago

copy trusty epoptes code

File size: 2.3 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4###########################################################################
5# UI connection.
6#
7# Copyright (C) 2010 Fotis Tsamis <ftsamis@gmail.com>
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FINESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21#
22# On Debian GNU/Linux systems, the complete text of the GNU General
23# Public License can be found in `/usr/share/common-licenses/GPL".
24###########################################################################
25
26import os
27
28from twisted.internet import protocol
29from twisted.protocols import amp
30
31import commands
32
33class Daemon(amp.AMP):
34
35    def __init__(self, client):
36        self.client = client
37
38
39    def connectionMade(self):
40        amp.AMP.connectionMade(self)
41        self.client.connected(self)
42       
43    @commands.ClientConnected.responder
44    def clientConnected(self, handle):
45        self.client.amp_clientConnected(handle)
46        return {}
47
48
49    @commands.ClientDisconnected.responder
50    def clientDisconnected(self, handle):
51        self.client.amp_clientDisconnected(handle)
52        return {}
53
54
55    def enumerateClients(self):
56        d = self.callRemote(commands.EnumerateClients)
57        d.addCallback(lambda r: r['handles'])
58        return d
59       
60
61    def command(self, handle, command):
62        d = self.callRemote(commands.ClientCommand,
63                            handle=handle,
64                            command=command)
65
66        def gotResult(response):
67            filename = response['filename']
68            if filename:
69                result = open(filename, 'rb').read()
70                os.unlink(filename)
71                return result
72            else:
73                return response['result']
74
75        d.addCallback(gotResult)
76        return d
77
Note: See TracBrowser for help on using the repository browser.