def create_repo(name, alias, priority, gpgchk, url): repo = zypp.RepoInfo() repo.setBaseUrl(zypp.Url(url)) repo.setEnabled(True) repo.setName(name) repo.setPriority(priority) repo.setAutorefresh(True) repo.setGpgCheck(gpgchk) repo.setAlias(alias) repo.setKeepPackages(False) return repo
def addRepository(self, name, url=None, mirrorlist=None, proxy=None, proxy_username=None, proxy_password=None, inc=None, exc=None, ssl_verify=True, cost=None, priority=None): # TODO: Handle cost attribute for repos if not self.repo_manager: self.__initialize_repo_manager() repo = RepositoryStub() repo.name = name repo.id = name repo.proxy = proxy repo.proxy_username = proxy_username repo.proxy_password = proxy_password repo.ssl_verify = ssl_verify repo.baseurl.append(url) if inc: for pkg in inc: self.incpkgs[pkg] = name if exc: for pkg in exc: self.excpkgs[pkg] = name # check LICENSE files if not rpmmisc.checkRepositoryEULA(name, repo): msger.warning('skip repo:%s for failed EULA confirmation' % name) return None if mirrorlist: repo.mirrorlist = mirrorlist # Enable gpg check for verifying corrupt packages repo.gpgcheck = 1 if priority: repo.priority = priority self.repos.append(repo) try: repo_info = zypp.RepoInfo() repo_info.setAlias(repo.name) repo_info.setName(repo.name) repo_info.setEnabled(repo.enabled) repo_info.setAutorefresh(repo.autorefresh) repo_info.setKeepPackages(repo.keeppackages) baseurl = zypp.Url(repo.baseurl[0]) if not ssl_verify: baseurl.setQueryParam("ssl_verify", "no") if proxy: (scheme, host, path, parm, query, frag) = urlparse.urlparse(proxy) proxyinfo = host.split(":") baseurl.setQueryParam("proxy", proxyinfo[0]) port = "80" if len(proxyinfo) > 1: port = proxyinfo[1] baseurl.setQueryParam("proxyport", port) repo_info.addBaseUrl(baseurl) if repo.priority: repo_info.setPriority(repo.priority) self.repo_manager.addRepository(repo_info) self.__build_repo_cache(name) except RuntimeError, e: raise CreatorError(str(e))
def addRepository(self, name, url = None, mirrorlist = None, proxy = None, proxy_username = None, proxy_password = None, inc = None, exc = None, ssl_verify = True, nocache = False, cost=None, priority=None): # TODO: Handle cost attribute for repos if not self.repo_manager: self.__initialize_repo_manager() if not proxy and url: proxy = get_proxy_for(url) repo = RepositoryStub() repo.name = name repo.id = name repo.proxy = proxy repo.proxy_username = proxy_username repo.proxy_password = proxy_password repo.ssl_verify = ssl_verify repo.nocache = nocache repo.baseurl.append(url) if inc: for pkg in inc: self.incpkgs[pkg] = name if exc: for pkg in exc: self.excpkgs[pkg] = name if mirrorlist: repo.mirrorlist = mirrorlist # Enable gpg check for verifying corrupt packages repo.gpgcheck = 1 if priority is not None: # priority 0 has issue in RepoInfo.setPriority repo.priority = priority + 1 try: repo_info = zypp.RepoInfo() repo_info.setAlias(repo.name) repo_info.setName(repo.name) repo_info.setEnabled(repo.enabled) repo_info.setAutorefresh(repo.autorefresh) repo_info.setKeepPackages(repo.keeppackages) baseurl = zypp.Url(repo.baseurl[0].full) if not ssl_verify: baseurl.setQueryParam("ssl_verify", "no") if proxy: host = urlparse.urlparse(proxy)[1] # scheme, host, path, parm, query, frag = urlparse.urlparse(proxy) proxyinfo = host.rsplit(":", 1) host = proxyinfo[0] port = "80" if len(proxyinfo) > 1: port = proxyinfo[1] if proxy.startswith("socks") and len(proxy.rsplit(':', 1)) == 2: host = proxy.rsplit(':', 1)[0] port = proxy.rsplit(':', 1)[1] # parse user/pass from proxy host proxyinfo = host.rsplit("@", 1) if len(proxyinfo) == 2: host = proxyinfo[1] # Known Issue: If password contains ":", which should be # quoted, for example, use '123%3Aabc' instead of 123:abc userpassinfo = proxyinfo[0].rsplit(":", 1) if len(userpassinfo) == 2: proxy_username = userpassinfo[0] proxy_password = userpassinfo[1] elif len(userpassinfo) == 1: proxy_username = userpassinfo[0] baseurl.setQueryParam ("proxy", host) baseurl.setQueryParam ("proxyport", port) if proxy_username: baseurl.setQueryParam ("proxyuser", proxy_username) if proxy_password: baseurl.setQueryParam ("proxypass", proxy_password) else: baseurl.setQueryParam ("proxy", "_none_") self.repos.append(repo) repo_info.addBaseUrl(baseurl) if repo.priority is not None: repo_info.setPriority(repo.priority) # this hack is used to change zypp credential file location # the default one is $HOME/.zypp, which cause conflicts when # installing some basic packages, and the location doesn't # have any interface actually, so use a tricky way anyway homedir = None if 'HOME' in os.environ: homedir = os.environ['HOME'] os.environ['HOME'] = '/' else: os.environ['HOME'] = '/' self.repo_manager.addRepository(repo_info) # save back the $HOME env if homedir: os.environ['HOME'] = homedir else: del os.environ['HOME'] self.__build_repo_cache(name) except RuntimeError, e: raise CreatorError(str(e))
def _zypp_url(self, url): return zypp.Url(url) if url else zypp.Url()
def addRepository(self, name, url=None, mirrorlist=None, proxy=None, proxy_username=None, proxy_password=None, inc=None, exc=None, ssl_verify=True, nocache=False, cost=None, priority=None): # TODO: Handle cost attribute for repos if not self.repo_manager: self.__initialize_repo_manager() if not proxy and url: proxy = get_proxy_for(url) repo = RepositoryStub() repo.name = name repo.id = name repo.proxy = proxy repo.proxy_username = proxy_username repo.proxy_password = proxy_password repo.ssl_verify = ssl_verify repo.nocache = nocache repo.baseurl.append(url) if inc: for pkg in inc: self.incpkgs[pkg] = name if exc: for pkg in exc: self.excpkgs[pkg] = name # check LICENSE files if not rpmmisc.checkRepositoryEULA(name, repo): msger.warning('skip repo:%s for failed EULA confirmation' % name) return None if mirrorlist: repo.mirrorlist = mirrorlist # Enable gpg check for verifying corrupt packages repo.gpgcheck = 1 if priority is not None: # priority 0 has issue in RepoInfo.setPriority repo.priority = priority + 1 try: repo_info = zypp.RepoInfo() repo_info.setAlias(repo.name) repo_info.setName(repo.name) repo_info.setEnabled(repo.enabled) repo_info.setAutorefresh(repo.autorefresh) repo_info.setKeepPackages(repo.keeppackages) baseurl = zypp.Url(repo.baseurl[0]) if not ssl_verify: baseurl.setQueryParam("ssl_verify", "no") if proxy: scheme, host, path, parm, query, frag = urlparse.urlparse( proxy) proxyinfo = host.split(":") host = proxyinfo[0] port = "80" if len(proxyinfo) > 1: port = proxyinfo[1] if proxy.startswith("socks") and len(proxy.rsplit(':', 1)) == 2: host = proxy.rsplit(':', 1)[0] port = proxy.rsplit(':', 1)[1] baseurl.setQueryParam("proxy", host) baseurl.setQueryParam("proxyport", port) repo.baseurl[0] = baseurl.asCompleteString() self.repos.append(repo) repo_info.addBaseUrl(baseurl) if repo.priority is not None: repo_info.setPriority(repo.priority) # this hack is used to change zypp credential file location # the default one is $HOME/.zypp, which cause conflicts when # installing some basic packages, and the location doesn't # have any interface actually, so use a tricky way anyway homedir = None if 'HOME' in os.environ: homedir = os.environ['HOME'] os.environ['HOME'] = '/' else: os.environ['HOME'] = '/' self.repo_manager.addRepository(repo_info) # save back the $HOME env if homedir: os.environ['HOME'] = homedir else: del os.environ['HOME'] self.__build_repo_cache(name) except RuntimeError, e: raise CreatorError(str(e))