Format python files.
I used yapf to apply to Google style but I had to install with pip and
invoke the library as a script so not suitable for integration yet.
Change-Id: I8c3d9c334bf1766f0fff7217270c148a3d1d7662
diff --git a/build/image/convert_to_binary.py b/build/image/convert_to_binary.py
index bf50a8e..2935ec8 100644
--- a/build/image/convert_to_binary.py
+++ b/build/image/convert_to_binary.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-
"""Convert a file to binary format.
Calls objcopy to convert a file into raw binary format.
@@ -9,19 +8,19 @@
import subprocess
import sys
+
def Main():
- parser = argparse.ArgumentParser()
- parser.add_argument("--tool_prefix", required=True)
- parser.add_argument("--input", required=True)
- parser.add_argument("--output", required=True)
- args = parser.parse_args()
- subprocess.check_call([
- "{}objcopy".format(args.tool_prefix),
- "-O",
- "binary",
- args.input,
- args.output])
- return 0
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--tool_prefix", required=True)
+ parser.add_argument("--input", required=True)
+ parser.add_argument("--output", required=True)
+ args = parser.parse_args()
+ subprocess.check_call([
+ "{}objcopy".format(args.tool_prefix), "-O", "binary", args.input,
+ args.output
+ ])
+ return 0
+
if __name__ == "__main__":
- sys.exit(Main())
+ sys.exit(Main())
diff --git a/build/image/extract_offsets.py b/build/image/extract_offsets.py
index 23e711a..c52d01b 100644
--- a/build/image/extract_offsets.py
+++ b/build/image/extract_offsets.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-
"""Extract embedded offsets from an object file.
We let the compiler calculate the offsets it is going to use and have those
@@ -12,35 +11,35 @@
import subprocess
import sys
+
def Main():
- parser = argparse.ArgumentParser()
- parser.add_argument("--tool_prefix", required=True)
- parser.add_argument("--input", required=True)
- parser.add_argument("--output", required=True)
- args = parser.parse_args()
- raw = subprocess.check_output([
- "{}objdump".format(args.tool_prefix),
- "--disassemble-all",
- "--section",
- ".rodata",
- args.input])
- lines = raw.split('\n')
- with open(args.output, 'w') as header:
- header.write('#pragma once\n\n')
- for n in range(len(lines)):
- # Find a defined offset
- match = re.match('.+DEFINE_OFFSET__([^>]+)', lines[n])
- if not match:
- continue
- name = match.group(1)
- # The next line tells the offset
- if "..." in lines[n + 1]:
- offset = 0
- else:
- offset = re.match('.+\.[\S]+\s+(.+)$', lines[n + 1]).group(1)
- # Write the offset to the header
- header.write("#define {} {}\n".format(name, offset))
- return 0
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--tool_prefix", required=True)
+ parser.add_argument("--input", required=True)
+ parser.add_argument("--output", required=True)
+ args = parser.parse_args()
+ raw = subprocess.check_output([
+ "{}objdump".format(args.tool_prefix), "--disassemble-all", "--section",
+ ".rodata", args.input
+ ])
+ lines = raw.split('\n')
+ with open(args.output, 'w') as header:
+ header.write('#pragma once\n\n')
+ for n in range(len(lines)):
+ # Find a defined offset
+ match = re.match('.+DEFINE_OFFSET__([^>]+)', lines[n])
+ if not match:
+ continue
+ name = match.group(1)
+ # The next line tells the offset
+ if "..." in lines[n + 1]:
+ offset = 0
+ else:
+ offset = re.match('.+\.[\S]+\s+(.+)$', lines[n + 1]).group(1)
+ # Write the offset to the header
+ header.write("#define {} {}\n".format(name, offset))
+ return 0
+
if __name__ == "__main__":
- sys.exit(Main())
+ sys.exit(Main())
diff --git a/build/image/generate_initrd.py b/build/image/generate_initrd.py
index 488745f..28e1680 100644
--- a/build/image/generate_initrd.py
+++ b/build/image/generate_initrd.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-
"""Generate an initial RAM disk for the hypervisor.
Packages the VMs, initrds for the VMs and the list of secondary VMs (vms.txt)
@@ -12,44 +11,50 @@
import subprocess
import sys
+
def Main():
- parser = argparse.ArgumentParser()
- parser.add_argument("--primary_vm", required=True)
- parser.add_argument("--primary_vm_initrd")
- parser.add_argument("--secondary_vm", action="append", nargs=4, metavar=("MEMORY", "CORES", "NAME", "IMAGE"))
- parser.add_argument("--staging", required=True)
- parser.add_argument("--output", required=True)
- args = parser.parse_args()
- # Prepare the primary VM image.
- staged_files = ["vmlinuz"]
- shutil.copyfile(args.primary_vm, os.path.join(args.staging, "vmlinuz"))
- # Prepare the primary VM's initrd. Currently, it just makes an empty one.
- if args.primary_vm_initrd:
- raise NotImplementedError("This doesn't copy the primary VM's initrd yet")
- with open(os.path.join(args.staging, "initrd.img"), "w") as vms_txt:
- staged_files.append("initrd.img")
- # Prepare the secondary VMs.
- with open(os.path.join(args.staging, "vms.txt"), "w") as vms_txt:
- staged_files.append("vms.txt")
- if args.secondary_vm:
- for vm in args.secondary_vm:
- (vm_memory, vm_cores, vm_name, vm_image) = vm
- staged_files.append(vm_name)
- shutil.copy(vm_image, os.path.join(args.staging, vm_name))
- vms_txt.write("{} {} {}\n".format(vm_memory, vm_cores, vm_name))
- # Package files into an initial RAM disk.
- with open(args.output, "w") as initrd:
- # Move into the staging directory so the file names taken by cpio don't
- # include the path.
- os.chdir(args.staging)
- cpio = subprocess.Popen([
- "cpio",
- "--create"],
- stdin=subprocess.PIPE,
- stdout=initrd,
- stderr=subprocess.PIPE)
- cpio.communicate(input="\n".join(staged_files).encode("utf-8"))
- return 0
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--primary_vm", required=True)
+ parser.add_argument("--primary_vm_initrd")
+ parser.add_argument(
+ "--secondary_vm",
+ action="append",
+ nargs=4,
+ metavar=("MEMORY", "CORES", "NAME", "IMAGE"))
+ parser.add_argument("--staging", required=True)
+ parser.add_argument("--output", required=True)
+ args = parser.parse_args()
+ # Prepare the primary VM image.
+ staged_files = ["vmlinuz"]
+ shutil.copyfile(args.primary_vm, os.path.join(args.staging, "vmlinuz"))
+ # Prepare the primary VM's initrd. Currently, it just makes an empty one.
+ if args.primary_vm_initrd:
+ raise NotImplementedError(
+ "This doesn't copy the primary VM's initrd yet")
+ with open(os.path.join(args.staging, "initrd.img"), "w") as vms_txt:
+ staged_files.append("initrd.img")
+ # Prepare the secondary VMs.
+ with open(os.path.join(args.staging, "vms.txt"), "w") as vms_txt:
+ staged_files.append("vms.txt")
+ if args.secondary_vm:
+ for vm in args.secondary_vm:
+ (vm_memory, vm_cores, vm_name, vm_image) = vm
+ staged_files.append(vm_name)
+ shutil.copy(vm_image, os.path.join(args.staging, vm_name))
+ vms_txt.write("{} {} {}\n".format(vm_memory, vm_cores, vm_name))
+ # Package files into an initial RAM disk.
+ with open(args.output, "w") as initrd:
+ # Move into the staging directory so the file names taken by cpio don't
+ # include the path.
+ os.chdir(args.staging)
+ cpio = subprocess.Popen(
+ ["cpio", "--create"],
+ stdin=subprocess.PIPE,
+ stdout=initrd,
+ stderr=subprocess.PIPE)
+ cpio.communicate(input="\n".join(staged_files).encode("utf-8"))
+ return 0
+
if __name__ == "__main__":
- sys.exit(Main())
+ sys.exit(Main())