comparison bitten/slave.py @ 14:1733c601d2f8

Refactored the asyncore loop and shutdown procedure into {{{beep.Initiator}}}.
author cmlenz
date Thu, 16 Jun 2005 20:37:38 +0000
parents 21aa17f97522
children 06207499c58c
comparison
equal deleted inserted replaced
13:21aa17f97522 14:1733c601d2f8
29 29
30 30
31 class Slave(beep.Initiator): 31 class Slave(beep.Initiator):
32 32
33 channelno = None # The channel number used by the bitten profile 33 channelno = None # The channel number used by the bitten profile
34 terminated = False
34 35
35 def channel_started(self, channelno, profile_uri): 36 def channel_started(self, channelno, profile_uri):
36 if profile_uri == BittenProfileHandler.URI: 37 if profile_uri == BittenProfileHandler.URI:
37 self.channelno = channelno 38 self.channelno = channelno
38 39
39 def greeting_received(self, profiles): 40 def greeting_received(self, profiles):
40 if BittenProfileHandler.URI in profiles: 41 if BittenProfileHandler.URI in profiles:
41 self.channels[0].profile.send_start([BittenProfileHandler], 42 self.channels[0].profile.send_start([BittenProfileHandler],
42 handle_ok=self.channel_started) 43 handle_ok=self.channel_started)
44
43 45
44 class BittenProfileHandler(beep.Profile): 46 class BittenProfileHandler(beep.Profile):
45 """Handles communication on the Bitten profile from the client perspective. 47 """Handles communication on the Bitten profile from the client perspective.
46 """ 48 """
47 URI = 'http://bitten.cmlenz.net/beep-profile/' 49 URI = 'http://bitten.cmlenz.net/beep-profile/'
96 elif opt in ('-q', '--quiet'): 98 elif opt in ('-q', '--quiet'):
97 quiet = True 99 quiet = True
98 100
99 slave = Slave(host, port) 101 slave = Slave(host, port)
100 try: 102 try:
101 try: 103 slave.run()
102 asyncore.loop()
103 except KeyboardInterrupt, beep.TerminateSession:
104 def handle_ok():
105 raise asyncore.ExitNow, 'Session terminated'
106 def handle_error(code, message):
107 print>>sys.stderr, \
108 'Build master refused to terminate session (%d): %s' \
109 % (code, message)
110 slave.channels[0].profile.send_close(slave.channelno)
111 slave.channels[0].profile.send_close(handle_ok=handle_ok,
112 handle_error=handle_error)
113 time.sleep(.25)
114 except beep.TerminateSession, e: 104 except beep.TerminateSession, e:
115 print e 105 print 'Session terminated:', e
Copyright (C) 2012-2017 Edgewall Software