add ability to install packages

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
reviewable/pr18780/r1
Igor Gnatenko 10 years ago
parent 25d61b7d01
commit bbc8dae006

@ -22,14 +22,11 @@
import traceback import traceback
import os import os
import operator
import functools
import dnf import dnf
import dnf.cli
try: import dnf.util
from dnf import find_unfinished_transactions, find_ts_remaining
from rpmUtils.miscutils import splitFilename
transaction_helpers = True
except:
transaction_helpers = False
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -174,6 +171,54 @@ def list_stuff(module, conf_file, stuff):
else: else:
return [pkg_to_dict(p) for p in dnf.subject.Subject(stuff).get_best_query(my.sack)] return [pkg_to_dict(p) for p in dnf.subject.Subject(stuff).get_best_query(my.sack)]
def ensure(module, state, pkgspec, conf_file, enablerepo, disablerepo, disable_gpg_check):
my = dnf_base(conf_file)
items = pkgspec.split(',')
if disablerepo:
for repo in disablerepo.split(','):
[r.disable() for r in b.repos.get_matching(repo)]
if enablerepo:
for repo in enablerepo.split(','):
[r.enable() for r in b.repos.get_matching(repo)]
my.conf.gpgcheck = disable_gpg_check
res = {}
res['results'] = []
res['msg'] = ''
res['rc'] = 0
res['changed'] = False
if not dnf.util.am_i_root():
res['msg'] = 'This command has to be run under the root user.'
res['rc'] = 1
pkg_specs, grp_specs, filenames = dnf.cli.commands.parse_spec_group_file(items)
if state in ['installed', 'present']:
# Install files.
local_pkgs = map(my.add_remote_rpm, filenames)
map(my.package_install, local_pkgs)
# Install groups.
if grp_specs:
my.read_comps()
my.env_group_install(grp_specs, dnf.const.GROUP_PACKAGE_TYPES)
# Install packages.
for pkg_spec in pkg_specs:
try:
my.install(pkg_spec)
except dnf.exceptions.MarkingError:
res['results'].append('No package %s available.' % pkg_spec)
res['rc'] = 1
if not my.resolve() and res['rc'] == 0:
res['msg'] += 'Nothing to do'
res['changed'] = False
else:
my.download_packages(my.transaction.install_set)
my.do_transaction()
[res['results'].append('Installed: %s' % pkg) for pkg in my.transaction.install_set)
[res['results'].append('Removed: %s' % pkg) for pkg in my.transaction.remove_set)
module.exit_json(**res)
def main(): def main():
# state=installed name=pkgspec # state=installed name=pkgspec
@ -212,7 +257,6 @@ def main():
module.exit_json(**results) module.exit_json(**results)
else: else:
return
pkg = params['name'] pkg = params['name']
state = params['state'] state = params['state']
enablerepo = params.get('enablerepo', '') enablerepo = params.get('enablerepo', '')

Loading…
Cancel
Save