Skip to content

Commit 9d92c03

Browse files
j-mracekMichaelMraka
authored andcommitted
Apply excludes for *.rpm files from command-line (RhBug:1262878)
It change API where there is a single call to add multiple RPM into sack and apply include, exclude.
1 parent 33e68e5 commit 9d92c03

14 files changed

Lines changed: 75 additions & 72 deletions

dnf/base.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -954,13 +954,24 @@ def download_packages(self, pkglist, progress=None, callback_total=None):
954954
percent = 100 - real / full * 100
955955
logger.info(msg, full / 1024 ** 2, real / 1024 ** 2, percent)
956956

957-
def add_remote_rpm(self, path):
957+
def add_remote_rpms(self, path_list, strict=True):
958958
# :api
959-
if not os.path.exists(path) and '://' in path:
960-
# download remote rpm to a tempfile
961-
path = self.urlopen(path, suffix='.rpm', delete=False).name
962-
self._add_tempfiles([path])
963-
return self.sack.add_cmdline_package(path)
959+
pkgs = []
960+
pkgs_error = []
961+
for path in path_list:
962+
if not os.path.exists(path) and '://' in path:
963+
# download remote rpm to a tempfile
964+
path = self.urlopen(path, suffix='.rpm', delete=False).name
965+
self._add_tempfiles([path])
966+
try:
967+
pkgs.append(self.sack.add_cmdline_package(path))
968+
except EnvironmentError as e:
969+
logger.warning(e)
970+
pkgs_error.append(path)
971+
self._setup_excludes_includes()
972+
if pkgs_error and strict:
973+
raise EnvironmentError(_("Could not open {}").format(', '.join(pkgs_error)))
974+
return pkgs
964975

