Пример #1
0
def add_repo(name, indexuri, at=None):
    if ctx.repodb.has_repo(name):
        raise Error(_('Repo %s already present.') % name)
    else:
        repo = db.repo.Repo(URI(indexuri))
        ctx.repodb.add_repo(name, repo, at=at)
        ctx.ui.info(_('Repo %s added to system.') % name)
Пример #2
0
 def make_uri(uri):
     "handle URI arg"
     if type(uri) == types.StringType or type(uri) == types.UnicodeType:
         uri = URI(uri)
     elif not isinstance(uri, URI):
         raise Error(_("uri must have type either URI or string"))
     return uri
Пример #3
0
 def check_signature(uri, transfer_dir, sign=detached):
     if sign == File.detached:
         try:
             sigfilename = File.download(URI(uri + '.sig'), transfer_dir)
         except:
             raise NoSignatureFound(uri)
         if os.system('gpg --verify ' + sigfilename) != 0:
             raise InvalidSignature(uri)
Пример #4
0
 def set_spec_file(self, specuri):
     if not specuri.is_remote_file():
         # FIXME: doesn't work for file://
         specuri = URI(os.path.realpath(specuri.get_uri()))
     self.specuri = specuri
     spec = SpecFile()
     spec.read(specuri, ctx.config.tmp_dir())
     self.spec = spec
Пример #5
0
    def formatRequest(self, request):
        if self.url.auth_info():
            enc = encodestring('%s:%s' % self.url.auth_info())
            request.add_header('Authorization', 'Basic %s' % enc)

        range_handlers = {
            'http': HTTPRangeHandler,
            'https': HTTPRangeHandler,
            'ftp': FTPRangeHandler
        }

        if self.exist_size and range_handlers.has_key(self.scheme):
            opener = urllib2.build_opener(range_handlers.get(self.scheme)())
            urllib2.install_opener(opener)
            request.add_header('Range', 'bytes=%d-' % self.exist_size)

        proxy_handler = None

        if ctx.config.values.general.http_proxy and self.url.scheme(
        ) == "http":
            http_proxy = ctx.config.values.general.http_proxy
            proxy_handler = urllib2.ProxyHandler(
                {URI(http_proxy).scheme(): http_proxy})

        elif ctx.config.values.general.https_proxy and self.url.scheme(
        ) == "https":
            https_proxy = ctx.config.values.general.https_proxy
            proxy_handler = urllib2.ProxyHandler(
                {URI(https_proxy): https_proxy})

        elif ctx.config.values.general.ftp_proxy and self.url.scheme(
        ) == "ftp":
            ftp_proxy = ctx.config.values.general.ftp_proxy
            proxy_handler = urllib2.ProxyHandler({URI(http_proxy): ftp_proxy})

        if proxy_handler:
            ctx.ui.info(
                _("Proxy configuration has been found for '%s' protocol") %
                self.url.scheme())
            opener = urllib2.build_opener(proxy_handler)
            urllib2.install_opener(opener)

        return request
Пример #6
0
def install_single(pkg, upgrade=False):
    """install a single package from URI or ID"""
    url = URI(pkg)
    # Check if we are dealing with a remote file or a real path of
    # package filename. Otherwise we'll try installing a package from
    # the package repository.
    if url.is_remote_file() or os.path.exists(url.uri):
        install_single_file(pkg, upgrade)
    else:
        install_single_name(pkg, upgrade)
Пример #7
0
    def download(uri,
                 transfer_dir="/tmp",
                 sha1sum=False,
                 compress=None,
                 sign=None,
                 copylocal=False):

        assert isinstance(uri, URI)

        if sha1sum:
            sha1filename = File.download(URI(uri.get_uri() + '.sha1sum'),
                                         transfer_dir)
            sha1f = file(sha1filename)
            newsha1 = sha1f.readlines()[0]

        if uri.is_remote_file() or copylocal:
            localfile = join(transfer_dir, uri.filename())

            # TODO: code to use old .sha1sum file, is this a necessary optimization?
            #oldsha1fn = localfile + '.sha1sum'
            #if os.exists(oldsha1fn):
            #oldsha1 = file(oldsha1fn).readlines()[0]
            if sha1sum and os.path.exists(localfile):
                oldsha1 = pisi.util.sha1_file(localfile)
                if (newsha1 == oldsha1):
                    # early terminate, we already got it ;)
                    raise AlreadyHaveException(uri, localfile)

            if uri.is_remote_file():
                ctx.ui.info(_("Fetching %s") % uri.get_uri(), verbose=True)
                fetch_url(uri, transfer_dir, ctx.ui.Progress)
            else:
                # copy to transfer dir,
                localfile = join(transfer_dir, uri.filename())
                ctx.ui.info(_("Copying %s to transfer dir") % uri.get_uri(),
                            verbose=True)
                shutil.copy(uri.get_uri(), transfer_dir)
        else:
            localfile = uri.get_uri()  #TODO: use a special function here?
            if not os.path.exists(localfile):
                raise IOError(_("File '%s' not found.") % localfile)
            if not os.access(localfile, os.W_OK):
                oldfn = localfile
                localfile = join(transfer_dir, os.path.basename(localfile))
                shutil.copy(oldfn, localfile)

        if sha1sum:
            if (pisi.util.sha1_file(localfile) != newsha1):
                raise Error(_("File integrity of %s compromised.") % uri)

        localfile = File.decompress(localfile, compress)

        return localfile
