Skip to content

Commit cbd3b8e

Browse files
authored
Merge pull request #34 from lool/contents-xml-directory-name
Support pathnames in contents.xml
2 parents fc12ab8 + a24084a commit cbd3b8e

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

gen_contents.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: BSD-3-Clause
44

55
import getopt
6+
import os
67
import sys
78

89
from xml.etree import ElementTree as ET
@@ -46,6 +47,20 @@ def UpdateMetaData(TemplateRoot, PartitionRoot):
4647
PartitionsSet.add((label, filename))
4748
print(f"PartitionsSet: {PartitionsSet}")
4849

50+
def _add_file_elements(parent_element, pathname, file_path_flavor=None):
51+
"""Helper function to add file_name and file_path sub-elements."""
52+
file_name_text = os.path.basename(pathname)
53+
file_path_text = os.path.dirname(pathname)
54+
if not file_path_text: # no directory, use explicit . as current dir
55+
file_path_text = "."
56+
57+
new_file_name = ET.SubElement(parent_element, "file_name")
58+
new_file_name.text = file_name_text
59+
new_file_path = ET.SubElement(parent_element, "file_path")
60+
if file_path_flavor:
61+
new_file_path.set("flavor", file_path_flavor)
62+
new_file_path.text = file_path_text
63+
4964
builds = TemplateRoot.findall('builds_flat/build')
5065
for build in builds:
5166
Name = build.find('name')
@@ -59,24 +74,15 @@ def UpdateMetaData(TemplateRoot, PartitionRoot):
5974
for Partition in PartitionsSet:
6075
new_download_file = ET.SubElement(build, "download_file")
6176
new_download_file.set("fastboot_complete", Partition[0])
62-
new_file_name = ET.SubElement(new_download_file, "file_name")
63-
new_file_name.text = Partition[1]
64-
new_file_path = ET.SubElement(new_download_file, "file_path")
65-
new_file_path.text = "."
77+
_add_file_elements(new_download_file, Partition[1])
6678
# GPT Main & GPT Backup entries
6779
for PhysicalPartitionNumber in range(0, len(PhyPartition)):
6880
new_download_file = ET.SubElement(build, "download_file")
6981
new_download_file.set("storage_type", DefaultStorageType)
70-
new_file_name = ET.SubElement(new_download_file, "file_name")
71-
new_file_name.text = 'gpt_main%d.xml' % (PhysicalPartitionNumber)
72-
new_file_path = ET.SubElement(new_download_file, "file_path")
73-
new_file_path.text = "."
82+
_add_file_elements(new_download_file, 'gpt_main%d.xml' % (PhysicalPartitionNumber))
7483
new_download_file = ET.SubElement(build, "download_file")
7584
new_download_file.set("storage_type", DefaultStorageType)
76-
new_file_name = ET.SubElement(new_download_file, "file_name")
77-
new_file_name.text = 'gpt_backup%d.xml' % (PhysicalPartitionNumber)
78-
new_file_path = ET.SubElement(new_download_file, "file_path")
79-
new_file_path.text = "."
85+
_add_file_elements(new_download_file, 'gpt_backup%d.xml' % (PhysicalPartitionNumber))
8086

8187
PartitionFile = build.find('partition_file')
8288
if PartitionFile is not None:
@@ -85,11 +91,7 @@ def UpdateMetaData(TemplateRoot, PartitionRoot):
8591
for PhysicalPartitionNumber in range(0, len(PhyPartition)):
8692
new_partition_file = ET.SubElement(build, "partition_file")
8793
new_partition_file.set("storage_type", DefaultStorageType)
88-
new_file_name = ET.SubElement(new_partition_file, "file_name")
89-
new_file_name.text = 'rawprogram%d.xml' % (PhysicalPartitionNumber)
90-
new_file_path = ET.SubElement(new_partition_file, "file_path")
91-
new_file_path.set("flavor", "default")
92-
new_file_path.text = "."
94+
_add_file_elements(new_partition_file, 'rawprogram%d.xml' % (PhysicalPartitionNumber), "default")
9395

9496
PartitionPatchFile = build.find('partition_patch_file')
9597
if PartitionPatchFile is not None:
@@ -98,11 +100,7 @@ def UpdateMetaData(TemplateRoot, PartitionRoot):
98100
for PhysicalPartitionNumber in range(0, len(PhyPartition)):
99101
new_partition_patch_file = ET.SubElement(build, "partition_patch_file")
100102
new_partition_patch_file.set("storage_type", DefaultStorageType)
101-
new_file_name = ET.SubElement(new_partition_patch_file, "file_name")
102-
new_file_name.text = 'patch%d.xml' % (PhysicalPartitionNumber)
103-
new_file_path = ET.SubElement(new_partition_patch_file, "file_path")
104-
new_file_path.set("flavor", "default")
105-
new_file_path.text = "."
103+
_add_file_elements(new_partition_patch_file, 'patch%d.xml' % (PhysicalPartitionNumber), "default")
106104

107105
###############################################################################
108106
# main

0 commit comments

Comments
 (0)