teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/split-files.py

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