add listing.py to list out data

This commit is contained in:
randomuser 2021-11-22 22:38:32 -06:00
parent 4b4da419dd
commit 72f45811c7
1 changed files with 44 additions and 0 deletions

44
listing.py Normal file
View File

@ -0,0 +1,44 @@
#!/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 FileParsingError:
print(f"[{red}error{reset}] error parsing file!")
return
entries = rec.findEntrypoints()
for i in entries:
printRecord(i, 0)
if __name__ == '__main__':
main()