def main()

in src/tools/Package-Core.py [0:0]


def main(argv):
    """The main entry of merge python modules run"""
    try:
        # Clear
        os.system('cls' if os.name == 'nt' else 'clear')

        # Determine code path if not specified
        if len(argv) < 2:
            # auto-detect src path
            source_code_path = os.path.dirname(os.path.realpath(__file__)).replace("tools", os.path.join("core","src"))
            if os.path.exists(os.path.join(source_code_path, "__main__.py")) is False:
                print("Invalid core source code path. Check enlistment.\n")
                return
        else:
            # explicit src path parameter
            source_code_path = argv[1]
            if os.path.exists(os.path.join(source_code_path, "PatchInstaller.py")) is False:
                print("Invalid core source code path. Check src parameter.\n")
                return

        # Prepare destination for compiled scripts
        working_directory = os.path.abspath(os.path.join(source_code_path, os.pardir, os.pardir))
        merge_file_directory = os.path.join(working_directory, 'out')
        try:
            os.makedirs(merge_file_directory)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        # Generated compiled scripts at the destination
        merged_file_details = [('MsftLinuxPatchCore.py', 'Constants.PROD')]
        for merged_file_detail in merged_file_details:
            merged_file_destination = os.path.join(working_directory, 'out', merged_file_detail[0])
            generate_compiled_script(source_code_path, merged_file_destination, merged_file_detail[0], merged_file_detail[1])

        # add all dependencies under core/src/external_dependencies to destination directory
        external_dependencies_destination = os.path.join(merge_file_directory, 'external_dependencies')
        external_dependencies_source_code_path = os.path.join(source_code_path, 'external_dependencies')
        add_external_dependencies(external_dependencies_destination, external_dependencies_source_code_path)

    except Exception as error:
        print('Exception during packaging all python modules in core: ' + repr(error))
        raise