#!/usr/bin/python3 -Bsu

import os
import stat
import logging
import sys

# Configure logging to output to stderr
logging.basicConfig(
    stream=sys.stderr,
    level=logging.ERROR,
    format='%(message)s'
)

stat_list = [
    '/bin', '/boot', '/etc', '/home', '/lib', '/lib64', '/media',
    '/mnt', '/opt', '/root', '/sbin', '/srv', '/tmp', '/usr',
    '/var', '/initrd.img', '/vmlinuz'
]

idx = 0
while idx < len(stat_list):
    item = stat_list[idx]
    try:
        statrslt = os.stat(item)
        print("{} |-| {} |-| {} |-| {}".format(
            item,
            statrslt[stat.ST_UID],
            statrslt[stat.ST_GID],
            stat.filemode(statrslt[stat.ST_MODE])
        ))
        if os.path.isdir(item) and not os.path.islink(item):
            subitems = os.listdir(item)
            for subitem in subitems:
                stat_list.append(item + '/' + subitem)
    except Exception as e:
        logging.error("Error processing item %s: %s", item, e)
    idx += 1
