Add name option when building the patch

This change add option '--name' to the patch builder
script allowing user to select the desired file name for the
patch file. If the 'name' option is not provided, file name will
default to patch id from the recipe.

Test plan:
    PASS: Build patch with --name option
    e.g: python3 patch_builder --recipe recipe.xml --name filename.patch

    PASS: Build patch without --name option
    e.g: python3 patch_builder --recipe recipe.xml

Story: 2010676
Task: 49858

Change-Id: Ia9b936d44ef83e6ff3d9561b22ae045fb2891f33
Signed-off-by: Dostoievski Batista <dostoievski.albinobatista@windriver.com>
This commit is contained in:
Dostoievski Batista 2024-04-11 19:02:27 -03:00
parent 48e190ef4a
commit 1eab69901d
1 changed files with 9 additions and 5 deletions

View File

@ -44,12 +44,13 @@ PATCH_SCRIPTS = {
}
class PatchBuilder(object):
def __init__(self, patch_recipe_file):
def __init__(self, patch_recipe_file, file_name=None):
self.metadata = metadata.PatchMetadata(patch_recipe_file)
self.metadata.parse_input_xml_data()
self.fetch_debs = fetch_debs.FetchDebs()
self.fetch_debs.need_dl_stx_pkgs = self.metadata.stx_packages
self.fetch_debs.need_dl_binary_pkgs = self.metadata.binary_packages
self.patch_name = f'{self.metadata.patch_id}.patch' if file_name == None else file_name
def get_md5(self, path):
'''
@ -64,7 +65,7 @@ class PatchBuilder(object):
return int(md5.hexdigest(), 16)
def build_patch(self):
logger.info(f"Generating patch {self.metadata.patch_id}")
logger.info(f"Generating patch {self.patch_name}")
# Fetch debs from metadata and
# Create software.tar, metadata.tar and signatures
# Create a temporary working directory
@ -117,7 +118,7 @@ class PatchBuilder(object):
os.remove("metadata.xml")
# Pack .patch file
self.__sign_and_pack(f'{self.metadata.patch_id}.patch')
self.__sign_and_pack(self.patch_name)
def copy_script(self, script_type, install_script):
if not os.path.isfile(install_script):
@ -201,8 +202,11 @@ class PatchBuilder(object):
@click.command()
@click.option('--recipe', help='Patch recipe input XML file, examples are available under EXAMLES directory',
required=True)
def build(recipe):
patch_builder = PatchBuilder(recipe)
@click.option('--name', help='Allow user to define name of the patch file. e.g.: test-sample-rr.patch. \
Name will default to patch_id if not defined',
required=False)
def build(recipe, name=None):
patch_builder = PatchBuilder(recipe, name)
patch_builder.build_patch()
if __name__ == '__main__':