ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
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')
ac3a84
o_boot = open('.file-list-boot', '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_oomd = open('.file-list-oomd', 'w')
4295f9
o_remote = open('.file-list-remote', 'w')
ac3a84
o_resolve = open('.file-list-resolve', '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')
ac3a84
o_main = open('.file-list-main', '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
ac3a84
    elif re.search(r'/libsystemd-(shared|core)-.*\.so$', n):
ac3a84
        o = o_main
ac3a84
    elif re.search(r'/libcryptsetup-token-systemd-.*\.so$', n):
ac3a84
        o = o_udev
ac3a84
    elif re.search(r'/lib.*\.pc|/man3/|/usr/include|\.so$', n):
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
ac3a84
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
ac3a84
4295f9
    elif re.search(r'''/usr/lib/systemd/network/80-|
4295f9
                       networkd|
4295f9
                       networkctl|
ac3a84
                       org.freedesktop.network1|
ac3a84
                       sysusers\.d/systemd-network.conf|
ac3a84
                       tmpfiles\.d/systemd-network.conf|
ac3a84
                       systemd\.network|
ac3a84
                       systemd\.netdev
4295f9
    ''', n, re.X):
4295f9
        o = o_networkd
ac3a84
4295f9
    elif '.so.' in n:
4295f9
        o = o_libs
ac3a84
4295f9
    elif re.search(r'''udev(?!\.pc)|
4295f9
                       hwdb|
4295f9
                       bootctl|
ac3a84
                       boot-update|
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|
ac3a84
                       crypttab|
152484
                       cryptenroll|
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|
ac3a84
                       veritysetup|
ac3a84
                       integritysetup|
ac3a84
                       integritytab|
4295f9
                       remount-fs|
ac3a84
                       /initrd|
ac3a84
                       systemd-pcrphase|
ac3a84
                       systemd-measure|
4295f9
                       /boot$|
4295f9
                       /kernel/|
4295f9
                       /kernel$|
ac3a84
                       /modprobe.d|
ac3a84
                       binfmt|
ac3a84
                       sysctl|
ac3a84
                       coredump|
ac3a84
                       homed|home1|
ac3a84
                       portabled|portable1
ac3a84
    ''', n, re.X):     # coredumpctl, homectl, portablectl are included in the main package because
ac3a84
                       # they can be used to interact with remote daemons. Also, the user could be
ac3a84
                       # confused if those user-facing binaries are not available.
4295f9
        o = o_udev
ac3a84
ac3a84
    elif re.search(r'''/boot/efi''', n, re.X):
ac3a84
        o = o_boot
ac3a84
ac3a84
    elif re.search(r'''resolved|resolve1|
ac3a84
                       resolvectl|
ac3a84
                       systemd-resolve|
ac3a84
                       resolvconf|
ac3a84
                       systemd\.(positive|negative)|
ac3a84
                       nss-resolve
ac3a84
    ''', n, re.X):     # resolvectl and nss-resolve are in the main package.
ac3a84
        o = o_resolve
ac3a84
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
ac3a84
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'
ac3a84
4295f9
    else:
ac3a84
        o = o_main
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)