Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if source != 'AUTO':
args = parser.parse_args(source)
else:
args = parser.parse_args()
DS.pacman = args.pac
DS.cleanup = args.cleanup
pkgnames = args.pkgnames
if args.aur4:
pkgbuilder.aur.AUR.base = 'https://aur4.archlinux.org'
if args.debug:
DS.debugmode(nochange=True)
DS.log.info('*** PKGBUILDer v{0}'.format(__version__))
DS.log.debug('*** debug output on.')
DS.log.info('Arguments parsed. {0}'.format(args.__dict__))
if 'VIRTUAL_ENV' in os.environ:
DS.log.error("virtualenv detected, exiting.")
DS.fancy_error(_("PKGBUILDer cannot work in a virtualenv, "
"exiting."))
exit(83)
if not args.color:
DS.colorsoff()
DS.log.debug('Colors turned off.')
if args.info:
DS.log.debug('Showing info...')
DS.pgpcheck = DS.get_setting('--pgpcheck', 'options', 'pgpcheck',
args.pgpcheck, args.nopgpcheck)
DS.confirm = DS.get_setting('--confirm', 'options', 'confirm',
args.confirm, args.noconfirm)
DS.deepclone = DS.get_setting('--deep', 'options', 'deepclone',
args.deepclone, args.shallowclone)
DS.colors_status = DS.get_setting('--colors', 'options', 'colors',
args.colors, args.nocolors)
DS.edit_pkgbuild = DS.get_setting('--edit-pkgbuild', 'options', 'edit_pkgbuild',
args.edit_pkgbuild, args.noedit_pkgbuild)
pkgnames = args.pkgnames
if DS.get_setting('--debug', 'options', 'debug',
args.debug, args.nodebug):
DS.debugmode(nochange=True)
DS.log.info('*** PKGBUILDer v{0}'.format(__version__))
DS.log.debug('*** debug output on.')
DS.log.info('Arguments parsed. {0}'.format(args.__dict__))
if 'VIRTUAL_ENV' in os.environ:
DS.log.error("virtualenv detected, exiting.")
DS.fancy_error(_("PKGBUILDer cannot work in a virtualenv, "
"exiting."))
exit(83)
if not DS.colors_status:
DS.colorsoff()
DS.log.debug('Colors turned off.')
if args.info:
DS.log.debug('Showing info...')
npkgpaths = self.pacman_pkgpaths
uopt = self.uopt.strip()
if self.asdeps:
uopt = uopt + ' --asdeps'
if not DS.confirm:
uopt = uopt + ' --noconfirm'
uopt = uopt.strip()
if uopt:
DS.log.debug('$PACMAN -U {0} {1}'.format(uopt, npkgpaths))
ret = DS.sudo([DS.paccommand, '-U'] + uopt.split(' ') + npkgpaths)
else:
DS.log.debug('$PACMAN -U {0}'.format(npkgpaths))
ret = DS.sudo([DS.paccommand, '-U'] + npkgpaths)
self.pacmanreturn = ret
self._set_status_from_return(ret, TransactionStatus.installed,
TransactionStatus.install_failed)
return ret
v = rpkg.version
try:
datetime.datetime.strptime(v.split('-')[0], '%Y%m%d')
datever = True
except:
datever = False
dt = datetime.date.today().strftime('%Y%m%d-1')
if (rpkg.name.endswith(('git', 'hg', 'bzr', 'svn', 'cvs',
'darcs'))):
if vcsup:
upgradable.append([rpkg.name, lpkg.version, dt])
else:
DS.log.warning('{0} is -[vcs], ignored for '
'downgrade.'.format(rpkg.name))
elif datever:
if vcsup:
upgradable.append([rpkg.name, lpkg.version, dt])
else:
DS.log.warning('{0} version is a date, ignored '
'for downgrade.'.format(rpkg.name))
else:
downgradable.append([rpkg.name, lpkg.version,
rpkg.version])
return [upgradable, downgradable, ignored]
pkgpaths.append(p)
elif os.path.exists(pacp):
DS.log.warning("Not moving package file {0} -- "
"found in pacman cache".format(p))
else:
DS.log.error("Not moving package file {0} -- "
"not found".format(p))
if not quiet:
DS.fancy_warning2(_("Package file {0} not found").format(
p))
failed_files += 1
for s in self.sigpaths:
pacs = self._pacman_pkgpath(p)
if s == pacs:
DS.log.warning("Not moving signature file {0} -- "
"already in pacman cache".format(s))
elif os.path.exists(s):
sigpaths.append(s)
elif os.path.exists(pacs):
DS.log.warning("Not moving signature file {0} -- "
"found in pacman cache".format(s))
else:
DS.log.error("Not moving signature file {0} -- "
"not found".format(s))
if not quiet:
DS.fancy_warning2(_("Signature file {0} not found").format(
s))
failed_files += 1
DS.log.debug('mv {0} {1} /var/cache/pacman/pkg/'.format(
pkgpaths, sigpaths))
def validate(self, quiet):
"""Check if packages were installed.
:param bool quiet: suppress messages
:return: number of packages that were not installed
:rtype: int
"""
if self.pkgnames:
if not quiet:
DS.fancy_msg(_('Validating installation status...'))
DS.log.info('Validating: ' + '; '.join(self.pkgnames))
DS.pycreload()
localdb = DS.pyc.get_localdb()
aurpkgs = {aurpkg.name: aurpkg.version for aurpkg in
pkgbuilder.utils.info(self.pkgnames)}
wrong = len(self.pkgnames)
else:
wrong = 0
for pkgname in self.pkgnames:
lpkg = localdb.get_pkg(pkgname)
try:
aurversion = aurpkgs[pkgname]
except KeyError:
if not lpkg:
DS.fancy_msg(_('Checking dependencies...'))
depends = prepare_deps(os.path.abspath('./.SRCINFO'))
deps = depcheck(depends, pkg)
pkgtypes = [_('found in system'), _('found in repos'),
_('found in the AUR')]
aurbuild = []
if not deps:
DS.fancy_msg2(_('none found'))
for dpkg, pkgtype in deps.items():
if pkgtype == 2 and dpkg not in subpackages:
# If we didn’t check for subpackages, we would get an infinite
# loop if subpackages depended on each other
aurbuild.append(dpkg)
elif dpkg in subpackages:
DS.log.debug("Package depends on itself, ignoring")
DS.fancy_msg2(': '.join((dpkg, pkgtypes[pkgtype])))
if aurbuild != []:
os.chdir('../')
return [RES_AURDEPS, aurbuild]
# Edit the pkgbuild
if pkgbuild_edit:
continue_install = edit_pkgbuild(pkg.packagebase)
if not continue_install:
return [RES_ABORT, ([], [])]
mpparams = ['makepkg', '-sf']
if DS.clean:
mpparams.append('-c')
def main(source='AUTO', quit=True):
"""Main routine of PKGBUILDer."""
try:
verstring = 'PKGBUILDer v' + __version__
# TRANSLATORS: translate the whole sentence.
# Alternatively, use translation instead of locale.
locale = _('LANG locale by AUTHOR ')
if locale != 'LANG locale by AUTHOR ':
verstring = ' — '.join([verstring, locale])
DS.log.info('Initialized, parsing arguments.')
parser = argparse.ArgumentParser(
prog='pkgbuilder',
description=_('An AUR helper (and library) in Python 3.'),
epilog=_('Also accepting ABS packages.'))
parser.add_argument(
'-V', '--version', action='version', version=verstring,
help=_('show version number and quit'))
parser.add_argument(
'pkgnames', metavar=_('PACKAGE'), action='store', nargs='*',
help=_('AUR/ABS packages to build'))
argopr = parser.add_argument_group(_('operations'))
argopr.add_argument(
'-F', '--fetch', action='store_true', default=False, dest='fetch',
help=_('fetch package files'))
argopr.add_argument(
abspkgs = []
aurpkgs = []
allpkgs = []
try:
if preprocessed:
allpkgs = pkgnames
pkgnames = [p.name for p in allpkgs]
else:
print(':: ' + _('Fetching package information...'))
for pkgname in pkgnames:
pkg = None
try:
pkg = pkgbuilder.utils.info([pkgname])[0]
except IndexError:
try:
DS.log.info('{0} not found in the AUR, checking in '
'repositories'.format(pkgname))
syncpkgs = []
for j in [i.pkgcache for i in DS.pyc.get_syncdbs()]:
syncpkgs.append(j)
syncpkgs = functools.reduce(lambda x, y: x + y,
syncpkgs)
abspkg = pyalpm.find_satisfier(syncpkgs, pkgname)
pkg = pkgbuilder.package.ABSPackage.from_pyalpm(abspkg)
except AttributeError:
pass
allpkgs.append(pkg)
if not pkg:
raise pkgbuilder.exceptions.PackageNotFoundError(
pkgname, 'fetch')
if not DS.pgpcheck:
mpparams.append('--skippgpcheck')
if not DS.confirm:
mpparams.append('--noconfirm')
if not DS.depcheck:
mpparams.append('--nodeps')
if not DS.colors_status:
mpparams.append('--nocolor')
DS.log.info("Running makepkg: {0}".format(mpparams))
mpstatus = subprocess.call(mpparams, shell=False)
DS.log.info("makepkg status: {0}".format(mpstatus))
if pkginstall:
toinstall = find_packagefile(os.getcwd())
else:
toinstall = ([], [])
if pkg.is_abs:
os.chdir('../../')
else:
os.chdir('../')
DS.log.info("Found package files: {0}".format(toinstall))
return [mpstatus, toinstall]