Last active
March 21, 2022 11:51
-
-
Save thozza/951cf9d955535eed6e5d1a9cb78d8761 to your computer and use it in GitHub Desktop.
Depsolving two transactions in a row using DNF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import tempfile | |
import dnf | |
import pprint | |
REPOS = [ | |
{ | |
"id": "baseos", | |
"baseurl": "https://rpmrepo.osbuild.org/v2/mirror/rhvpn/el8/el8-x86_64-baseos-n8.6-20220301/", | |
}, | |
{ | |
"id": "appstream", | |
"baseurl": "https://rpmrepo.osbuild.org/v2/mirror/rhvpn/el8/el8-x86_64-appstream-n8.6-20220301/", | |
}, | |
{ | |
"id": "rhui-azure", | |
"baseurl": "https://rpmrepo.osbuild.org/v2/mirror/rhvpn/el8/el8-x86_64-rhui-azure-20220227", | |
} | |
] | |
INSTALL_SPEC_1 = { | |
"include": [ | |
"@Server", | |
"NetworkManager", | |
"kernel", | |
"kernel-core", | |
"kernel-modules", | |
"selinux-policy-targeted", | |
"efibootmgr", | |
"lvm2", | |
"grub2-efi-x64", | |
"shim-x64", | |
"dracut-config-generic", | |
"dracut-norescue", | |
"bzip2", | |
"langpacks-en", | |
"grub2-pc", | |
"rhc", | |
"yum-utils", | |
"rhui-azure-rhel8", | |
"WALinuxAgent", | |
"cloud-init", | |
"cloud-utils-growpart", | |
"gdisk", | |
"hyperv-daemons", | |
"nvme-cli", | |
"cryptsetup-reencrypt", | |
"uuid", | |
"rng-tools", | |
"patch", | |
"dracut-config-generic", | |
"grub2-pc", | |
"dracut-config-generic", | |
"efibootmgr", | |
"grub2-efi-x64", | |
"shim-x64", | |
"kernel" | |
], | |
"exclude": [ | |
"aic94xx-firmware", | |
"alsa-firmware", | |
"alsa-lib", | |
"alsa-sof-firmware", | |
"alsa-tools-firmware", | |
"dracut-config-rescue", | |
"ivtv-firmware", | |
"iwl1000-firmware", | |
"iwl100-firmware", | |
"iwl105-firmware", | |
"iwl135-firmware", | |
"iwl2000-firmware", | |
"iwl2030-firmware", | |
"iwl3160-firmware", | |
"iwl3945-firmware", | |
"iwl4965-firmware", | |
"iwl5000-firmware", | |
"iwl5150-firmware", | |
"iwl6000-firmware", | |
"iwl6000g2a-firmware", | |
"iwl6000g2b-firmware", | |
"iwl6050-firmware", | |
"iwl7260-firmware", | |
"libertas-sd8686-firmware", | |
"libertas-sd8787-firmware", | |
"libertas-usb8388-firmware", | |
"glibc-all-langpacks", | |
"biosdevname", | |
"cockpit-podman", | |
"bolt", | |
"buildah", | |
"containernetworking-plugins", | |
"dnf-plugin-spacewalk", | |
"iprutils", | |
"plymouth", | |
"podman", | |
"python3-dnf-plugin-spacewalk", | |
"python3-rhnlib", | |
"python3-hwdata", | |
"NetworkManager-config-server", | |
"rhn-client-tools", | |
"rhn-setup", | |
"rhnsd", | |
"rhn-check", | |
"rhnlib", | |
"usb_modeswitch" | |
] | |
} | |
INSTALL_SPEC_2 = { | |
"include": ["kernel"], | |
"exclude": [] | |
} | |
def CreateDNFBase(repos, module_platform_id, persistdir, cachedir, arch): | |
base = dnf.Base() | |
base.conf.fastestmirror = True | |
base.conf.zchunk = False | |
base.conf.module_platform_id = module_platform_id | |
base.conf.config_file_path = "/dev/null" | |
base.conf.persistdir = persistdir | |
base.conf.cachedir = cachedir | |
base.conf.substitutions['arch'] = arch | |
base.conf.substitutions['basearch'] = dnf.rpm.basearch(arch) | |
for repo in repos: | |
dnf_repo = dnf.repo.Repo(repo["id"], base.conf) | |
dnf_repo.baseurl = repo["baseurl"] | |
base.repos.add(dnf_repo) | |
base.fill_sack(load_system_repo=False) | |
return base | |
def main(): | |
with tempfile.TemporaryDirectory() as tempdir: | |
persistent_dir = os.path.join(tempdir, "persistent") | |
os.makedirs(persistent_dir) | |
cache_dir = os.path.join(tempdir, "cache") | |
os.makedirs(cache_dir) | |
dnf_base = CreateDNFBase(REPOS, "platform:el8", persistent_dir, cache_dir, "x86_64") | |
# transaction #1 | |
dnf_base.install_specs(INSTALL_SPEC_1.get("include"), INSTALL_SPEC_1.get("exclude")) | |
dnf_base.resolve() | |
dependencies_1 = [] | |
for tsi in dnf_base.transaction: | |
if tsi.action not in dnf.transaction.FORWARD_ACTIONS: | |
continue | |
package = tsi.pkg | |
dependencies_1.append(package.name) | |
# transaction #1 | |
dnf_base.install_specs(INSTALL_SPEC_2.get("include"), INSTALL_SPEC_2.get("exclude")) | |
dnf_base.resolve() | |
dependencies_2 = [] | |
for tsi in dnf_base.transaction: | |
if tsi.action not in dnf.transaction.FORWARD_ACTIONS: | |
continue | |
package = tsi.pkg | |
dependencies_2.append(package.name) | |
print("Dependencies #1:\n", len(dependencies_1)) | |
pprint.pprint(dependencies_1) | |
print("\n\n") | |
print("Dependencies #2:\n", len(dependencies_2)) | |
pprint.pprint(dependencies_2) | |
print("diff:") | |
pprint.pprint(set(dependencies_2)-set(dependencies_1)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment