How to use the pkgbuilder.exceptions.NetworkError function in pkgbuilder

To help you get started, we’ve selected a few pkgbuilder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kwpolska / pkgbuilder / pkgbuilder / build.py View on Github external
pkgname, 'fetch')

        for pkg in allpkgs:
            if pkg.is_abs:
                abspkgs.append(pkg)
            else:
                aurpkgs.append(pkg)

        if abspkgs:
            print(_(':: Retrieving packages from asp...'))
            pm = pkgbuilder.ui.Progress(len(abspkgs))
            for pkg in abspkgs:
                pm.msg(_('retrieving {0}').format(pkg.name), True)
                rc = asp_export(pkg)
                if rc > 0:
                    raise pkgbuilder.exceptions.NetworkError(
                        _('Failed to retieve {0} (from ASP).').format(
                            pkg.name), source='asp', pkg=pkg, retcode=rc)

        if aurpkgs:
            print(_(':: Retrieving packages from aur...'))
            pm = pkgbuilder.ui.Progress(len(aurpkgs))
            for pkg in aurpkgs:
                pm.msg(_('cloning {0}').format(pkg.packagebase), True)
                clone(pkg.packagebase)

        print(_('Successfully fetched: ') + ' '.join(pkgnames))
    except pkgbuilder.exceptions.PBException as e:
        print(':: ERROR: ' + str(e.msg))
        exit(1)
github Kwpolska / pkgbuilder / pkgbuilder / main.py View on Github external
sigs += out[1][1]
                except PBException as e:
                    DS.fancy_error(str(e))
                    if e.exit:
                        exit(1)

            if toinstall:
                pkgbuilder.build.install(toinstall, sigs, asdeps=False)

            if args.validate and tovalidate:
                qs = pkgbuilder.build.validate(tovalidate)
                if quit:
                    DS.log.info('Quitting peacefully.')
                    exit(qs)

    except NetworkError as e:
        DS.fancy_error(str(e))
        # TRANSLATORS: do not translate the word 'requests'.
        DS.fancy_error(_('PKGBUILDer (or the requests library) had '
                         'problems with fulfilling an HTTP request.'))
        if e.exit:
            exit(1)
    except PBException as e:
        DS.fancy_error(str(e))
        if e.exit:
            exit(1)

    DS.log.info('Quitting peacefully.')
github Kwpolska / pkgbuilder / pkgbuilder / build.py View on Github external
subpackages = [pkg.name]  # no way to get it
    if not pkg:
        raise pkgbuilder.exceptions.PackageNotFoundError(pkgname, 'build')

    DS.fancy_msg(_('Building {0}...').format(pkg.name))
    pkgbuilder.utils.print_package_search(pkg,
                                          prefix=DS.colors['blue'] +
                                          '  ->' + DS.colors['all_off'] +
                                          DS.colors['bold'] + ' ',
                                          prefixp='  -> ')
    sys.stdout.write(DS.colors['all_off'])
    if pkg.is_abs:
        DS.fancy_msg(_('Retrieving from ASP...'))
        rc = asp_export(pkg)
        if rc > 0:
            raise pkgbuilder.exceptions.NetworkError(
                _('Failed to retieve {0} (from ASP).').format(
                    pkg.name), source='asp', pkg=pkg, retcode=rc)

        existing = find_packagefile(pkg.name)
        if any(pkg.name in i for i in existing[0]):
            DS.fancy_msg(_('Found an existing package for '
                           '{0}').format(pkgname))
            if not pkginstall:
                existing = ([], [])
            return [RES_EXISTING, existing]
        try:
            os.chdir('./{0}'.format(pkg.name))
        except FileNotFoundError:
            raise pkgbuilder.exceptions.PBException(
                'The package download failed.\n    This package might '
                'be generated from a split PKGBUILD.  Please find out the '
github Kwpolska / pkgbuilder / pkgbuilder / exceptions.py View on Github external
"""Return a friendly representation of the exception."""
        return _('Network error: {0} (via {1})').format(self.msg, self.source)


class ConnectionError(NetworkError):
    """A connection error."""

    qualname = 'ConnectionError'

    def __str__(self):
        """Return a friendly representation of the exception."""
        return _('Connection error: {0} (via {1})').format(self.msg,
                                                           self.source)


class HTTPError(NetworkError):
    """An HTTP error."""

    qualname = 'HTTPError'

    def __init__(self, source, origin, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1} (via {2})'.format(self.qualname,
                                                      source.status_code,
                                                      source))
        self.msg = _('HTTP Error {0} (via {1})').format(source.status_code,
                                                        source)
        self.source = source
        try:
            self.origin = origin.args[0].reason
        except:
            try:
github Kwpolska / pkgbuilder / pkgbuilder / aur.py View on Github external
"""Make a multiinfo request and return plain JSON data."""
        if not args:
            # No need to bother.
            return self.emptystr % (self.rpcver, 'multiinfo')

        try:
            req = requests.get(self.rpc,
                               params={'type': 'multiinfo', 'arg[]': args},
                               headers={'User-Agent': self.ua})
            req.raise_for_status()
        except requests.exceptions.ConnectionError as e:
            raise ConnectionError(e.args[0].args[0], e)
        except requests.exceptions.HTTPError as e:
            raise HTTPError(req, e)
        except requests.exceptions.RequestException as e:
            raise NetworkError(str(e), e)

        return req.text
github Kwpolska / pkgbuilder / pkgbuilder / exceptions.py View on Github external
except Exception:
            try:
                self.source = source.args[0]
            except Exception:
                self.source = source
        self._source = source
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

    def __str__(self):
        """Return a friendly representation of the exception."""
        return _('Network error: {0} (via {1})').format(self.msg, self.source)


class ConnectionError(NetworkError):
    """A connection error."""

    qualname = 'ConnectionError'

    def __str__(self):
        """Return a friendly representation of the exception."""
        return _('Connection error: {0} (via {1})').format(self.msg,
                                                           self.source)


class HTTPError(NetworkError):
    """An HTTP error."""

    qualname = 'HTTPError'

    def __init__(self, source, origin, exit=True, *args, **kwargs):
github Kwpolska / pkgbuilder / pkgbuilder / aur.py View on Github external
# No need to bother.
            return self.emptystr % (self.rpcver, rtype)

        params = {'type': rtype, 'arg': arg}
        if search_by is not None:
            params['search_by'] = search_by
        try:
            req = requests.get(self.rpc, params=params,
                               headers={'User-Agent': self.ua})
            req.raise_for_status()
        except requests.exceptions.ConnectionError as e:
            raise ConnectionError(e.args[0].args[0], e)
        except requests.exceptions.HTTPError as e:
            raise HTTPError(req, e)
        except requests.exceptions.RequestException as e:
            raise NetworkError(str(e), e)

        return req.text