예제 #1
0
def urlopen(absurl, repo=None, mode='w+b', **kwargs):
    """Open the specified absolute url, return a file object.

    repo -- Use this repo-specific config (proxies, certs)
    kwargs -- These are passed to TemporaryFile
    """

    def build_default_handle():
        handle = librepo.Handle()
        handle.useragent = dnf.const.USER_AGENT
        return handle

    if PY3 and 'b' not in mode:
        kwargs.setdefault('encoding', 'utf-8')
    fo = tempfile.NamedTemporaryFile(mode, **kwargs)
    if repo:
        handle = repo.get_handle()
    else:
        handle = build_default_handle()
    try:
        librepo.download_url(absurl, fo.fileno(), handle)
    except librepo.LibrepoException as e:
        raise IOError(e.args[1])
    fo.seek(0)
    return fo
예제 #2
0
def urlopen(plugin, repo, url, mode='w+b', **kwargs):
    """
    # :api
    modified dnf.util.urlopen() which respects proxy setting
    even for non-repo downloads
    """
    conf = plugin.base.conf

    def non_repo_handle():
        handle = librepo.Handle()
        handle.useragent = dnf.const.USER_AGENT
        # see dnf.repo.Repo._handle_new_remote() how to pass
        handle.maxspeed = conf.throttle if type(conf.throttle) is int \
                     else int(conf.bandwidth * conf.throttle)
        handle.proxy = conf.proxy
        handle.proxyuserpwd = dnf.repo._user_pass_str(conf.proxy_username,
                                                      conf.proxy_password)
        handle.sslverifypeer = handle.sslverifyhost = conf.sslverify
        return handle

    if PY3 and 'b' not in mode:
        kwargs.setdefault('encoding', 'utf-8')
    fo = tempfile.NamedTemporaryFile(mode, **kwargs)
    if repo:
        handle = repo.get_handle()
    else:
        handle = non_repo_handle()
    try:
        librepo.download_url(url, fo.fileno(), handle)
    except librepo.LibrepoException as e:
        raise IOError(e.args[1])
    fo.seek(0)
    return fo
예제 #3
0
파일: util.py 프로젝트: gbraad/dnf
def urlopen(absurl, repo=None, mode='w+b', **kwargs):
    """Open the specified absolute url, return a file object.

    repo -- Use this repo-specific config (proxies, certs)
    kwargs -- These are passed to TemporaryFile
    """

    def build_default_handle():
        handle = librepo.Handle()
        handle.useragent = dnf.const.USER_AGENT
        return handle

    if PY3 and 'b' not in mode:
        kwargs.setdefault('encoding', 'utf-8')
    fo = tempfile.NamedTemporaryFile(mode, **kwargs)
    if repo:
        handle = repo.get_handle()
    else:
        handle = build_default_handle()
    try:
        librepo.download_url(absurl, fo.fileno(), handle)
    except librepo.LibrepoException as e:
        raise IOError(e.args[1])
    fo.seek(0)
    return fo
예제 #4
0
def urlopen(plugin, repo, url, mode='w+b', **kwargs):
    """
    # :api
    modified dnf.util.urlopen() which respects proxy setting
    even for non-repo downloads
    """
    conf = plugin.base.conf

    def non_repo_handle():
        handle = librepo.Handle()
        handle.useragent = dnf.const.USER_AGENT
        # see dnf.repo.Repo._handle_new_remote() how to pass
        handle.maxspeed = conf.throttle if type(conf.throttle) is int \
                     else int(conf.bandwidth * conf.throttle)
        handle.proxy = conf.proxy
        handle.proxyuserpwd = dnf.repo._user_pass_str(conf.proxy_username,
                                                      conf.proxy_password)
        handle.sslverifypeer = handle.sslverifyhost = conf.sslverify
        return handle

    if PY3 and 'b' not in mode:
        kwargs.setdefault('encoding', 'utf-8')
    fo = tempfile.NamedTemporaryFile(mode, **kwargs)
    if repo:
        handle = repo.get_handle()
    else:
        handle = non_repo_handle()
    try:
        librepo.download_url(url, fo.fileno(), handle)
    except librepo.LibrepoException as e:
        raise IOError(e.args[1])
    fo.seek(0)
    return fo
