Ejemplo n.º 1
0
    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 priority attribute for repos
        def _varSubstitute(option):
            # takes a variable and substitutes like yum configs do
            option = option.replace("$basearch", rpmUtils.arch.getBaseArch())
            option = option.replace("$arch", rpmUtils.arch.getCanonArch())
            return option

        repo = MyYumRepository(name)

        # Set proxy
        repo.proxy = proxy
        repo.proxy_username = proxy_username
        repo.proxy_password = proxy_password

        if url:
            repo.baseurl.append(_varSubstitute(url))

        # 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 = _varSubstitute(mirrorlist)

        conf = yum.config.RepoConf()
        for k, v in conf.iteritems():
            if v or not hasattr(repo, k):
                repo.setAttribute(k, v)

        repo.sslverify = ssl_verify
        repo.cache = not nocache

        repo.basecachedir = self.cachedir
        repo.base_persistdir = self.conf.persistdir
        repo.failovermethod = "priority"
        repo.metadata_expire = 0
        # Enable gpg check for verifying corrupt packages
        repo.gpgcheck = 1
        repo.enable()
        repo.setup(0)
        self.repos.add(repo)
        if cost:
            repo.cost = cost

        msger.verbose('repo: %s was added' % name)
        return repo
Ejemplo n.º 2
0
    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 priority attribute for repos
        def _varSubstitute(option):
            # takes a variable and substitutes like yum configs do
            option = option.replace("$basearch", rpmUtils.arch.getBaseArch())
            option = option.replace("$arch", rpmUtils.arch.getCanonArch())
            return option

        repo = MyYumRepository(name)

        # Set proxy
        repo.proxy = proxy
        repo.proxy_username = proxy_username
        repo.proxy_password = proxy_password

        if url:
            repo.baseurl.append(_varSubstitute(url))

        # 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 = _varSubstitute(mirrorlist)

        conf = yum.config.RepoConf()
        for k, v in conf.iteritems():
            if v or not hasattr(repo, k):
                repo.setAttribute(k, v)

        repo.sslverify = ssl_verify
        repo.cache = not nocache

        repo.basecachedir = self.cachedir
        repo.base_persistdir = self.conf.persistdir
        repo.failovermethod = "priority"
        repo.metadata_expire = 0
        # Enable gpg check for verifying corrupt packages
        repo.gpgcheck = 1
        repo.enable()
        repo.setup(0)
        self.repos.add(repo)
        if cost:
            repo.cost = cost

        msger.verbose('repo: %s was added' % name)
        return repo
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
    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))
Ejemplo n.º 5
0
    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()

        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.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(":")
                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_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))
Ejemplo n.º 6
0
    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))