ryantimwilson / rpms / systemd

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