My understanding is that pacman -Qi will reliably tell you the packager because it is getting the information from the 'desc' files under /var/lib/pacman/local. I could be wrong ?
Poorly written Python that chatgpt and I came up with. This definitely gets it's information from the 'desc' files
#!/usr/bin/env python3
### getdistro.py
import os
def get_distro(d_file):
with open(d_file, 'r') as file:
lines = file.readlines()
for i, line in enumerate(lines):
if line.strip() == '%NAME%':
package_name = lines[i + 1].strip()
p_dict = {'package_name': package_name}
p_list.append(p_dict)
if line.strip() == '%PACKAGER%':
packager = lines[i + 1].strip()
if "archlinux" in packager:
distro = "Arch"
elif "artix" in packager:
distro = "Artix"
else:
distro = "Unknown"
p_dict['distro'] = distro
break
def write_list_to_file(lst, filename):
with open(filename, 'w') as file:
for item in lst:
file.write(str(item) + '\n')
local_dir = "/var/lib/pacman/local"
p_list = []
dirs = os.listdir(local_dir)
dirs.sort()
for p_dir in dirs:
p_dir = os.path.join(local_dir, p_dir)
if not os.path.isdir(p_dir):
continue
desc_file = os.path.join(p_dir, "desc")
get_distro(desc_file)
arch_packages = [p for p in p_list if p.get('distro') == 'Arch']
artix_packages = [p for p in p_list if p.get('distro') == 'Artix']
unknown_packages = [p for p in p_list if p.get('distro') == 'Unknown']
arch_package_names = [package['package_name'] for package in arch_packages]
artix_package_names = [package['package_name'] for package in artix_packages]
unknown_package_names = [package['package_name'] for package in unknown_packages]
write_list_to_file(arch_package_names, 'Arch.txt')
write_list_to_file(artix_package_names, 'Artix.txt')
write_list_to_file(unknown_package_names, 'Unknown.txt')
print("Arch Packages:")
for package in arch_packages:
print(package['package_name'])
print("\nArtix Packages:")
for package in artix_packages:
print(package['package_name'])
print("\nUnknown Packages:")
for package in unknown_packages:
print(package['package_name'])