File: client.py

package info (click to toggle)
atheist 0.20110402-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 1,348 kB
  • sloc: python: 4,764; xml: 626; makefile: 113; cpp: 54; ansic: 5; sh: 5
file content (101 lines) | stat: -rwxr-xr-x 2,522 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import time
import gobject
import logging

import Ice

Ice.loadSlice('-I%s atheist.ice' % Ice.getSliceDir())
import Atheist

import atheist.log

log = logging.getLogger()
log.setLevel(logging.DEBUG)
log.addHandler(atheist.log.create_basic_handler())


class StatusObserverI(Atheist.StatusObserver):
    def updateTasks(self, tasks, current=None):
        log.info("statusOb Task: %s" % tasks)

    def updateTaskCases(self, cases, current=None):
        log.info("statusOb TaskCase: %s" % cases)

    def updateManager(self, value, current=None):
        log.info("statusOb Manager: %s" % value)


class OutObserverI(Atheist.OutObserver):
    def update(self, taskID, val, current=None):
        print taskID, val


class LogObserverI(Atheist.LogObserver):
    def update(self, taskID, entry, current=None):
        print taskID, entry



class client(Ice.Application):

    def run(self, argv):
        self.shutdownOnInterrupt()

        ic = self.communicator()

        adapter = ic.createObjectAdapterWithEndpoints("Client", "default")
        base = ic.stringToProxy(ic.getProperties().getProperty("Manager.Proxy"))
        print base

        self.mng = Atheist.ManagerPrx.checkedCast(base)

        if not self.mng:
            raise RuntimeError("Invalid proxy")

        self.mng.attachStatusOb(
            Atheist.StatusObserverPrx.uncheckedCast(
                adapter.addWithUUID(StatusObserverI())))

        self.mng.attachOutOb(
            Atheist.OutObserverPrx.uncheckedCast(
                adapter.addWithUUID(OutObserverI())).ice_batchOneway(), [])

        self.mng.attachLogOb(
            Atheist.LogObserverPrx.uncheckedCast(
                adapter.addWithUUID(LogObserverI())).ice_batchOneway(), [])

        adapter.activate()
        self.callbackOnInterrupt()

        gobject.threads_init()
        gobject.timeout_add(3, self.event)
        self.loop = gobject.MainLoop()
        self.loop.run()

        self.communicator().shutdown()
        return 0

    def interruptCallback(self, args):
        gobject.idle_add(self.loop.quit)

    def event(self):
        print 'Event!'

        cases = self.mng.getTaskCases()
        if cases:
            print len(cases), "task cases"
            print cases[0].getConfig()

        self.mng.ice_oneway().runAll()
        print "FIN ------------"
        gobject.timeout_add(20000, self.event)

        return False


if __name__ == "__main__":
    sys.exit(client().main(sys.argv))