Skip to content

Instantly share code, notes, and snippets.

@msehnout
Last active April 13, 2021 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msehnout/1f071ffd6134723083e6dd9a51859e87 to your computer and use it in GitHub Desktop.
Save msehnout/1f071ffd6134723083e6dd9a51859e87 to your computer and use it in GitHub Desktop.
dnf resolve 2 package sets
#!/usr/bin/python3
import dnf
base = dnf.Base()
conf = base.conf
conf.cachedir = '/tmp/my_cache_dir'
conf.substitutions['releasever'] = '33'
conf.substitutions['basearch'] = 'x86_64'
base.repos.add_new_repo('my-repo', conf,
baseurl=["http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/"])
base.fill_sack(load_system_repo=False)
print("Enabled repositories:")
for repo in base.repos.iter_enabled():
print("id: {}".format(repo.id))
print("baseurl: {}".format(repo.baseurl))
# First include and exclude packages and groups that define the OS
print("First run:")
include = [
"vim-minimal"
]
exclude = [
"logrotate"
]
base.install_specs(
include,
exclude=exclude,
strict=True
)
base.resolve()
for tsi in base.transaction:
# Avoid using the install_set() helper, as it does not guarantee
# a stable order
if tsi.action not in dnf.transaction.FORWARD_ACTIONS:
continue
print(f"Pkg to install: {tsi.pkg}")
# Second, apply the customizations from the user. Ideally this would override whatever
# excludes from the first run, but THIS DOESN'T WORK YET.
print("Second run:")
include = [
"vsftpd"
]
exclude = []
base.install_specs(
include,
exclude=exclude,
strict=False
)
base.resolve()
for tsi in base.transaction:
# Avoid using the install_set() helper, as it does not guarantee
# a stable order
if tsi.action not in dnf.transaction.FORWARD_ACTIONS:
continue
print(f"Pkg to install: {tsi.pkg}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment