X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=pdm%2Fcli.py;h=7cfa2635fd5d60a369f44bd9bf764fa14a8f8b5c;hb=HEAD;hp=0b316823ef8cddc23728b85b1f2bb4c434d5e21e;hpb=c58b1ad8cc6658ea46ed049f6909b4ce05906b57;p=pdm.git diff --git a/pdm/cli.py b/pdm/cli.py index 0b31682..df04883 100644 --- a/pdm/cli.py +++ b/pdm/cli.py @@ -19,16 +19,21 @@ def resolve(spec): return spec sk = None try: - if "/" in spec: + if ":" in spec: + p = spec.rindex(":") + first, second = spec[:p], spec[p + 1:] + if "/" in second: + from . import sshsock + sk = sshsock.sshsocket(first, second) + else: + sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sk.connect((first, second)) + elif "/" in spec: sk = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sk.connect(spec) elif spec.isdigit(): sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.connect(("localhost", int(spec))) - elif ":" in spec: - sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - p = spec.rindex(":") - sk.connect((spec[:p], int(spec[p + 1:]))) else: raise Exception("Unknown target specification %r" % spec) rv = sk @@ -66,13 +71,19 @@ class client(object): if proto is not None: self.select(proto) + @property + def closed(self): + return self.sk is None + def close(self): """Close this connection""" - self.sk.close() + if self.sk is not None: + self.sk.close() + self.sk = None def fileno(self): """Return the file descriptor of the underlying socket.""" - return self.sk.fileno() + return self.sk.fileno() if self.sk else None def readline(self): """Read a single NL-terminated line and return it.""" @@ -192,7 +203,8 @@ class perfproxy(object): def close(self): if self.id is not None: - self.cl.run("unbind", self.id) + if not self.cl.closed: + self.cl.run("unbind", self.id) del self.cl.proxies[self.id] self.id = None @@ -319,7 +331,7 @@ class perfclient(client): used by the server process. The proxy objects returned by this function are cached and the - same object are returned the next time the same name is + same object is returned the next time the same name is requested, which means that they are kept live until the client connection is closed. """