teknoraver / rpms / systemd

Forked from rpms/systemd a month ago
Clone

Blame SOURCES/split-files.py

aa0848
import re, sys, os, collections
aa0848
aa0848
buildroot = sys.argv[1]
aa0848
known_files = sys.stdin.read().splitlines()
aa0848
known_files = {line.split()[-1]:line for line in known_files}
aa0848
aa0848
def files(root):
aa0848
    os.chdir(root)
aa0848
    todo = collections.deque(['.'])
aa0848
    while todo:
aa0848
        n = todo.pop()
aa0848
        files = os.scandir(n)
aa0848
        for file in files:
aa0848
            yield file
aa0848
            if file.is_dir() and not file.is_symlink():
aa0848
                todo.append(file)
aa0848
aa0848
o_libs = open('.file-list-libs', 'w')
aa0848
o_udev = open('.file-list-udev', 'w')
aa0848
o_pam = open('.file-list-pam', 'w')
aa0848
o_rpm_macros = open('.file-list-rpm-macros', 'w')
aa0848
o_devel = open('.file-list-devel', 'w')
aa0848
o_container = open('.file-list-container', 'w')
aa0848
o_networkd = open('.file-list-networkd', 'w')
aa0848
o_resolved = open('.file-list-resolved', 'w')
aa0848
o_oomd = open('.file-list-oomd', 'w')
aa0848
o_remote = open('.file-list-remote', 'w')
aa0848
o_tests = open('.file-list-tests', 'w')
aa0848
o_standalone_tmpfiles = open('.file-list-standalone-tmpfiles', 'w')
aa0848
o_standalone_sysusers = open('.file-list-standalone-sysusers', 'w')
aa0848
o_rest = open('.file-list-rest', 'w')
aa0848
for file in files(buildroot):
aa0848
    n = file.path[1:]
aa0848
    if re.match(r'''/usr/(share|include)$|
aa0848
                    /usr/share/man(/man.|)$|
aa0848
                    /usr/share/zsh(/site-functions|)$|
aa0848
                    /usr/share/dbus-1$|
aa0848
                    /usr/share/dbus-1/system.d$|
aa0848
                    /usr/share/dbus-1/(system-|)services$|
aa0848
                    /usr/share/polkit-1(/actions|/rules.d|)$|
aa0848
                    /usr/share/pkgconfig$|
aa0848
                    /usr/share/bash-completion(/completions|)$|
aa0848
                    /usr(/lib|/lib64|/bin|/sbin|)$|
aa0848
                    /usr/lib.*/(security|pkgconfig)$|
aa0848
                    /usr/lib/rpm(/macros.d|)$|
aa0848
                    /usr/lib/firewalld(/services|)$|
aa0848
                    /usr/share/(locale|licenses|doc)|             # no $
aa0848
                    /etc(/pam\.d|/xdg|/X11|/X11/xinit|/X11.*\.d|)$|
aa0848
                    /etc/(dnf|dnf/protected.d)$|
aa0848
                    /usr/(src|lib/debug)|                         # no $
aa0848
                    /run$|
aa0848
                    /var(/cache|/log|/lib|/run|)$
aa0848
    ''', n, re.X):
aa0848
        continue
aa0848
    if '/security/pam_' in n or '/man8/pam_' in n:
aa0848
        o = o_pam
aa0848
    elif '/rpm/' in n:
aa0848
        o = o_rpm_macros
aa0848
    elif '/usr/lib/systemd/tests' in n:
aa0848
        o = o_tests
