teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/split-files.py

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