aboutsummaryrefslogtreecommitdiffstats
path: root/print_dep.py
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2014-08-13 17:30:02 +0200
committerTharre <tharre3@gmail.com>2014-08-13 17:34:08 +0200
commitd09eb6c95b85fcb22d6b36353c82c3b4293e6fb7 (patch)
tree4574d2a1fbc04671c889caf49da64a73d4d74904 /print_dep.py
parent325c8e3992bf7b73714d10a5d2202c89ddbac189 (diff)
downloadredo-d09eb6c95b85fcb22d6b36353c82c3b4293e6fb7.tar.gz
redo-d09eb6c95b85fcb22d6b36353c82c3b4293e6fb7.tar.xz
redo-d09eb6c95b85fcb22d6b36353c82c3b4293e6fb7.zip
Implement (incomplete) dependency checking.
Targets still do not depend on .do-files, and a lot of the edge cases are still not handled correctly. Furthermore some error-checking code is still missing, which could possibly crash the program (partially marked with comments), as well as some free() calls. An utitlity python script (print_dep.py) was also added to aid in debugging matters.
Diffstat (limited to 'print_dep.py')
-rwxr-xr-xprint_dep.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/print_dep.py b/print_dep.py
new file mode 100755
index 0000000..803b5e9
--- /dev/null
+++ b/print_dep.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+
+# quick and dirty utility to make the binary mess, produced by my redo program
+# into something more friendly to the human eye
+# requires termcolor (pip install termcolor)
+
+import struct
+import sys
+import hashlib
+from binascii import hexlify
+from os.path import basename
+from termcolor import colored
+
+def convert_back(s):
+ return s.replace('!', '/')
+
+if (len(sys.argv) < 2):
+ print("Need an argument.")
+ exit(1)
+
+hasher = hashlib.sha1()
+file = open(sys.argv[1], 'rb')
+magic = file.read(4)
+hash = file.read(20)
+subdeps = file.read()
+org_file = convert_back(basename(sys.argv[1]))
+
+hash_str = str(hexlify(hash), 'ascii')
+
+with open(org_file, 'rb') as f:
+ buf = f.read()
+ hasher.update(buf)
+
+print("Target: " + org_file)
+print("Hash: " + hash_str + " ", end="")
+if hasher.hexdigest() == hash_str:
+ print(colored(u"\u2714", "green", attrs=['bold']))
+else:
+ print(colored(u"\u2718", "red", attrs=['bold']))
+
+print("Magic number: " + str(struct.unpack('i', magic)[0]))
+print("Dependencies:")
+start = True
+thing = ""
+for byte in subdeps:
+ if start:
+ print(" " + chr(byte) + "-", end="")
+ start = False
+ elif byte == 0:
+ start = True
+ print(thing)
+ thing = ""
+ else:
+ thing += chr(byte)
+ continue