X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fpython%2Fdolcon%2F__init__.py;h=d8a2b753f74f50cb5673f02ce3732b73d78441b0;hb=00ea20394f7910ae77782aab32d9bb975e6233fe;hp=e7adb29ec4644989a11632ba694d479c7abe8325;hpb=fbe30a6da13729c16770608bb5a7f11d79b22fb2;p=doldaconnect.git diff --git a/lib/python/dolcon/__init__.py b/lib/python/dolcon/__init__.py index e7adb29..d8a2b75 100644 --- a/lib/python/dolcon/__init__.py +++ b/lib/python/dolcon/__init__.py @@ -1,4 +1,5 @@ from dolmod import * +import os def login(useauthless = True, **kw): result = [None] @@ -10,7 +11,7 @@ def login(useauthless = True, **kw): return result[0] def mustconnect(host, port = -1): - connect(host, port) + fd = connect(host, port) while True: resp = getresp() if resp is not None and resp.getcmd() == u".connect": @@ -18,12 +19,18 @@ def mustconnect(host, port = -1): select() if resp.getcode() != 200: raise RuntimeError, resp.intresp()[0][0] + return fd -def cnl(host, port = -1, useauthless = True, **kw): - mustconnect(host, port) +def cnl(host = None, port = -1, useauthless = True, **kw): + if host is None: + host = os.getenv("DCSERVER") + if host is None: + raise ValueError, "No DC host to connect to" + fd = mustconnect(host, port) err, reason = login(useauthless, **kw) if err != "success": raise RuntimeError, (err, reason) + return fd def ecmd(*args): tag = qcmd(*args)