X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fpython%2Fdolcon%2F__init__.py;h=8675b38b0cf67b061979987cf0782bc3e4800deb;hb=17537706a99e4baf6ceca6e66df520f2b675a775;hp=11cb6d4467faaafd3429eaee5142054063826f35;hpb=ff076c0adebb0b8495465cb59531046eb158eab9;p=doldaconnect.git diff --git a/lib/python/dolcon/__init__.py b/lib/python/dolcon/__init__.py index 11cb6d4..8675b38 100644 --- a/lib/python/dolcon/__init__.py +++ b/lib/python/dolcon/__init__.py @@ -47,14 +47,14 @@ def cnl(host = None, port = -1, useauthless = True, **kw): """A convenience function for connect and loginasync. This function will connect to the given server, or the server in - the environment variable $DCSERVER if none is given, and - authenticate to the server. If any of the steps fail, an exception - is raised. + the environment variable $DCSERVER if none is given, or, if that + fails, localhost, and authenticate to the server. If any of the + steps fail, an exception is raised. """ if host is None: host = os.getenv("DCSERVER") if host is None: - raise ValueError, "No DC host to connect to" + host = "localhost" fd = mustconnect(host, port) err, reason = login(useauthless, **kw) if err != "success": @@ -88,3 +88,14 @@ def ecmda(code, *args): if resp.getcode() != code: raise ValueError, resp.getcode() return resp + +def ecmds(*args): + """Another convenience function for ecmd. + + Like ecmda, but will fail on all 5xx codes, and succeed on all + others. + """ + resp = ecmd(*args) + if resp.getcode() >= 500 and resp.getcode() < 600: + raise ValueError, tuple(resp.extract()[0]) + return resp