Change package name.
[doldaconnect.git] / lib / python / dolcon / __init__.py
CommitLineData
fbe30a6d 1from dolmod import *
c5de778c 2import os
fbe30a6d 3
4def login(useauthless = True, **kw):
5 result = [None]
6 def mycb(*v):
7 result[0] = v
8 loginasync(mycb, useauthless, **kw)
9 while result[0] is None:
10 select()
11 return result[0]
12
13def mustconnect(host, port = -1):
00ea2039 14 fd = connect(host, port)
fbe30a6d 15 while True:
16 resp = getresp()
17 if resp is not None and resp.getcmd() == u".connect":
18 break
19 select()
20 if resp.getcode() != 200:
21 raise RuntimeError, resp.intresp()[0][0]
00ea2039 22 return fd
fbe30a6d 23
c5de778c 24def cnl(host = None, port = -1, useauthless = True, **kw):
25 if host is None:
26 host = os.getenv("DCSERVER")
27 if host is None:
28 raise ValueError, "No DC host to connect to"
00ea2039 29 fd = mustconnect(host, port)
fbe30a6d 30 err, reason = login(useauthless, **kw)
31 if err != "success":
32 raise RuntimeError, (err, reason)
00ea2039 33 return fd
fbe30a6d 34
35def ecmd(*args):
36 tag = qcmd(*args)
37 while True:
38 resp = getresp(tag)
39 if resp is not None:
40 break;
41 select()
42 return resp
43
44def ecmda(code, *args):
45 resp = ecmd(*args)
46 if resp.getcode() != code:
47 raise ValueError, resp.getcode()
48 return resp