965976
def _sig_check_pkg(self, po):
966977
"""Verify the GPG signature of the given package object.

dnf/cli/cli.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,32 +329,28 @@ def distro_sync_userlist(self, userlist):
329329
msg = _('No packages marked for distribution synchronization.')
330330
raise dnf.exceptions.Error(msg)
331331

332-
def downgradePkgs(self, extcmds):
332+
def downgradePkgs(self, specs=[], file_pkgs=[]):
333333
"""Attempt to take the user specified list of packages or
334-
wildcards and downgrade them. If a complete version number if
334+
wildcards and downgrade them. If a complete version number is
335335
specified, attempt to downgrade them to the specified version
336336
337-
:param extcmds: a list of names or wildcards specifying
338-
packages to downgrade
339-
:return: (exit_code, [ errors ])
340-
341-
exit_code is::
342-
343-
0 = we're done, exit
344-
1 = we've errored, exit with error string
345-
2 = we've got work yet to do, onto the next stage
337+
:param specs: a list of names or wildcards specifying packages to downgrade
338+
:param file_pkgs: a list of pkg objects from local files
346339
"""
347340

348341
oldcount = self._goal.req_length()
349-
350-
for arg in extcmds:
351-
wildcard = True if dnf.util.is_glob_pattern(arg) else False
352-
if arg.endswith('.rpm'):
353-
pkg = self.add_remote_rpm(arg)
342+
for pkg in file_pkgs:
343+
try:
354344
self.package_downgrade(pkg)
355345
continue # it was something on disk and it ended in rpm
356346
# no matter what we don't go looking at repos
347+
except dnf.exceptions.MarkingError as e:
348+
logger.info(e)
349+
# it was something on disk and it ended in rpm
350+
# no matter what we don't go looking at repos
357351

352+
for arg in specs:
353+
wildcard = True if dnf.util.is_glob_pattern(arg) else False
358354
try:
359355
self.downgrade_to(arg)
360356
except dnf.exceptions.PackageNotFoundError as err:

dnf/cli/commands/downgrade.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from __future__ import absolute_import
2222
from __future__ import unicode_literals
2323
from dnf.cli import commands
24+
from dnf.cli.option_parser import OptionParser
2425
from dnf.i18n import _
2526

2627
class DowngradeCommand(commands.Command):
@@ -33,7 +34,8 @@ class DowngradeCommand(commands.Command):
3334

3435
@staticmethod
3536
def set_argparser(parser):
36-
parser.add_argument('package', nargs='*', help=_('Package to downgrade'))
37+
parser.add_argument('package', nargs='*', help=_('Package to downgrade'),
38+
action=OptionParser.ParseSpecGroupFileCallback)
3739

3840
def configure(self):
3941
demands = self.cli.demands
@@ -43,7 +45,8 @@ def configure(self):
4345
demands.root_user = True
4446

4547
commands.checkGPGKey(self.base, self.cli)
46-
commands.checkEnabledRepo(self.base, self.opts.package)
48+
commands.checkEnabledRepo(self.base, self.opts.filenames)
4749

4850
def run(self):
49-
return self.base.downgradePkgs(self.opts.package)
51+
return self.base.downgradePkgs(specs=self.opts.pkg_specs + [ '@' + x for x in self.opts.grp_specs],
52+
file_pkgs=self.base.add_remote_rpms(self.opts.filenames, strict=False))

dnf/cli/commands/install.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
from dnf.i18n import _
2626

2727
import dnf.exceptions
28-
import functools
2928
import logging
30-
import operator
3129

3230
logger = logging.getLogger('dnf')
3331

@@ -61,15 +59,11 @@ def configure(self):
6159

6260
def run(self):
6361
strict = self.base.conf.strict
64-
package_install_fnc = functools.partial(self.base.package_install,
65-
strict=strict)
6662

6763
# Install files.
68-
local_pkgs = map(self.base.add_remote_rpm, self.opts.filenames)
6964
# try to install packages with higher version first
70-
local_pkgs = sorted(local_pkgs, reverse=True)
71-
results = map(package_install_fnc, local_pkgs)
72-
done = functools.reduce(operator.or_, results, False)
65+
for pkg in sorted(self.base.add_remote_rpms(self.opts.filenames, strict=strict), reverse=True):
66+
self.base.package_install(pkg, strict=strict)
7367

7468
# Install groups.
7569
if self.opts.grp_specs:
@@ -81,7 +75,6 @@ def run(self):
8175
except dnf.exceptions.Error:
8276
if self.base.conf.strict:
8377
raise
84-
done = True
8578

8679
# Install packages.
8780
errs = []
@@ -93,9 +86,5 @@ def run(self):
9386
logger.info(msg, self.base.output.term.MODE['bold'], pkg_spec,
9487
self.base.output.term.MODE['normal'])
9588
errs.append(pkg_spec)
96-
done = True
9789
if len(errs) != 0 and self.base.conf.strict:
9890
raise dnf.exceptions.PackagesNotAvailableError(_("Unable to find a match."), packages=errs)
99-
100-
if not done:
101-
raise dnf.exceptions.Error(_('Nothing to do.'))

dnf/cli/commands/reinstall.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
from dnf.i18n import _
2626

2727
import dnf.exceptions
28-
import functools
2928
import logging
30-
import operator
3129

3230
logger = logging.getLogger('dnf')
3331

@@ -62,9 +60,14 @@ def configure(self):
6260
def run(self):
6361

6462
# Reinstall files.
65-
local_pkgs = map(self.base.add_remote_rpm, self.opts.filenames)
66-
results = map(self.base.package_reinstall, local_pkgs)
67-
done = functools.reduce(operator.or_, results, False)
63+
done = False
64+
for pkg in self.base.add_remote_rpms(self.opts.filenames, strict=False):
65+
try:
66+
self.base.package_reinstall(pkg)
67+
except dnf.exceptions.MarkingError as e:
68+
logger.info(e)
69+
else:
70+
done = True
6871

6972
# Reinstall packages.
7073
for pkg_spec in self.opts.pkg_specs + ['@' + x for x in self.opts.grp_specs]:

dnf/cli/commands/upgrade.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
from dnf.cli.option_parser import OptionParser
2626

2727
import dnf.exceptions
28-
import functools
2928
import logging
30-
import operator
3129

3230
logger = logging.getLogger('dnf')
3331

@@ -60,11 +58,17 @@ def configure(self):
6058
commands.checkEnabledRepo(self.base, self.opts.pkg_specs)
6159

6260
def run(self):
63-
if self.opts.pkg_specs or self.opts.grp_specs or self.opts.filenames:
61+
done = False
62+
if self.opts.filenames or self.opts.pkg_specs or self.opts.grp_specs:
6463
# Update files.
65-
local_pkgs = map(self.base.add_remote_rpm, self.opts.filenames)
66-
results = map(self.base.package_upgrade, local_pkgs)
67-
done = functools.reduce(operator.or_, results, False)
64+
if self.opts.filenames:
65+
for pkg in self.base.add_remote_rpms(self.opts.filenames, strict=False):
66+
try:
67+
self.base.package_upgrade(pkg)
68+
except dnf.exceptions.MarkingError as e:
69+
logger.info(e)
70+
else:
71+
done = True
6872

6973
# Update packages.
7074
for pkg_spec in self.opts.pkg_specs:
@@ -84,6 +88,5 @@ def run(self):
8488
# Update all packages.
8589
self.base.upgrade_all()
8690
done = True
87-
8891
if not done:
8992
raise dnf.exceptions.Error(_('No packages marked for upgrade.'))

doc/api_base.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949

5050
Init an instance with a reasonable default configuration. The constructor takes no arguments.
5151

52-
.. method:: add_remote_rpm(path)
52+
.. method:: add_remote_rpms(path_list, strict=True)
5353

54-
Add RPM file at `path` to the :attr:`sack` and return the respective :class:`dnf.package.Package` instance. Does the download to a temporary file if `path` is a remote URL. Raises :exc:`IOError` if there are problems obtaining or reading the file.
54+
Add RPM files at list `path_list` to the :attr:`sack` and return the list of respective :class:`dnf.package.Package` instances. Does the download to a temporary files for each path if `path` is a remote URL. Raises :exc:`EnvironmentError` if there are problems obtaining during reading files and `strict=True`.
5555

5656
.. method:: close()
5757

doc/examples/install_extension.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@
4242
except dnf.exceptions.MarkingError:
4343
sys.exit('Feature(s) cannot be found: ' + ftr_spec)
4444
# Package marking methods set the user request.
45-
for rpm_spec in RPM_SPECS:
46-
try:
47-
base.package_install(base.add_remote_rpm(rpm_spec))
48-
except IOError:
49-
sys.exit('RPM cannot be loaded: ' + rpm_spec)
45+
try:
46+
base.package_install(base.add_remote_rpms(RPM_SPECS, strict=False))
47+
except EnvironmentError as e:
48+
sys.exit(e)
5049
# Comps data reading initializes the base.comps attribute.
5150
if GRP_SPECS:
5251
base.read_comps()

doc/examples/install_plugin.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ def run(self, args):
6565
except dnf.exceptions.MarkingError:
6666
raise dnf.exceptions.Error('feature(s) not found: ' + ftr_spec)
6767
# Package marking methods set the user request.
68-
for rpm_spec in rpm_specs:
69-
try:
70-
self.base.package_install(self.base.add_remote_rpm(rpm_spec))
71-
except IOError:
72-
raise dnf.exceptions.Error('RPM not loadable: ' + rpm_spec)
68+
try:
69+
self.base.package_install(self.base.add_remote_rpms(rpm_specs, strict=False))
70+
except EnvironmentError as e:
71+
raise dnf.exceptions.Error(e)
7372
# Comps data reading initializes the base.comps attribute.
7473
if grp_specs:
7574
self.base.read_comps()

doc/release_notes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ API changes in 0.5.0:
655655

656656
API extensions in 0.5.0:
657657

658-
* :meth:`dnf.Base.add_remote_rpm`
658+
* :meth:`dnf.Base.add_remote_rpms`
659659
* :meth:`dnf.Base.close`
660660
* :meth:`dnf.Base.group_upgrade`
661661
* :meth:`dnf.Base.resolve` optionally accepts `allow_erasing` arguments now.

0 commit comments

Comments
 (0)