diff --git a/dnf/automatic/main.py b/dnf/automatic/main.py index c27a75268d..27a27c53c5 100644 --- a/dnf/automatic/main.py +++ b/dnf/automatic/main.py @@ -76,19 +76,24 @@ def parse_arguments(args): parser = argparse.ArgumentParser() parser.add_argument('conf_path', nargs='?', default=dnf.const.CONF_AUTOMATIC_FILENAME) parser.add_argument('--timer', action='store_true') + parser.add_argument('--includepkgs', dest='includepkgs', action='append') + parser.add_argument('--excludepkgs', dest='excludepkgs', action='append') parser.add_argument('--installupdates', dest='installupdates', action='store_true') parser.add_argument('--downloadupdates', dest='downloadupdates', action='store_true') parser.add_argument('--no-installupdates', dest='installupdates', action='store_false') parser.add_argument('--no-downloadupdates', dest='downloadupdates', action='store_false') parser.set_defaults(installupdates=None) parser.set_defaults(downloadupdates=None) + parser.set_defaults(includepkgs=[]) + parser.set_defaults(excludepkgs=[]) return parser.parse_args(args), parser class AutomaticConfig(object): def __init__(self, filename=None, downloadupdates=None, - installupdates=None): + installupdates=None, includepkgs=[], + excludepkgs=[]): if not filename: filename = dnf.const.CONF_AUTOMATIC_FILENAME self.commands = CommandsConfig() @@ -108,6 +113,9 @@ def __init__(self, filename=None, downloadupdates=None, elif installupdates is False: self.commands.apply_updates = False + self.commands.includepkgs.extend(includepkgs) + self.commands.excludepkgs.extend(excludepkgs) + self.commands.imply() self.filename = filename @@ -174,6 +182,8 @@ class CommandsConfig(Config): def __init__(self): super(CommandsConfig, self).__init__() self.add_option('apply_updates', libdnf.conf.OptionBool(False)) + self.add_option('includepkgs', libdnf.conf.OptionStringList(libdnf.conf.VectorString([]))) + self.add_option('excludepkgs', libdnf.conf.OptionStringList(libdnf.conf.VectorString([]))) self.add_option('base_config_file', libdnf.conf.OptionString('/etc/dnf/dnf.conf')) self.add_option('download_updates', libdnf.conf.OptionBool(False)) self.add_option('upgrade_type', libdnf.conf.OptionEnumString('default', @@ -305,7 +315,8 @@ def main(args): try: conf = AutomaticConfig(opts.conf_path, opts.downloadupdates, - opts.installupdates) + opts.installupdates, opts.includepkgs, + opts.excludepkgs) emitters = None with dnf.Base() as base: cli = dnf.cli.Cli(base) @@ -332,6 +343,24 @@ def main(args): base.configure_plugins() base.fill_sack() + + include_query = base.sack.query().filterm(empty=True) + if len(conf.commands.includepkgs) > 0: + for incl in set(conf.commands.includepkgs): + subj = dnf.subject.Subject(incl) + include_query = include_query.union(subj.get_best_query( + base.sack, with_nevra=True, with_provides=False, with_filenames=False)) + exclude_query = base.sack.query().filterm(empty=True) + for excl in set(conf.commands.excludepkgs): + subj = dnf.subject.Subject(excl) + exclude_query = exclude_query.union(subj.get_best_query( + base.sack, with_nevra=True, with_provides=False, with_filenames=False)) + if len(conf.commands.includepkgs) > 0: + base.sack.add_includes(include_query) + base.sack.set_use_includes(True) + if exclude_query: + base.sack.add_excludes(exclude_query) + upgrade(base, conf.commands.upgrade_type) base.resolve() output = dnf.cli.output.Output(base, base.conf) diff --git a/tests/automatic/test_main.py b/tests/automatic/test_main.py index dc4acd52f4..0f23c6c2fb 100644 --- a/tests/automatic/test_main.py +++ b/tests/automatic/test_main.py @@ -39,6 +39,11 @@ def test_load(self): self.assertEqual(conf.commands.random_sleep, 300) self.assertEqual(conf.email.email_from, 'staring@crowd.net') + # test includepkg and excludepkgs + conf = dnf.automatic.main.AutomaticConfig(FILE) + self.assertEqual(list(conf.commands.includepkgs), ["dnf", "dnf-automatic"]) + self.assertEqual(list(conf.commands.excludepkgs), ["gtk3", "gtk3-immodule-xim"]) + # test overriding installupdates conf = dnf.automatic.main.AutomaticConfig(FILE, installupdates=False) # as per above, download is set false in config diff --git a/tests/etc/automatic.conf b/tests/etc/automatic.conf index 63b67269dc..b2ebb99b84 100644 --- a/tests/etc/automatic.conf +++ b/tests/etc/automatic.conf @@ -2,6 +2,8 @@ update_cmd = default download_updates = no apply_updates = yes +includepkgs = dnf,dnf-automatic +excludepkgs = gtk3,gtk3-immodule-xim [email] email_from = staring@crowd.net