aa0848
    elif re.search(r'/lib.*\.pc|/man3/|/usr/include|(?
aa0848
        o = o_devel
aa0848
    elif re.search(r'''journal-(remote|gateway|upload)|
aa0848
                       systemd-remote\.conf|
aa0848
                       /usr/share/systemd/gatewayd|
aa0848
                       /var/log/journal/remote
aa0848
    ''', n, re.X):
aa0848
        o = o_remote
aa0848
    elif re.search(r'''mymachines|
aa0848
                       machinectl|
aa0848
                       systemd-nspawn|
aa0848
                       import-pubring.gpg|
aa0848
                       systemd-(machined|import|pull)|
aa0848
                       /machine.slice|
aa0848
                       /machines.target|
aa0848
                       var-lib-machines.mount|
aa0848
                       org.freedesktop.(import|machine)1
aa0848
    ''', n, re.X):
aa0848
        o = o_container
aa0848
    elif re.search(r'''/usr/lib/systemd/network/80-|
aa0848
                       networkd|
aa0848
                       networkctl|
aa0848
                       org.freedesktop.network1
aa0848
    ''', n, re.X):
aa0848
        o = o_networkd
aa0848
    elif re.search(r'''resolved|
aa0848
                       resolvectl|
aa0848
                       resolvconf|
aa0848
                       org.freedesktop.resolve1|
aa0848
                       systemd-resolve|
aa0848
                       nss-resolve
aa0848
    ''', n, re.X):
aa0848
        o = o_resolved
aa0848
    elif '.so.' in n:
aa0848
        o = o_libs
aa0848
    elif re.search(r'''udev(?!\.pc)|
aa0848
                       hwdb|
aa0848
                       bootctl|
aa0848
                       sd-boot|systemd-boot\.|loader.conf|
aa0848
                       bless-boot|
aa0848
                       boot-system-token|
aa0848
                       kernel-install|
aa0848
                       vconsole|
aa0848
                       backlight|
aa0848
                       rfkill|
aa0848
                       random-seed|
aa0848
                       modules-load|
aa0848
                       timesync|
aa0848
                       cryptenroll|
aa0848
                       cryptsetup|
aa0848
                       kmod|
aa0848
                       quota|
aa0848
                       pstore|
aa0848
                       sleep|suspend|hibernate|
aa0848
                       systemd-tmpfiles-setup-dev|
aa0848
                       network/99-default.link|
aa0848
                       growfs|makefs|makeswap|mkswap|
aa0848
                       fsck|
aa0848
                       repart|
aa0848
                       gpt-auto|
aa0848
                       volatile-root|
aa0848
                       verity-setup|
aa0848
                       remount-fs|
aa0848
                       /boot$|
aa0848
                       /boot/efi|
aa0848
                       /kernel/|
aa0848
                       /kernel$|
aa0848
                       /modprobe.d
aa0848
    ''', n, re.X):
aa0848
        o = o_udev
aa0848
    elif re.search(r'''10-oomd-.*defaults\.conf|
aa0848
                       oomd\.conf|
aa0848
                       oomctl|
aa0848
                       org.freedesktop.oom1|
aa0848
                       systemd-oomd
aa0848
    ''', n, re.X):
aa0848
        o = o_oomd
aa0848
    elif n.endswith('.standalone'):
aa0848
        if 'tmpfiles' in n:
aa0848
            o = o_standalone_tmpfiles
aa0848
        elif 'sysusers' in n:
aa0848
            o = o_standalone_sysusers
aa0848
        else:
aa0848
            assert False, 'Found .standalone not belonging to known packages'
aa0848
    else:
aa0848
        o = o_rest
aa0848
aa0848
    if n in known_files:
aa0848
        prefix = ' '.join(known_files[n].split()[:-1])
aa0848
        if prefix:
aa0848
            prefix += ' '
aa0848
    elif file.is_dir() and not file.is_symlink():
aa0848
        prefix = '%dir '
aa0848
    elif 'README' in n:
aa0848
        prefix = '%doc '
aa0848
    elif n.startswith('/etc'):
aa0848
        prefix = '%config(noreplace) '
aa0848
    else:
aa0848
        prefix = ''
aa0848
aa0848
    suffix = '*' if '/man/' in n else ''
aa0848
aa0848
    print(f'{prefix}{n}{suffix}', file=o)