Skip to content

Commit 5c95a7e

Browse files
authored
Merge pull request #79 from igoropaniuk/refactor/linting-and-style-cleanup
refactor: code style and linting cleanup
2 parents 2caadb3 + f255780 commit 5c95a7e

5 files changed

Lines changed: 4068 additions & 2291 deletions

File tree

gen_contents.py

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
import getopt
66
import os
77
import sys
8-
98
from xml.etree import ElementTree as ET
109

1110

1211
def usage():
13-
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+
)
1418
sys.exit(1)
1519

1620

@@ -28,22 +32,22 @@ def ParseXML(XMLFile):
2832

2933

3034
def UpdateMetaData(TemplateRoot, PartitionRoot, BuildId):
31-
ChipIdList = TemplateRoot.findall('product_info/chipid')
35+
ChipIdList = TemplateRoot.findall("product_info/chipid")
3236
DefaultStorageType = None
3337
for ChipId in ChipIdList:
34-
Flavor = ChipId.get('flavor')
35-
StorageType = ChipId.get('storage_type')
38+
Flavor = ChipId.get("flavor")
39+
StorageType = ChipId.get("storage_type")
3640
print(f"Chipid Flavor: {Flavor} Storage Type: {StorageType}")
3741
if Flavor == "default":
38-
DefaultStorageType = ChipId.get('storage_type')
42+
DefaultStorageType = ChipId.get("storage_type")
3943

40-
PhyPartition = PartitionRoot.findall('physical_partition')
44+
PhyPartition = PartitionRoot.findall("physical_partition")
4145
Partitions = []
42-
for partition in PartitionRoot.findall('physical_partition/partition'):
43-
label = partition.get('label')
44-
filename = partition.get('filename')
46+
for partition in PartitionRoot.findall("physical_partition/partition"):
47+
label = partition.get("label")
48+
filename = partition.get("filename")
4549
if label and filename:
46-
Partitions.append({'label': label, 'filename': filename})
50+
Partitions.append({"label": label, "filename": filename})
4751
print(f"Partitions: {Partitions}")
4852

4953
def _add_file_elements(parent_element, pathname, file_path_flavor=None):
@@ -60,48 +64,61 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
6064
new_file_path.set("flavor", file_path_flavor)
6165
new_file_path.text = file_path_text
6266

63-
builds = TemplateRoot.findall('builds_flat/build')
67+
builds = TemplateRoot.findall("builds_flat/build")
6468
for build in builds:
65-
Name = build.find('name')
69+
Name = build.find("name")
6670
print(f"Build Name: {Name.text}")
6771
new_build_id = ET.SubElement(build, "build_id")
6872
new_build_id.text = BuildId
6973
if Name.text != "common":
7074
continue
71-
DownloadFile = build.find('download_file')
75+
DownloadFile = build.find("download_file")
7276
if DownloadFile is not None:
7377
build.remove(DownloadFile)
7478
# Partition entires
7579
for Partition in Partitions:
7680
new_download_file = ET.SubElement(build, "download_file")
77-
new_download_file.set("fastboot_complete", Partition['label'])
78-
_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"])
7983
# GPT Main & GPT Backup entries
8084
for PhysicalPartitionNumber in range(0, len(PhyPartition)):
8185
new_download_file = ET.SubElement(build, "download_file")
8286
new_download_file.set("storage_type", DefaultStorageType)
83-
_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+
)
8490
new_download_file = ET.SubElement(build, "download_file")
8591
new_download_file.set("storage_type", DefaultStorageType)
86-
_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+
)
8795

88-
PartitionFile = build.find('partition_file')
96+
PartitionFile = build.find("partition_file")
8997
if PartitionFile is not None:
9098
build.remove(PartitionFile)
9199
# Rawprogram entries
92100
for PhysicalPartitionNumber in range(0, len(PhyPartition)):
93101
new_partition_file = ET.SubElement(build, "partition_file")
94102
new_partition_file.set("storage_type", DefaultStorageType)
95-
_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+
)
96108

97-
PartitionPatchFile = build.find('partition_patch_file')
109+
PartitionPatchFile = build.find("partition_patch_file")
98110
if PartitionPatchFile is not None:
99111
build.remove(PartitionPatchFile)
100112
# Patch entries
101113
for PhysicalPartitionNumber in range(0, len(PhyPartition)):
102114
new_partition_patch_file = ET.SubElement(build, "partition_patch_file")
103115
new_partition_patch_file.set("storage_type", DefaultStorageType)
104-
_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+
105122

106123
###############################################################################
107124
# main
@@ -117,7 +134,7 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
117134
try:
118135
build_id = ""
119136
opts, rem = getopt.getopt(sys.argv[1:], "t:p:o:b:")
120-
for (opt, arg) in opts:
137+
for opt, arg in opts:
121138
if opt in ["-t"]:
122139
template = arg
123140
elif opt in ["-p"]:
@@ -142,7 +159,9 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
142159

143160
OutputTree = ET.ElementTree(xml_root)
144161
ET.indent(OutputTree, space="\t", level=0)
145-
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+
)
146165
except Exception as e:
147166
print(("Error: ", e))
148167
sys.exit(1)

0 commit comments

Comments
 (0)