[CRIU] [PATCH 1/7] scripts: add magic-gen.py
Ruslan Kuprieiev
kupruser at gmail.com
Mon Nov 3 07:56:33 PST 2014
This script is needed to generate python module from
include/magic.h file, that contains magic numbers that
we put into our criu *.img files.
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
scripts/magic-gen.py | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100755 scripts/magic-gen.py
diff --git a/scripts/magic-gen.py b/scripts/magic-gen.py
new file mode 100755
index 0000000..bb09ded
--- /dev/null
+++ b/scripts/magic-gen.py
@@ -0,0 +1,45 @@
+#!/bin/env python
+import os, sys
+import struct
+
+# This program parses criu magic.h file and produces
+# magic.py with all *_MAGIC constants except RAW and V1.
+def main(argv):
+ if len(argv) != 3:
+ print("Usage: magic-gen.py path/to/image.h path/to/magic.py")
+ exit(1)
+
+ magic_c_header = argv[1]
+ magic_py = argv[2]
+
+ out = open(magic_py, 'w+')
+
+ magic = {}
+
+ f = open(magic_c_header, 'r')
+ for line in f:
+ split = line.split()
+
+ if len(split) < 3:
+ continue
+
+ if not '#define' in split[0]:
+ continue
+
+ key = split[1]
+ value = split[2]
+
+ if value in magic:
+ value = magic[value]
+
+ magic[key] = value
+
+ if value == '0x0' or value == '1':
+ continue
+
+ out.write(key+" = "+"\'"+value+"\'\n")
+ f.close()
+ out.close()
+
+if __name__ == "__main__":
+ main(sys.argv)
--
1.9.3
More information about the CRIU
mailing list