archive/listing.py

45 lines
1.0 KiB
Python

#!/usr/bin/python
import record
import sys
red = '\033[31m'
blue = '\033[34m'
green = '\033[32m'
reset = '\033[0m'
def printRecord(rec, level):
try: filename = rec.data['file']
except KeyError: filename = None
# TODO: if multi-inherit, specify correct inherit_order
try: index = rec.data['inherit_order']
except KeyError: index = None
print(" " * level +
f"[{red}{index}{reset}] {green}{rec.name}{reset}, {blue}{filename}{reset}")
for i in rec.children:
printRecord(rec.children[i], level + 1)
def main():
try:
rec = record.RecordCollection(sys.argv[1])
except IndexError:
print(f"[{red}error{reset}] you didn't specify the file!")
return
except FileNotFoundError:
print(f"[{red}error{reset}] the file doesn't exist!")
return
except record.FileParsingError:
print(f"[{red}error{reset}] error parsing file!")
return
entries = rec.findEntrypoints()
for i in entries:
printRecord(i, 0)
if __name__ == '__main__':
main()