Skip to content

additional_packaging.py file

To extend the build process, you can create a additional_packaging.py file in the same file level where you have your globalConfig file.

This file should have either of the below two functions:

  • the cleanup_output_files function, which accepts output_path (str), add-on name (str) as its arguments.
  • the additional_packaging function, which accepts add-on name (str) as its only argument.

First the cleanup_output_files function would be called from ucc-gen build process and then additional_packaging function.

See the following example for proper usage:

  • Build custom UI after ucc-gen finishes all its necessary steps.
  • Use a workaround for a ucc-gen feature that has not been implemented.

Example

Below is an example of additional_packaging.py containing both the implementations of functions.

from os.path import sep, exists, dirname, realpath, join
from os import remove, system, _exit, WEXITSTATUS

def additional_packaging(ta_name=None):
    """
    `build-ui.sh` builds custom component present in source code and ships them in the output directory
    """
    if exists(
        join(dirname(realpath(__file__)), "build-ui.sh")
    ):
        system("chmod +x ./build-ui.sh")
        return_code = system("./build-ui.sh")
        if return_code != 0:
            _exit(WEXITSTATUS(return_code))

def cleanup_output_files(output_path: str, ta_name: str) -> None:
    """
    prepare a list for the files to be deleted after the source code has been copied to output directory
    :param output_path: The path provided in `--output` argument in ucc-gen command or the default output path.
    :param ta_name: The add-on name which is passed as a part of `--addon-name` argument during `ucc-gen init` 
                    or present in app.manifest file of add-on.
    """
    files_to_delete = []
    files_to_delete.append(sep.join([output_path, ta_name, "default", "redundant.conf"]))
    files_to_delete.append(sep.join([output_path, ta_name, "bin", "template_modinput_layout.py"]))
    files_to_delete.append(sep.join([output_path, ta_name, "bin", "example_one_input_one.py"]))
    files_to_delete.append(sep.join([output_path, ta_name, "bin", "template_rest_handler_script.py"]))
    files_to_delete.append(sep.join([output_path, ta_name, "bin", "file_does_not_exist.py"]))
    files_to_delete.append(sep.join([output_path, ta_name, "default", "nav", "views", "file_copied_from_source_code.xml"]))

    for delete_file in files_to_delete:
        try:
            remove(delete_file)
        except (FileNotFoundError):
            # simply pass if the file doesn't exist
            pass