Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(rawargs):
global handle
parser = config.make_parser()
mode = parser.add_mutually_exclusive_group(required=True)
mode.add_argument('--asdeps', dest='mode',
action="store_const",
const=pyalpm.PKG_REASON_DEPEND)
mode.add_argument('--asexplicit', dest='mode',
action="store_const",
const=pyalpm.PKG_REASON_EXPLICIT)
parser.add_argument('pkgs', metavar='pkg', nargs='*',
help="a dependency string, e.g. 'pacman>=3.4.0'")
args = parser.parse_args(rawargs)
handle = config.init_with_config_and_options(args)
if args.verbose:
print("database " + " ".join(rawargs), file=sys.stderr)
commit(args.pkgs, args.mode)
return 0
def init_transaction(self, options=None):
""" Transaction initialization """
if options is None:
options = {}
transaction = None
try:
transaction = self.handle.init_transaction(
nodeps=options.get('nodeps', False),
dbonly=options.get('dbonly', False),
force=options.get('force', False),
needed=options.get('needed', False),
alldeps=(options.get('mode', None) ==
pyalpm.PKG_REASON_DEPEND),
allexplicit=(options.get('mode', None) ==
pyalpm.PKG_REASON_EXPLICIT),
cascade=options.get('cascade', False),
nosave=options.get('nosave', False),
recurse=(options.get('recursive', 0) > 0),
recurseall=(options.get('recursive', 0) > 1),
unneeded=options.get('unneeded', False),
downloadonly=options.get('downloadonly', False))
except pyalpm.error as pyalpm_error:
logging.error("Can't init alpm transaction: %s", pyalpm_error)
return transaction
"Transaction initialization"
handle.dlcb = cb_dl
handle.eventcb = cb_event
handle.questioncb = cb_conv
handle.progresscb = cb_progress
t = handle.init_transaction(
cascade=getattr(options, "cascade", False),
nodeps=getattr(options, "nodeps", False),
force=getattr(options, 'force', False),
dbonly=getattr(options, 'dbonly', False),
downloadonly=getattr(options, 'downloadonly', False),
nosave=getattr(options, 'nosave', False),
recurse=(getattr(options, 'recursive', 0) > 0),
recurseall=(getattr(options, 'recursive', 0) > 1),
unneeded=getattr(options, 'unneeded', False),
alldeps=(getattr(options, 'mode', None) == pyalpm.PKG_REASON_DEPEND),
allexplicit=(getattr(options, 'mode', None) == pyalpm.PKG_REASON_EXPLICIT))
return t
def main(rawargs):
global handle
parser = config.make_parser()
group = parser.add_argument_group("upgrade options")
group.add_argument('-d', '--nodeps',
action='store_true', default=False,
help='skip dependency checks')
group.add_argument('-f', '--force',
action='store_true', default=False,
help='force install, overwrite conflicting files')
group.add_argument('-k', '--dbonly',
action='store_true', default=False,
help='only modify database entries, not package files')
group.add_argument('--asdeps', dest='mode',
action="store_const",
const=pyalpm.PKG_REASON_DEPEND)
group.add_argument('--asexplicit', dest='mode',
action="store_const",
const=pyalpm.PKG_REASON_EXPLICIT)
group.add_argument('pkgs', metavar='pkg', nargs='*',
help="a list of package URLs, e.g. package-1.0-1-x86_64.tar.xz")
args = parser.parse_args(rawargs)
handle = config.init_with_config_and_options(args)
if args.verbose:
print("upgrade " + " ".join(rawargs), file=sys.stderr)
return upgrade(args.pkgs, args)
print(format_attr('Replaces', pkg.replaces))
if style == 'sync':
print(format_attr('Download Size', '%.2f K' % (pkg.size / 1024)))
if style == 'file':
print(format_attr('Compressed Size', '%.2f K' % (pkg.size / 1024)))
print(format_attr('Installed Size', '%.2f K' % (pkg.isize / 1024)))
print(format_attr('Packager', pkg.packager))
print(format_attr('Architecture', pkg.arch))
print(format_attr('Build Date', pkg.builddate, format_str='time'))
if style == 'local':
# local installation information
print(format_attr('Install Date', pkg.installdate, format_str='time'))
if pkg.reason == pyalpm.PKG_REASON_EXPLICIT:
reason = 'Explicitly installed'
elif pkg.reason == pyalpm.PKG_REASON_DEPEND:
reason = 'Installed as a dependency for another package'
else:
reason = 'N/A'
print(format_attr('Install Reason', reason))
if style != 'sync':
print(format_attr('Install Script', 'Yes' if pkg.has_scriptlet else 'No'))
if style == 'sync':
print(format_attr('MD5 Sum', pkg.md5sum))
print(format_attr('SHA256 Sum', pkg.sha256sum))
print(format_attr('Signatures', 'Yes' if pkg.base64_sig else 'No'))
print(format_attr('Description', pkg.desc))
if level >= 2 and style == 'local':
# print backup information
print('Backup files:')
def init_transaction(self, options=None):
""" Transaction initialization """
if options is None:
options = {}
transaction = None
try:
transaction = self.handle.init_transaction(
nodeps=options.get('nodeps', False),
dbonly=options.get('dbonly', False),
force=options.get('force', False),
needed=options.get('needed', False),
alldeps=(options.get('mode', None) == pyalpm.PKG_REASON_DEPEND),
allexplicit=(options.get('mode', None) == pyalpm.PKG_REASON_EXPLICIT),
cascade=options.get('cascade', False),
nosave=options.get('nosave', False),
recurse=(options.get('recursive', 0) > 0),
recurseall=(options.get('recursive', 0) > 1),
unneeded=options.get('unneeded', False),
downloadonly=options.get('downloadonly', False))
except pyalpm.error as pyalpm_error:
logging.error("Can't init alpm transaction: %s", pyalpm_error)
return transaction
info['download size'] = pkg.size / 1024
if style == 'file':
info['compressed size'] = pkg.size / 1024
info['installed size'] = pkg.isize / 1024
info['packager'] = pkg.packager
info['architecture'] = pkg.arch
info['build date'] = pkg.builddate
if style == 'local':
# local installation information
info['install date'] = pkg.installdate
if pkg.reason == pyalpm.PKG_REASON_EXPLICIT:
reason = _('Explicitly installed')
elif pkg.reason == pyalpm.PKG_REASON_DEPEND:
reason = _('Installed as a dependency for another package')
else:
reason = 'N/A'
info['install reason'] = reason
if style != 'sync':
if pkg.has_scriptlet:
info['install script'] = 'Yes'
else:
info['install script'] = 'No'
if style == 'sync':
info['md5 sum'] = pkg.md5sum
info['sha256 sum'] = pkg.sha256sum
if pkg.base64_sig:
info['signatures'] = 'Yes'
def filter_pkglist(pkglist, options):
result = []
if options.foreign:
syncpkgs = set()
for db in handle.get_syncdbs():
syncpkgs |= set(p.name for p in db.pkgcache)
for pkg in pkglist:
if options.deps and pkg.reason == pyalpm.PKG_REASON_EXPLICIT:
continue
if options.explicit and pkg.reason == pyalpm.PKG_REASON_DEPEND:
continue
if options.unrequired and len(pkg.compute_requiredby()) > 0:
continue
if options.foreign and pkg.name in syncpkgs:
continue
if options.upgrades and pyalpm.sync_newversion(pkg, handle.get_syncdbs()) is None:
continue
result.append(pkg)
return result
grp_install = parser.add_argument_group("Install options")
grp_install.add_argument('-d', '--nodeps',
action='store_true', default=False,
help='skip dependency checks')
grp_install.add_argument('-f', '--force',
action='store_true', default=False,
help='force install, overwrite conflicting files')
grp_install.add_argument('-k', '--dbonly',
action='store_true', default=False,
help='only modify database entries, not package files')
grp_install.add_argument('-w', '--downloadonly',
action='store_true', default=False,
help='download packages but do not install/upgrade anything')
grp_install.add_argument('--asdeps', dest='mode',
action="store_const",
const=pyalpm.PKG_REASON_DEPEND)
grp_install.add_argument('--asexplicit', dest='mode',
action="store_const",
const=pyalpm.PKG_REASON_EXPLICIT)
# Options to query sync databases
group1 = parser.add_argument_group("Query actions")
group1.add_argument('-g', '--groups', action='store_true', default=False,
help='view list of groups, or all members of a package group')
group1.add_argument('-i', '--info',
action='count', dest='info', default=0,
help='view package information')
group1.add_argument('-l', '--list', action='store_true', default=False,
help='list the contents of repositories')
group1.add_argument('-s', '--search', action='store_true', default=False,
help='search remote repositories for matching strings')
group1.add_argument('-q', '--quiet',
action='store_true', dest='quiet', default=False,