Пример #8
0
    def __init__(self, url, destdir, resume=True):
        if not isinstance(url, URI):
            url = URI(url)

        if ctx.config.get_option("authinfo"):
            url.set_auth_info(ctx.config.get_option("authinfo"))

        self.resume = resume
        self.scheme = url.scheme()
        self.url = url
        self.destdir = destdir
        util.check_dir(self.destdir)
        self.eta = '??:??:??'
        self.percent = 0
        self.rate = 0.0
        self.progress = None
        self.exist_size = 0
Пример #9
0
 def fetch_component(self):
     if not self.spec.source.partOf:
         ctx.ui.warning(_('PartOf tag not defined, looking for component'))
         diruri = parenturi(self.specuri.get_uri())
         parentdir = parenturi(diruri)
         url = util.join_path(parentdir, 'component.xml')
         progress = ctx.ui.Progress
         if URI(url).is_remote_file():
             fetch_url(url, self.pkg_work_dir(), progress)
             path = util.join_path(self.pkg_work_dir(), 'component.xml')
         else:
             if not os.path.exists(url):
                 raise Exception(
                     _('Cannot find component.xml in upper directory'))
             path = url
         comp = component.Component()
         comp.read(path)
         ctx.ui.info(_('Source is part of %s component') % comp.name)
         self.spec.source.partOf = comp.name
         self.spec.override_tags()
Пример #10
0
def rebuild_repo(repo):
    ctx.ui.info(_('* Rebuilding \'%s\' named repo... ') % repo, noln=True)

    if ctx.repodb.has_repo(repo):
        repouri = URI(ctx.repodb.get_repo(repo).indexuri.get_uri())
        indexname = repouri.filename()
        index = Index()
        indexpath = pisi.util.join_path(ctx.config.index_dir(), repo,
                                        indexname)
        tmpdir = os.path.join(ctx.config.tmp_dir(), 'index')
        pisi.util.clean_dir(tmpdir)
        pisi.util.check_dir(tmpdir)
        try:
            index.read_uri(indexpath, tmpdir,
                           force=True)  # don't look for sha1sum there
        except IOError, e:
            ctx.ui.warning(
                _("Input/Output error while reading %s: %s") %
                (indexpath, unicode(e)))
            return
        ctx.txn_proc(lambda txn: index.update_db(repo, txn=txn))
        ctx.ui.info(_('OK.'))
Пример #11
0
    def __init__(self, specuri):

        # process args
        if not isinstance(specuri, URI):
            specuri = URI(specuri)

        # read spec file, we'll need it :)
        self.set_spec_file(specuri)

        if specuri.is_remote_file():
            #make local here and f**k up
            self.specdir = self.fetch_files()
        else:
            self.specdir = dirname(self.specuri.get_uri())

        self.sourceArchive = SourceArchive(self.spec, self.pkg_work_dir())

        self.set_environment_vars()

        self.actionLocals = None
        self.actionGlobals = None
        self.srcDir = None
Пример #12
0
    def from_name(name):
        # download package and return an installer object
        # find package in repository
        sf, reponame = ctx.sourcedb.get_spec_repo(name)
        src = sf.source
        if src:

            src_uri = URI(src.sourceURI)
            if src_uri.is_absolute_path():
                src_path = str(src_uri)
            else:
                repo = ctx.repodb.get_repo(reponame)
                #FIXME: don't use dirname to work on URLs
                src_path = os.path.join(
                    os.path.dirname(repo.indexuri.get_uri()),
                    str(src_uri.path()))

            ctx.ui.debug(_("Source URI: %s") % src_path)

            return Builder(src_path)
        else:
            raise Error(
                _("Source %s not found in any active repository.") % name)
Пример #13
0
    def from_name(name, ignore_dep=None):
        # download package and return an installer object
        # find package in repository
        repo = ctx.packagedb.which_repo(name)
        if repo:
            ctx.ui.info(_("Package %s found in repository %s") % (name, repo))
            repo = ctx.repodb.get_repo(repo)
            pkg = ctx.packagedb.get_package(name)

            # FIXME: let pkg.packageURI be stored as URI type rather than string
            pkg_uri = URI(pkg.packageURI)
            if pkg_uri.is_absolute_path():
                pkg_path = str(pkg.packageURI)
            else:
                pkg_path = os.path.join(
                    os.path.dirname(repo.indexuri.get_uri()),
                    str(pkg_uri.path()))

            ctx.ui.info(_("Package URI: %s") % pkg_path, verbose=True)

            return Install(pkg_path, ignore_dep)
        else:
            raise Error(
                _("Package %s not found in any active repository.") % name)
Пример #14
0
 def __init__(self, spec, pkg_work_dir):
     self.url = URI(spec.source.archive.uri)
     self.pkg_work_dir = pkg_work_dir
     self.archiveFile = join(ctx.config.archives_dir(), self.url.filename())
     self.archive = spec.source.archive