#!/usr/bin/env python3

import os
import sys
import pickle


rootDir = sys.argv[1]


def remove_root(d):
    return d.replace(rootDir, "/")


def print_stats(d, f):
    st = os.lstat(os.path.join(d, f))
    relpath = remove_root(d)
    info = (st.st_atime, st.st_ctime, st.st_gid, st.st_mode, st.st_mtime, st.st_nlink, st.st_size, st.st_uid)
    line = "%s|%s|%s|%s|%s|%s|%s|%s" % info
    return line


if __name__ == "__main__":
    # check for trailing slash
    if rootDir[-1] != "/":
        rootDir = rootDir + "/"
    for dirName, subdirList, fileList in os.walk(rootDir, followlinks=False):
        print("F|"+remove_root(dirName) + "|" + print_stats(dirName, "."))
        for fname in fileList:
            print(remove_root(dirName) + "|" + fname + "|" + print_stats(dirName, fname))
            if(os.path.islink(os.path.join(dirName, fname))):
                print("S|" + os.path.join(remove_root(dirName), fname) + "|" + remove_root(os.path.realpath(os.path.join(dirName, fname))))
        for fname in subdirList:
            print(remove_root(dirName) + "|" + fname + "|" + print_stats(dirName, fname))
            if(os.path.islink(os.path.join(dirName, fname))):
                print("S|" + os.path.join(remove_root(dirName), fname) + "|" + remove_root(os.path.realpath(os.path.join(dirName, fname))))