How to use the pkgbuilder.exceptions.PBException 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 / main.py View on Github external
DS.root_crash()

            DS.log.info('Starting build...')
            toinstall = []
            sigs = []
            tovalidate = set(pkgnames)

            for pkgname in pkgnames:
                try:
                    DS.log.info('Building {0}'.format(pkgname))
                    out = pkgbuilder.build.auto_build(pkgname, args.depcheck,
                                                      args.pkginst, pkgnames)
                    if out:
                        toinstall += out[1][0]
                        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'.
github Kwpolska / pkgbuilder / pkgbuilder / build.py View on Github external
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 / build.py View on Github external
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 '
                'name of the “main” package (eg. python- instead of python2-) '
                'and try again.', pkg.name, exit=False)

        if not os.path.exists('.SRCINFO'):
            # Create a .SRCINFO file for ASP/repo packages.
            # Slightly hacky, but saves us work on parsing bash.
            DS.log.debug("Creating .SRCINFO for repository package")
            srcinfo = subprocess.check_output(["makepkg", "--printsrcinfo"])
            with open(".SRCINFO", "wb") as fh:
                fh.write(srcinfo)
    else:
        existing = find_packagefile(pkg.packagebase)
        if any(pkg.name in i for i in existing[0]):
            DS.fancy_msg(_('Found an existing package for '
github Kwpolska / pkgbuilder / pkgbuilder / exceptions.py View on Github external
def __init__(self, msg, source, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1}'.format(self.qualname, msg))
        self.msg = msg
        self.source = source
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

    def __str__(self):
        """Return a friendly representation of the exception."""
        return self.msg


class AURError(PBException):
    """AUR-related errors."""

    qualname = 'AURError'

    def __init__(self, msg, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1}'.format(self.qualname, msg))
        self.msg = msg
        self.source = 'AUR'
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

    def __str__(self):
        """Return a friendly representation of the exception."""
        return _('AUR Error: {0}').format(self.msg)
github Kwpolska / pkgbuilder / pkgbuilder / exceptions.py View on Github external
"""Initialize and log the error."""
        DS.log.error('({0:<20}) {1} (via {2})'.format(self.qualname, name,
                                                      source))
        self.name = name
        self.msg = _('Package {0} not found. (via {1})').format(name, source)
        self.source = source
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

    def __str__(self):
        """Return a friendly representation of the exception."""
        return self.msg


class SanityError(PBException):
    """When PKGBUILDer or one of its friends goes insane."""

    qualname = 'SanityError'

    def __init__(self, msg, source, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1} (via {2})'.format(self.qualname, msg,
                                                      source))
        self.msg = msg
        self.source = source
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

    def __str__(self):
        """Return a friendly representation of the exception."""
github Kwpolska / pkgbuilder / pkgbuilder / exceptions.py View on Github external
def __init__(self, msg, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1}'.format(self.qualname, msg))
        self.msg = msg
        self.source = 'AUR'
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

    def __str__(self):
        """Return a friendly representation of the exception."""
        return _('AUR Error: {0}').format(self.msg)


class MakepkgError(PBException):
    """makepkg return codes."""

    qualname = 'MakepkgError'

    def __init__(self, retcode, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1}'.format(self.qualname, retcode))
        self.retcode = retcode
        self.source = 'makepkg'
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

    def __str__(self):
        """Return a friendly representation of the exception."""
        return _('makepkg returned {0}.').format(self.retcode)
github Kwpolska / pkgbuilder / pkgbuilder / exceptions.py View on Github external
def __init__(self, msg, source, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1} (via {2})'.format(self.qualname, msg,
                                                      source))
        self.msg = msg
        self.source = source
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

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


class CloneError(PBException):
    """A ``git clone`` failed."""

    qualname = 'CloneError'

    def __init__(self, returncode, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) git clone returned {1}'.format(
            self.qualname, returncode))
        self.returncode = returncode
        self.msg = _('git clone returned {0}.').format(self.returncode)
        self.exit = exit
        self.args = args
        self.kwargs = kwargs


class ClonePathExists(CloneError):
github Kwpolska / pkgbuilder / pkgbuilder / exceptions.py View on Github external
def __init__(self, retcode, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1}'.format(self.qualname, retcode))
        self.retcode = retcode
        self.source = 'makepkg'
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

    def __str__(self):
        """Return a friendly representation of the exception."""
        return _('makepkg returned {0}.').format(self.retcode)


class NetworkError(PBException):
    """Network-related errors."""

    qualname = 'NetworkError'

    def __init__(self, msg, source, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1} (via {2})'.format(self.qualname, msg,
                                                      source))
        self.msg = msg
        try:
            self.source = source.args[0].reason
        except Exception:
            try:
                self.source = source.args[0]
            except Exception:
                self.source = source
github Kwpolska / pkgbuilder / pkgbuilder / build.py View on Github external
completelist = []
    build_result = build_runner(pkgname, performdepcheck, pkginstall, pkgbuild_edit)
    try:
        if build_result[0] == 0:
            DS.fancy_msg(_('The build succeeded.'))
        elif build_result[0] >= 0 and build_result[0] < 256:
            raise pkgbuilder.exceptions.MakepkgError(build_result[0])
        elif build_result[0] == RES_ABORT:
            DS.fancy_warning(_('Installation aborted by user.'))
        elif build_result[0] == RES_EXISTING:
            # existing package, do nothing
            pass
        elif build_result[0] == RES_AURDEPS:
            DS.fancy_warning(_('Building more AUR packages is required.'))
            if not pkginstall:
                raise pkgbuilder.exceptions.PBException(
                    _('Cannot install dependencies and continue building '
                      'because -w, --buildonly was specified.  Please run '
                      'without -w, --buildonly or install dependencies '
                      'manually and try again.'),
                    'auto_build deps')

            toinstall2 = []
            sigs2 = []
            for pkgname2 in build_result[1]:
                toinstall = []
                if pkgname2 in completelist:
                    if (completelist.index(pkgname2) <
                            completelist.index(pkgname)):
                        # Already built the package.
                        toinstall, sigs = find_packagefile(
                            os.path.join(os.getcwd(), pkgname2))
github Kwpolska / pkgbuilder / pkgbuilder / exceptions.py View on Github external
self.source = source
        try:
            self.origin = origin.args[0].reason
        except:
            try:
                self.origin = origin.args[0]
            except:
                self.source = origin
        self._origin = origin
        self.exit = exit
        self.args = args
        self.kwargs = kwargs
        self.code = source.status_code


class PackageError(PBException):
    """Package-related errors."""

    qualname = 'PackageError'

    def __init__(self, msg, source, exit=True, *args, **kwargs):
        """Initialize and log the error."""
        DS.log.error('({0:<20}) {1} (from {2})'.format(self.qualname, msg,
                                                       source))
        self.msg = msg
        self.source = source
        self.exit = exit
        self.args = args
        self.kwargs = kwargs

    def __str__(self):
        """Return a friendly representation of the exception."""