Skip to content

Commit

Permalink
[dnf-automatic] Add in options for includepkgs and excludepkgs
Browse files Browse the repository at this point in the history
This option adds in includepks and excludepkgs so we can specify a list
we wanted updated or explicitly excluded from automatic updates
  • Loading branch information
SludgeGirl committed Dec 30, 2023
1 parent 1c43d09 commit 0d11d72
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
33 changes: 31 additions & 2 deletions dnf/automatic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/automatic/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def test_load(self):
self.assertEqual(conf.commands.random_sleep, 300)
self.assertEqual(conf.email.email_from, '[email protected]')

# 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
Expand Down
2 changes: 2 additions & 0 deletions tests/etc/automatic.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [email protected]

0 comments on commit 0d11d72

Please sign in to comment.