예제 #5
0
파일: util.py 프로젝트: ryanuber/dnf
def urlopen(absurl, **opts):
    """Open the specified absolute url, return a file object.
       'opts' argument is not used atm.
    """
    fo = tempfile.TemporaryFile()
    librepo.download_url(absurl, fo.fileno(), default_handle)
    fo.seek(0)
    return fo
예제 #6
0
def download_2():
    """Handle could be used if you need specify some network
    options like proxy server etc."""

    # NOTE: LRO_URLS and LRO_MIRRORLIST options of the handle are ignored!!

    h = librepo.Handle()
    #h.setopt(librepo.LRO_PROXY, "http://foo.proxy.bar:8080")

    fd = os.open(DEST_FN_2, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0666)
    librepo.download_url(URL, fd, handle=h)
예제 #7
0
def download_2():
    """Handle could be used if you need specify some network
    options like proxy server etc."""

    # NOTE: LRO_URLS and LRO_MIRRORLIST options of the handle are ignored!!

    h = librepo.Handle()
    #h.setopt(librepo.LRO_PROXY, "http://foo.proxy.bar:8080")

    fd = os.open(DEST_FN_2, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0666)
    librepo.download_url(URL, fd, handle=h)
예제 #8
0
    def http_download_file(option, pkgname):
        url = srcdir_path + '/' + pkgname
        file_name = destdir_path + '/' + pkgname

        try:
            """Example of the simplest usage"""
            fd = os.open(file_name, os.O_RDWR | os.O_CREAT | os.O_TRUNC)
            librepo.download_url(url, fd)
            os.close(fd)
            logger.info(_("%s http download is OK."), pkgname)
        except librepo.LibrepoException as e:
            logger.error(_("%s."), e.args[1])
            os.remove(file_name)
            return
예제 #9
0
파일: util.py 프로젝트: rhn/dnf
def _urlopen(url, conf=None, repo=None, mode='w+b', **kwargs):
    """
    Open the specified absolute url, return a file object
    which respects proxy setting even for non-repo downloads
    """
    if PY3 and 'b' not in mode:
        kwargs.setdefault('encoding', 'utf-8')
    fo = tempfile.NamedTemporaryFile(mode, **kwargs)
    if repo:
        handle = repo._get_handle()
    else:
        handle = _non_repo_handle(conf)
    try:
        librepo.download_url(url, fo.fileno(), handle)
    except librepo.LibrepoException as e:
        raise IOError(e.args[1])
    fo.seek(0)
    return fo
예제 #10
0
파일: util.py 프로젝트: xyxel/dnf
def urlopen(absurl, repo=None):
    """Open the specified absolute url, return a file object.

    repo -- Use this repo-specific config (proxies, certs)
    """
    if PY3:
        fo = tempfile.TemporaryFile(mode='w+', encoding='utf-8')
    else:
        fo = tempfile.TemporaryFile()
    handle = default_handle
    if repo:
        handle = repo.get_handle()
    try:
        librepo.download_url(absurl, fo.fileno(), handle)
    except librepo.LibrepoException as e:
        raise IOError(e.args[1])
    fo.seek(0)
    return fo
예제 #11
0
파일: util.py 프로젝트: lubomir/dnf
def _urlopen(url, conf=None, repo=None, mode='w+b', **kwargs):
    """
    Open the specified absolute url, return a file object
    which respects proxy setting even for non-repo downloads
    """
    if PY3 and 'b' not in mode:
        kwargs.setdefault('encoding', 'utf-8')
    fo = tempfile.NamedTemporaryFile(mode, **kwargs)
    if repo:
        handle = repo._get_handle()
    else:
        handle = _non_repo_handle(conf)
    try:
        librepo.download_url(url, fo.fileno(), handle)
    except librepo.LibrepoException as e:
        raise IOError(e.args[1])
    fo.seek(0)
    return fo
