Skip to content

Commit f255780

Browse files
committed
ptool, msp, utils, gen_partition, gen_contents: apply black formatting
Enforces a consistent, machine-verified code style using black tool [1] across all Python sources so that future diffs reflect only logic changes and not incidental whitespace or quoting differences. [1] https://github.com/psf/black Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
1 parent 938f948 commit f255780

5 files changed

Lines changed: 3958 additions & 2126 deletions

File tree

gen_contents.py

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010

1111
def usage():
12-
print(("\n\tUsage: %s -t <template> -p <partitions_xml_path> -o <output> \n\tVersion 0.1\n" % (sys.argv[0])))
12+
print(
13+
(
14+
"\n\tUsage: %s -t <template> -p <partitions_xml_path> -o <output> \n\tVersion 0.1\n"
15+
% (sys.argv[0])
16+
)
17+
)
1318
sys.exit(1)
1419

1520

@@ -27,22 +32,22 @@ def ParseXML(XMLFile):
2732

2833

2934
def UpdateMetaData(TemplateRoot, PartitionRoot, BuildId):
30-
ChipIdList = TemplateRoot.findall('product_info/chipid')
35+
ChipIdList = TemplateRoot.findall("product_info/chipid")
3136
DefaultStorageType = None
3237
for ChipId in ChipIdList:
33-
Flavor = ChipId.get('flavor')
34-
StorageType = ChipId.get('storage_type')
38+
Flavor = ChipId.get("flavor")
39+
StorageType = ChipId.get("storage_type")
3540
print(f"Chipid Flavor: {Flavor} Storage Type: {StorageType}")
3641
if Flavor == "default":
37-
DefaultStorageType = ChipId.get('storage_type')
42+
DefaultStorageType = ChipId.get("storage_type")
3843

39-
PhyPartition = PartitionRoot.findall('physical_partition')
44+
PhyPartition = PartitionRoot.findall("physical_partition")
4045
Partitions = []
41-
for partition in PartitionRoot.findall('physical_partition/partition'):
42-
label = partition.get('label')
43-
filename = partition.get('filename')
46+
for partition in PartitionRoot.findall("physical_partition/partition"):
47+
label = partition.get("label")
48+
filename = partition.get("filename")
4449
if label and filename:
45-
Partitions.append({'label': label, 'filename': filename})
50+
Partitions.append({"label": label, "filename": filename})
4651
print(f"Partitions: {Partitions}")
4752

4853
def _add_file_elements(parent_element, pathname, file_path_flavor=None):
@@ -59,48 +64,61 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
5964
new_file_path.set("flavor", file_path_flavor)
6065
new_file_path.text = file_path_text
6166

62-
builds = TemplateRoot.findall('builds_flat/build')
67+
builds = TemplateRoot.findall("builds_flat/build")
6368
for build in builds:
64-
Name = build.find('name')
69+
Name = build.find("name")
6570
print(f"Build Name: {Name.text}")
6671
new_build_id = ET.SubElement(build, "build_id")
6772
new_build_id.text = BuildId
6873
if Name.text != "common":
6974
continue
70-
DownloadFile = build.find('download_file')
75+
DownloadFile = build.find("download_file")
7176
if DownloadFile is not None:
7277
build.remove(DownloadFile)
7378
# Partition entires
7479
for Partition in Partitions:
7580
new_download_file = ET.SubElement(build, "download_file")
76-
new_download_file.set("fastboot_complete", Partition['label'])
77-
_add_file_elements(new_download_file, Partition['filename'])
81+
new_download_file.set("fastboot_complete", Partition["label"])
82+
_add_file_elements(new_download_file, Partition["filename"])
7883
# GPT Main & GPT Backup entries
7984
for PhysicalPartitionNumber in range(0, len(PhyPartition)):
8085
new_download_file = ET.SubElement(build, "download_file")
8186
new_download_file.set("storage_type", DefaultStorageType)
82-
_add_file_elements(new_download_file, 'gpt_main%d.bin' % (PhysicalPartitionNumber))
87+
_add_file_elements(
88+
new_download_file, "gpt_main%d.bin" % (PhysicalPartitionNumber)
89+
)
8390
new_download_file = ET.SubElement(build, "download_file")
8491
new_download_file.set("storage_type", DefaultStorageType)
85-
_add_file_elements(new_download_file, 'gpt_backup%d.bin' % (PhysicalPartitionNumber))
92+
_add_file_elements(
93+
new_download_file, "gpt_backup%d.bin" % (PhysicalPartitionNumber)
94+
)
8695

87-
PartitionFile = build.find('partition_file')
96+
PartitionFile = build.find("partition_file")
8897
if PartitionFile is not None:
8998
build.remove(PartitionFile)
9099
# Rawprogram entries
91100
for PhysicalPartitionNumber in range(0, len(PhyPartition)):
92101
new_partition_file = ET.SubElement(build, "partition_file")
93102
new_partition_file.set("storage_type", DefaultStorageType)
94-
_add_file_elements(new_partition_file, 'rawprogram%d.xml' % (PhysicalPartitionNumber), "default")
103+
_add_file_elements(
104+
new_partition_file,
105+
"rawprogram%d.xml" % (PhysicalPartitionNumber),
106+
"default",
107+
)
95108

96-
PartitionPatchFile = build.find('partition_patch_file')
109+
PartitionPatchFile = build.find("partition_patch_file")
97110
if PartitionPatchFile is not None:
98111
build.remove(PartitionPatchFile)
99112
# Patch entries
100113
for PhysicalPartitionNumber in range(0, len(PhyPartition)):
101114
new_partition_patch_file = ET.SubElement(build, "partition_patch_file")
102115
new_partition_patch_file.set("storage_type", DefaultStorageType)
103-
_add_file_elements(new_partition_patch_file, 'patch%d.xml' % (PhysicalPartitionNumber), "default")
116+
_add_file_elements(
117+
new_partition_patch_file,
118+
"patch%d.xml" % (PhysicalPartitionNumber),
119+
"default",
120+
)
121+
104122

105123
###############################################################################
106124
# main
@@ -116,7 +134,7 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
116134
try:
117135
build_id = ""
118136
opts, rem = getopt.getopt(sys.argv[1:], "t:p:o:b:")
119-
for (opt, arg) in opts:
137+
for opt, arg in opts:
120138
if opt in ["-t"]:
121139
template = arg
122140
elif opt in ["-p"]:
@@ -141,7 +159,9 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
141159

142160
OutputTree = ET.ElementTree(xml_root)
143161
ET.indent(OutputTree, space="\t", level=0)
144-
OutputTree.write(output_xml, encoding="utf-8", xml_declaration=True, short_empty_elements=False)
162+
OutputTree.write(
163+
output_xml, encoding="utf-8", xml_declaration=True, short_empty_elements=False
164+
)
145165
except Exception as e:
146166
print(("Error: ", e))
147167
sys.exit(1)

0 commit comments

Comments
 (0)