1 """Management for daemon processes
3 This module provides some client support for the daemon management
4 provided in the ashd.pdm module.
9 class protoerr(Exception):
13 if isinstance(spec, socket.socket):
18 sk = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
21 sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
22 sk.connect(("localhost", int(spec)))
24 sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
26 sk.connect((spec[:p], int(spec[p + 1:])))
28 raise Exception("Unknown target specification %r" % spec)
32 if sk is not None: sk.close()
36 def __init__(self, sk, proto = None):
39 line = self.readline()
41 raise protoerr("Illegal protocol signature")
50 p = self.buf.find("\n")
53 self.buf = self.buf[p + 1:]
55 ret = self.sk.recv(1024)
60 def select(self, proto):
62 raise Exception("Illegal protocol specified: %r" % proto)
63 self.sk.send(proto + "\n")
65 if len(rep) < 1 or rep[0] != "+":
66 raise protoerr("Error reply when selecting protocol %s: %s" % (proto, rep[1:]))
71 def __exit__(self, *excinfo):
75 class replclient(client):
76 def __init__(self, sk):
77 super(replclient, self).__init__(sk, "repl")
81 ncode = code.replace("\n\n", "\n")
82 if ncode == code: break
84 while len(code) > 0 and code[-1] == "\n":
86 self.sk.send(code + "\n\n")
95 raise protoerr("Error reply: %s" % ln[1:])
97 raise protoerr("Illegal reply: %s" % ln)