예제 #12
0
    def from_url(cls, url, force=False):
        """

        :param url: URL
        :type url: str
        :param force: Silently ignore invalid records
        :type force: bool
        :return:
        """
        # TODO: support for metalink and mirrorlist
        fd, fn = tempfile.mkstemp(prefix="deltarepos.xml.xz-", dir="/tmp")

        # Download deltarepos.xml
        deltarepos_xml_url = os.path.join(url, "deltarepos.xml.xz")
        try:
            librepo.download_url(deltarepos_xml_url, fd)
        except librepo.LibrepoException as e:
            os.remove(fn)
            raise DeltaRepoError("Cannot download {0}: {1}".format(
                deltarepos_xml_url, e))

        # Parse deltarepos.xml
        dr = DeltaRepos()
        try:
            dr.load(fn, pedantic=(not force))
        except DeltaRepoError as e:
            raise DeltaRepoError("Error while parsing deltarepos.xml "
                                 "from {0}: {1}".format(deltarepos_xml_url, e))
        finally:
            os.remove(fn)

        # Fill and return DRMirror object
        drm = cls()
        drm.url = url               # Url of the mirror
        drm.deltarepos = dr         # DeltaRepos object

        for record in dr.records:
            try:
                record.validate()
            except (ValueError, TypeError):
                continue
            drm.records.append(record)

        return drm
예제 #13
0
    def from_url(cls, url, force=False):
        """

        :param url: URL
        :type url: str
        :param force: Silently ignore invalid records
        :type force: bool
        :return:
        """
        # TODO: support for metalink and mirrorlist
        fd, fn = tempfile.mkstemp(prefix="deltarepos.xml.xz-", dir="/tmp")

        # Download deltarepos.xml
        deltarepos_xml_url = os.path.join(url, "deltarepos.xml.xz")
        try:
            librepo.download_url(deltarepos_xml_url, fd)
        except librepo.LibrepoException as e:
            os.remove(fn)
            raise DeltaRepoError("Cannot download {0}: {1}".format(
                deltarepos_xml_url, e))

        # Parse deltarepos.xml
        dr = DeltaRepos()
        try:
            dr.load(fn, pedantic=(not force))
        except DeltaRepoError as e:
            raise DeltaRepoError("Error while parsing deltarepos.xml "
                                 "from {0}: {1}".format(deltarepos_xml_url, e))
        finally:
            os.remove(fn)

        # Fill and return DRMirror object
        drm = cls()
        drm.url = url  # Url of the mirror
        drm.deltarepos = dr  # DeltaRepos object

        for record in dr.records:
            try:
                record.validate()
            except (ValueError, TypeError):
                continue
            drm.records.append(record)

        return drm
예제 #14
0
파일: util.py 프로젝트: auchytil/dnf
def urlopen(absurl, repo=None, **kwargs):
    """Open the specified absolute url, return a file object.

    repo -- Use this repo-specific config (proxies, certs)
    kwargs -- These are passed to TemporaryFile
    """
    if PY3:
        kwargs['mode'] = 'w+'
        kwargs['encoding'] = 'utf-8'
    fo = tempfile.NamedTemporaryFile(**kwargs)
    handle = default_handle
    if repo:
        handle = repo.get_handle()
    try:
        librepo.download_url(absurl, fo.fileno(), handle)
    except librepo.LibrepoException as e:
        raise IOError(e.args[1])
    fo.seek(0)
    return fo
예제 #15
0
def urlopen(absurl, repo=None, **kwargs):
    """Open the specified absolute url, return a file object.

    repo -- Use this repo-specific config (proxies, certs)
    kwargs -- These are passed to TemporaryFile
    """
    if PY3:
        kwargs['mode'] = 'w+'
        kwargs['encoding'] = 'utf-8'
    fo = tempfile.NamedTemporaryFile(**kwargs)
    handle = default_handle
    if repo:
        handle = repo.get_handle()
    try:
        librepo.download_url(absurl, fo.fileno(), handle)
    except librepo.LibrepoException as e:
        raise IOError(e.args[1])
    fo.seek(0)
    return fo
예제 #16
0
def download_1():
    """Example of the simplest usage"""
    fd = os.open(DEST_FN_1, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0666)
    librepo.download_url(URL, fd)
예제 #17
0
def download_1():
    """Example of the simplest usage"""
    fd = os.open(DEST_FN_1, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0666)
    librepo.download_url(URL, fd)