2018-02-17 16:46:23 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2023-08-14 11:06:18 +00:00
|
|
|
'''
|
|
|
|
Usage: ./comps-sync.py /path/to/comps-f39.xml.in
|
|
|
|
|
|
|
|
Can both remove packages from the manifest which are not mentioned in comps,
|
|
|
|
and add packages from comps.
|
|
|
|
'''
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import yaml
|
2018-02-17 16:46:23 +00:00
|
|
|
import libcomps
|
|
|
|
|
2022-10-31 23:16:03 +00:00
|
|
|
ARCHES = ("x86_64", "aarch64", "ppc64le")
|
|
|
|
|
2018-02-17 16:46:23 +00:00
|
|
|
def fatal(msg):
|
2023-08-14 11:06:18 +00:00
|
|
|
'''Print the error message and exit.'''
|
|
|
|
print(msg, file = sys.stderr)
|
2018-02-17 16:46:23 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2023-08-14 11:06:18 +00:00
|
|
|
def format_pkgtype(pkgtype):
|
|
|
|
'''Return a printable string from a libcomps package type.'''
|
|
|
|
if pkgtype == libcomps.PACKAGE_TYPE_DEFAULT:
|
2019-04-07 10:25:53 +00:00
|
|
|
return 'default'
|
2023-08-14 11:06:18 +00:00
|
|
|
if pkgtype == libcomps.PACKAGE_TYPE_MANDATORY:
|
2019-04-07 10:25:53 +00:00
|
|
|
return 'mandatory'
|
2023-08-14 11:06:18 +00:00
|
|
|
assert False
|
2019-04-07 10:25:53 +00:00
|
|
|
|
|
|
|
def write_manifest(fpath, pkgs, include=None):
|
2023-08-14 11:06:18 +00:00
|
|
|
'''Write the package list in a manifest.'''
|
|
|
|
with open(fpath, 'w', encoding='UTF-8') as f:
|
2019-04-07 10:25:53 +00:00
|
|
|
f.write("# DO NOT EDIT! This content is generated from comps-sync.py\n")
|
|
|
|
if include is not None:
|
2023-08-14 11:06:18 +00:00
|
|
|
f.write(f'include: {include}\n')
|
2019-04-07 10:25:53 +00:00
|
|
|
f.write("packages:\n")
|
2022-10-31 23:16:03 +00:00
|
|
|
for pkg in sorted(pkgs['all']):
|
2023-08-14 11:06:18 +00:00
|
|
|
f.write(f' - {pkg}\n')
|
2022-10-31 23:16:03 +00:00
|
|
|
for arch in ARCHES:
|
|
|
|
if pkgs[arch]:
|
|
|
|
f.write(f"packages-{arch}:\n")
|
|
|
|
for pkg in sorted(pkgs[arch]):
|
2023-08-14 11:06:18 +00:00
|
|
|
f.write(f' - {pkg}\n')
|
|
|
|
print(f'Wrote {fpath}')
|
|
|
|
|
|
|
|
def is_exclude_listed(pkgname):
|
|
|
|
'''Check if pkgname is in the exclude list.'''
|
|
|
|
for br in comps_exclude_list_all:
|
|
|
|
if br.match(pkgname):
|
|
|
|
return True
|
|
|
|
return False
|
2019-04-07 10:25:53 +00:00
|
|
|
|
2018-02-17 16:46:23 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("--save", help="Write changes", action='store_true')
|
|
|
|
parser.add_argument("src", help="Source path")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2019-04-07 10:29:21 +00:00
|
|
|
print("Syncing packages common to all desktops:")
|
2018-07-15 18:10:38 +00:00
|
|
|
|
2019-04-07 10:25:53 +00:00
|
|
|
base_pkgs_path = 'fedora-common-ostree-pkgs.yaml'
|
2023-08-14 11:06:18 +00:00
|
|
|
with open(base_pkgs_path, encoding='UTF-8') as f:
|
2019-04-07 10:25:53 +00:00
|
|
|
manifest = yaml.safe_load(f)
|
2022-10-31 23:16:03 +00:00
|
|
|
manifest_packages = {}
|
|
|
|
manifest_packages['all'] = set(manifest['packages'])
|
|
|
|
for arch in ARCHES:
|
|
|
|
if f'packages-{arch}' in manifest:
|
|
|
|
manifest_packages[arch] = set(manifest[f'packages-{arch}'])
|
|
|
|
else:
|
|
|
|
manifest_packages[arch] = set()
|
2018-02-17 16:46:23 +00:00
|
|
|
|
2023-08-14 11:06:18 +00:00
|
|
|
with open('comps-sync-exclude-list.yml', encoding='UTF-8') as f:
|
2018-07-15 18:10:38 +00:00
|
|
|
doc = yaml.safe_load(f)
|
2021-01-04 10:20:45 +00:00
|
|
|
comps_exclude_list = doc['exclude_list']
|
|
|
|
comps_include_list = doc['include_list']
|
|
|
|
comps_exclude_list_groups = doc['exclude_list_groups']
|
|
|
|
comps_desktop_exclude_list = doc['desktop_exclude_list']
|
|
|
|
comps_exclude_list_all = [re.compile(x) for x in doc['exclude_list_all_regexp']]
|
|
|
|
|
2018-02-17 16:46:23 +00:00
|
|
|
# Parse comps, and build up a set of all packages so we
|
|
|
|
# can find packages not listed in comps *at all*, beyond
|
|
|
|
# just the workstation environment.
|
|
|
|
comps = libcomps.Comps()
|
|
|
|
comps.fromxml_f(args.src)
|
|
|
|
|
|
|
|
# Parse the workstation-product environment, gathering
|
|
|
|
# default or mandatory packages.
|
2018-02-24 20:29:07 +00:00
|
|
|
ws_env_name = 'workstation-product-environment'
|
|
|
|
ws_ostree_name = 'workstation-ostree-support'
|
|
|
|
ws_environ = comps.environments[ws_env_name]
|
2018-02-17 16:46:23 +00:00
|
|
|
ws_pkgs = {}
|
|
|
|
for gid in ws_environ.group_ids:
|
2021-01-04 10:20:45 +00:00
|
|
|
if gid.name in comps_exclude_list_groups:
|
2018-02-17 22:08:14 +00:00
|
|
|
continue
|
2021-01-04 10:20:45 +00:00
|
|
|
exclude_list = comps_exclude_list.get(gid.name, set())
|
2022-10-31 23:16:03 +00:00
|
|
|
for arch in ARCHES:
|
|
|
|
filtered = comps.arch_filter([arch])
|
|
|
|
group = filtered.groups_match(id=gid.name)[0]
|
|
|
|
for pkg in group.packages:
|
|
|
|
pkgname = pkg.name
|
|
|
|
if pkg.type not in (libcomps.PACKAGE_TYPE_DEFAULT,
|
|
|
|
libcomps.PACKAGE_TYPE_MANDATORY):
|
|
|
|
continue
|
|
|
|
if pkgname in exclude_list or is_exclude_listed(pkgname):
|
|
|
|
continue
|
|
|
|
pkgdata = ws_pkgs.get(pkgname)
|
|
|
|
if pkgdata is None:
|
|
|
|
ws_pkgs[pkgname] = pkgdata = (pkg.type, set([gid.name]), set([arch]))
|
|
|
|
if (pkgdata[0] == libcomps.PACKAGE_TYPE_DEFAULT and
|
|
|
|
pkg.type == libcomps.PACKAGE_TYPE_MANDATORY):
|
|
|
|
ws_pkgs[pkgname] = pkgdata = (pkg.type, pkgdata[1], pkgdata[2])
|
|
|
|
pkgdata[1].add(gid.name)
|
|
|
|
pkgdata[2].add(arch)
|
2018-02-17 16:46:23 +00:00
|
|
|
|
2018-02-24 20:29:07 +00:00
|
|
|
ws_ostree_pkgs = set()
|
|
|
|
for pkg in comps.groups_match(id=ws_ostree_name)[0].packages:
|
2021-01-04 10:20:45 +00:00
|
|
|
if not is_exclude_listed(pkg.name):
|
2019-04-13 12:02:56 +00:00
|
|
|
ws_ostree_pkgs.add(pkg.name)
|
2018-02-24 20:29:07 +00:00
|
|
|
|
2019-04-07 10:30:37 +00:00
|
|
|
comps_unknown = set()
|
2022-10-31 23:16:03 +00:00
|
|
|
for arch in manifest_packages:
|
|
|
|
for pkg in manifest_packages[arch]:
|
|
|
|
if arch == "all":
|
|
|
|
if pkg in ws_pkgs and set(ws_pkgs[pkg][2]) == set(ARCHES):
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if pkg in ws_pkgs and arch in ws_pkgs[pkg][2]:
|
|
|
|
continue
|
|
|
|
if (pkg not in comps_include_list and
|
|
|
|
pkg not in ws_ostree_pkgs):
|
|
|
|
comps_unknown.add((pkg, arch))
|
2018-02-24 20:29:07 +00:00
|
|
|
|
2018-02-17 16:46:23 +00:00
|
|
|
# Look for packages in the manifest but not in comps at all
|
|
|
|
n_manifest_new = len(comps_unknown)
|
|
|
|
if n_manifest_new == 0:
|
2019-04-07 10:29:21 +00:00
|
|
|
print(" - All manifest packages are already listed in comps.")
|
2018-02-17 16:46:23 +00:00
|
|
|
else:
|
2023-08-14 11:06:18 +00:00
|
|
|
print(f' - {n_manifest_new} packages not in {ws_env_name}:')
|
2022-10-31 23:16:03 +00:00
|
|
|
for (pkg, arch) in sorted(comps_unknown, key = lambda x: x[0]):
|
2023-08-14 11:06:18 +00:00
|
|
|
print(f' {pkg} (arch: {arch})')
|
2022-10-31 23:16:03 +00:00
|
|
|
manifest_packages[arch].remove(pkg)
|
2018-02-17 16:46:23 +00:00
|
|
|
|
|
|
|
# Look for packages in workstation but not in the manifest
|
|
|
|
ws_added = {}
|
|
|
|
for (pkg,data) in ws_pkgs.items():
|
2022-10-31 23:16:03 +00:00
|
|
|
if set(ARCHES) == set(data[2]):
|
|
|
|
if pkg not in manifest_packages['all']:
|
|
|
|
ws_added[pkg] = data
|
|
|
|
manifest_packages['all'].add(pkg)
|
|
|
|
else:
|
|
|
|
for arch in data[2]:
|
|
|
|
if pkg not in manifest_packages[arch]:
|
|
|
|
manifest_packages[arch].add(pkg)
|
|
|
|
if pkg not in ws_added:
|
|
|
|
ws_added[pkg] = (data[0], data[1], set([arch]))
|
|
|
|
else:
|
|
|
|
ws_added[pkg][2].add(arch)
|
2018-02-17 16:46:23 +00:00
|
|
|
|
|
|
|
n_comps_new = len(ws_added)
|
|
|
|
if n_comps_new == 0:
|
2019-04-07 10:29:21 +00:00
|
|
|
print(" - All comps packages are already listed in manifest.")
|
2018-02-17 16:46:23 +00:00
|
|
|
else:
|
2023-08-14 11:06:18 +00:00
|
|
|
print(f' - {n_comps_new} packages not in manifest:')
|
2018-02-17 16:46:23 +00:00
|
|
|
for pkg in sorted(ws_added):
|
2022-10-31 23:16:03 +00:00
|
|
|
(req, groups, arches) = ws_added[pkg]
|
|
|
|
print(' {} ({}, groups: {}, arches: {})'.format(pkg, format_pkgtype(req), ', '.join(groups), ', '.join(arches)))
|
2018-02-17 16:46:23 +00:00
|
|
|
|
|
|
|
if (n_manifest_new > 0 or n_comps_new > 0) and args.save:
|
2019-04-07 10:25:53 +00:00
|
|
|
write_manifest(base_pkgs_path, manifest_packages)
|
2018-07-15 18:10:38 +00:00
|
|
|
|
2022-05-19 14:59:03 +00:00
|
|
|
# List of comps groups used for each desktop
|
|
|
|
desktops_comps_groups = {
|
2023-07-18 05:33:02 +00:00
|
|
|
"gnome": ["gnome-desktop", "base-x"],
|
|
|
|
"kde": ["kde-desktop", "base-x"],
|
|
|
|
"xfce": ["xfce-desktop", "base-x"],
|
|
|
|
"lxqt": ["lxqt-desktop", "base-x"],
|
|
|
|
"deepin": ["deepin-desktop", "base-x"],
|
|
|
|
"mate": ["mate-desktop", "base-x"],
|
2022-07-08 13:22:42 +00:00
|
|
|
"sway": ["swaywm", "swaywm-extended"],
|
2023-07-18 05:33:02 +00:00
|
|
|
"cinnamon": ["cinnamon-desktop", "base-x"],
|
|
|
|
"budgie": ["budgie-desktop", "budgie-desktop-apps", "base-x"]
|
2022-05-19 14:59:03 +00:00
|
|
|
}
|
|
|
|
|
2018-07-15 18:10:38 +00:00
|
|
|
# Generate treefiles for all desktops
|
2022-05-19 14:59:03 +00:00
|
|
|
for desktop, groups in desktops_comps_groups.items():
|
2018-07-15 18:10:38 +00:00
|
|
|
print()
|
2023-08-14 11:06:18 +00:00
|
|
|
print(f'Syncing packages for {desktop}:')
|
2018-07-15 18:10:38 +00:00
|
|
|
|
2023-08-14 11:06:18 +00:00
|
|
|
manifest_path = f'{desktop}-desktop-pkgs.yaml'
|
2022-05-19 14:59:03 +00:00
|
|
|
with open(manifest_path, encoding='UTF-8') as f:
|
2019-04-07 10:25:53 +00:00
|
|
|
manifest = yaml.safe_load(f)
|
2022-10-31 23:16:03 +00:00
|
|
|
manifest_packages = {}
|
|
|
|
manifest_packages['all'] = set(manifest['packages'])
|
|
|
|
for arch in ARCHES:
|
|
|
|
if f'packages-{arch}' in manifest:
|
|
|
|
manifest_packages[arch] = set(manifest[f'packages-{arch}'])
|
|
|
|
else:
|
|
|
|
manifest_packages[arch] = set()
|
2018-07-15 18:10:38 +00:00
|
|
|
|
2021-01-04 10:20:45 +00:00
|
|
|
# Filter packages in the comps desktop group using the exclude_list
|
2022-10-31 23:16:03 +00:00
|
|
|
comps_group_pkgs = {}
|
|
|
|
for arch in ARCHES:
|
|
|
|
filtered = comps.arch_filter([arch])
|
2022-05-19 14:59:03 +00:00
|
|
|
for group in groups:
|
|
|
|
for pkg in filtered.groups_match(id=group)[0].packages:
|
|
|
|
pkgname = pkg.name
|
|
|
|
exclude_list = comps_desktop_exclude_list.get(group, set())
|
|
|
|
if pkgname in exclude_list or is_exclude_listed(pkgname):
|
|
|
|
continue
|
|
|
|
if pkgname in comps_group_pkgs:
|
|
|
|
comps_group_pkgs[pkgname].add(arch)
|
|
|
|
else:
|
|
|
|
comps_group_pkgs[pkgname] = set([arch])
|
2018-07-15 18:10:38 +00:00
|
|
|
|
2022-10-31 23:16:03 +00:00
|
|
|
comps_unknown = set()
|
|
|
|
for arch in manifest_packages:
|
|
|
|
for pkg in manifest_packages[arch]:
|
|
|
|
if arch == "all":
|
|
|
|
if pkg in comps_group_pkgs and set(comps_group_pkgs[pkg]) == set(ARCHES):
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if pkg in comps_group_pkgs and arch in comps_group_pkgs[pkg]:
|
|
|
|
continue
|
|
|
|
comps_unknown.add((pkg, arch))
|
|
|
|
|
|
|
|
# Look for packages in the manifest but not in comps at all
|
2018-07-15 18:10:38 +00:00
|
|
|
n_manifest_new = len(comps_unknown)
|
|
|
|
if n_manifest_new == 0:
|
2019-04-07 10:29:21 +00:00
|
|
|
print(" - All manifest packages are already listed in comps.")
|
2018-07-15 18:10:38 +00:00
|
|
|
else:
|
2023-08-14 11:06:18 +00:00
|
|
|
print(f' - {n_manifest_new} packages not in {ws_env_name}:')
|
2022-10-31 23:16:03 +00:00
|
|
|
for (pkg, arch) in sorted(comps_unknown, key = lambda x: x[0]):
|
2023-08-14 11:06:18 +00:00
|
|
|
print(f' {pkg} (arch: {arch})')
|
2022-10-31 23:16:03 +00:00
|
|
|
manifest_packages[arch].remove(pkg)
|
|
|
|
|
2018-07-15 18:10:38 +00:00
|
|
|
|
2018-08-07 18:56:47 +00:00
|
|
|
# Look for packages in comps but not in the manifest
|
2022-10-31 23:16:03 +00:00
|
|
|
desktop_pkgs_added = {}
|
|
|
|
for (pkg, parches) in comps_group_pkgs.items():
|
|
|
|
if set(ARCHES) == set(parches):
|
|
|
|
if pkg not in manifest_packages['all']:
|
|
|
|
desktop_pkgs_added[pkg] = parches
|
|
|
|
manifest_packages['all'].add(pkg)
|
|
|
|
else:
|
|
|
|
for arch in parches:
|
|
|
|
if pkg not in manifest_packages[arch]:
|
|
|
|
manifest_packages[arch].add(pkg)
|
|
|
|
if pkg not in desktop_pkgs_added:
|
|
|
|
desktop_pkgs_added[pkg] = set([arch])
|
|
|
|
else:
|
|
|
|
desktop_pkgs_added[pkg].add(arch)
|
2018-07-15 18:10:38 +00:00
|
|
|
|
2019-04-07 10:30:37 +00:00
|
|
|
n_comps_new = len(desktop_pkgs_added)
|
2018-07-15 18:10:38 +00:00
|
|
|
if n_comps_new == 0:
|
2019-04-07 10:29:21 +00:00
|
|
|
print(" - All comps packages are already listed in manifest.")
|
2018-07-15 18:10:38 +00:00
|
|
|
else:
|
2023-08-14 11:06:18 +00:00
|
|
|
print(f' - {n_comps_new} packages not in {desktop} manifest:')
|
2019-04-07 10:30:37 +00:00
|
|
|
for pkg in sorted(desktop_pkgs_added):
|
2022-10-31 23:16:03 +00:00
|
|
|
arches = desktop_pkgs_added[pkg]
|
|
|
|
print(' {} (arches: {})'.format(pkg, ', '.join(arches)))
|
2018-07-15 18:10:38 +00:00
|
|
|
|
2019-04-07 10:30:37 +00:00
|
|
|
# Update manifest
|
2018-07-15 18:10:38 +00:00
|
|
|
if (n_manifest_new > 0 or n_comps_new > 0) and args.save:
|
2019-04-07 10:25:53 +00:00
|
|
|
write_manifest(manifest_path, manifest_packages, include="fedora-common-ostree.yaml")
|