def c_repo_check (self, a, **kw) : if not self._config_db.is_remote_repository(a[0]) : _path = self._config_db.get_repository_property(a[0], "path", ) if not os.path.exists(_path, ) or not os.path.isdir(_path, ) : return ("error: '%s' is not valid repository directory, check it." % _path, ) return ("'%s' is valid repository path." % _path, ) _path = self._config_db.get_repository_property(a[0], "path", ) _parsed = utils.parse_remote_repository(_path, ) from ssh_factory import SSHClient _client = SSHClient( None, _parsed.get("host"), _parsed.get("port", ), _parsed.get("user"), self._config_db.get_repository_property(a[0], "password", None, ), ) def _cb_open_session (r, ) : _client.close() return ("remote repository, '%s'('%s') is accessible." % (a[0], _path, ), ) def _eb_open_session (f, ) : _client.close() _r = ["error: remote repository, '%s'('%s') can not be accessible." % (a[0], _path, ), ] _e = None if f.check(error_internet.DNSLookupError, ) : _e = f.value.message elif f.check(error_conch.ConchError, ) : _e = "authentication failed, check the username or password." if _e : _r.append("\t- %s" % _e) return _r return _client.connect().addCallbacks(_cb_open_session, _eb_open_session, )
def c_repo_add_remote (self, a, **kw) : a = list(a) a.extend(["", "", ]) (_uri, _password, _alias, ) = a[:3] _description = a[3:] _parsed = utils.parse_remote_repository(_uri, ) if not _parsed.get("user") : raise _exceptions.BAD_ARGUMENT("`user` must be set, like `<user>@<host>`") if not _alias.strip() : if not self._config_db.has_repository(_parsed.get("path"), ) : _alias = _parsed.get("path") else : _alias = "/" + uuid.uuid1().hex _a = [_uri, _alias, ] self._config_db.add_repository(*_a, **dict( description=_description, password=_password, )).save() _l = ["remote repository, '%s', alias, '%s' was added." % (_uri, _alias, ), "", ] _l.extend(list(self.c_repo_list(None, **kw)), ) return tuple(_l)
def parse_remote_repository (self, alias, ) : if not self.is_remote_repository(alias, ) : raise ValueError("'%s' is not remote repository path." % alias, ) return utils.parse_remote_repository(self.get_repository_property(alias, "path", ), )