2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-03 07:45:17 +00:00

py: Reformat everything into pep8 style

As discussed on the mailing list, current .py files formatting does not
conform to the world standard, so we should better reformat it. For this
the yapf tool is used. The command I used was

  yapf -i $(find -name *.py)

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
Andrei Vagin
2019-09-07 15:46:22 +03:00
parent 5ff4fcb753
commit 5aa72e7237
28 changed files with 5738 additions and 5167 deletions

View File

@@ -1,61 +1,63 @@
#!/bin/env python2
import sys
# 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)
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]
magic_c_header = argv[1]
magic_py = argv[2]
out = open(magic_py, 'w+')
out = open(magic_py, 'w+')
# all_magic is used to parse constructions like:
# #define PAGEMAP_MAGIC 0x56084025
# #define SHMEM_PAGEMAP_MAGIC PAGEMAP_MAGIC
all_magic = {}
# and magic is used to store only unique magic.
magic = {}
# all_magic is used to parse constructions like:
# #define PAGEMAP_MAGIC 0x56084025
# #define SHMEM_PAGEMAP_MAGIC PAGEMAP_MAGIC
all_magic = {}
# and magic is used to store only unique magic.
magic = {}
f = open(magic_c_header, 'r')
for line in f:
split = line.split()
f = open(magic_c_header, 'r')
for line in f:
split = line.split()
if len(split) < 3:
continue
if len(split) < 3:
continue
if not '#define' in split[0]:
continue
if not '#define' in split[0]:
continue
key = split[1]
value = split[2]
key = split[1]
value = split[2]
if value in all_magic:
value = all_magic[value]
else:
magic[key] = value
if value in all_magic:
value = all_magic[value]
else:
magic[key] = value
all_magic[key] = value
all_magic[key] = value
out.write('#Autogenerated. Do not edit!\n')
out.write('by_name = {}\n')
out.write('by_val = {}\n')
for k, v in list(magic.items()):
# We don't need RAW or V1 magic, because
# they can't be used to identify images.
if v == '0x0' or v == '1' or k == '0x0' or v == '1':
continue
if k.endswith("_MAGIC"):
# Just cutting _MAGIC suffix
k = k[:-6]
v = int(v, 16)
out.write("by_name['" + k + "'] = " + str(v) + "\n")
out.write("by_val[" + str(v) + "] = '" + k + "'\n")
f.close()
out.close()
out.write('#Autogenerated. Do not edit!\n')
out.write('by_name = {}\n')
out.write('by_val = {}\n')
for k,v in list(magic.items()):
# We don't need RAW or V1 magic, because
# they can't be used to identify images.
if v == '0x0' or v == '1' or k == '0x0' or v == '1':
continue
if k.endswith("_MAGIC"):
# Just cutting _MAGIC suffix
k = k[:-6]
v = int(v, 16)
out.write("by_name['"+ k +"'] = "+ str(v) +"\n")
out.write("by_val["+ str(v) +"] = '"+ k +"'\n")
f.close()
out.close()
if __name__ == "__main__":
main(sys.argv)
main(sys.argv)