def generate_compiled_script()

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


def generate_compiled_script(source_code_path, merged_file_full_path, merged_file_name, environment):
    try:
        print('\n\n=============================== GENERATING ' + merged_file_name + '... =============================================================\n')

        print('========== Delete old extension file if it exists.')
        if os.path.exists(merged_file_full_path):
            os.remove(merged_file_full_path)

        print('\n========== Merging modules: \n')
        modules_to_be_merged = []
        for root, dirs, files in os.walk(source_code_path):
            for file_name in files:
                if ".py" not in file_name or ".pyc" in file_name:
                    continue
                file_path = os.path.join(root, file_name)
                if '__main__.py' in file_path:
                    modules_to_be_merged.append(file_path)
                elif os.path.basename(file_path) in ('__init__.py'):
                    continue
                elif os.path.basename(file_path) in ('Constants.py'):
                    modules_to_be_merged.insert(0, file_path)
                else:
                    if len(modules_to_be_merged) > 0 and '__main__.py' in modules_to_be_merged[-1]:
                        modules_to_be_merged.insert(-1, file_path)
                    else:
                        modules_to_be_merged.append(file_path)
        for python_module in modules_to_be_merged:
            print(format(os.path.basename(python_module)), end=', ')
            imports, codes = read_python_module(source_code_path, python_module)
            GLOBAL_IMPORTS.update(imports)
            write_merged_code(codes, merged_file_full_path)
        print("<end>")

        print('\n========== Prepend all import statements\n')
        insert_imports(GLOBAL_IMPORTS, merged_file_full_path)
        insert_imports(VERY_FIRST_IMPORTS, merged_file_full_path)

        print('========== Set Copyright, Version and Environment. Also enforce UNIX-style line endings.\n')
        insert_copyright_notice(merged_file_full_path, merged_file_name)
        timestamp = datetime.datetime.utcnow().strftime("%y%m%d-%H%M")
        replace_text_in_file(merged_file_full_path, '[%exec_name%]', merged_file_name.split('.')[0])
        replace_text_in_file(merged_file_full_path, '[%exec_sub_ver%]', timestamp)
        replace_text_in_file(merged_file_full_path, 'Constants.UNKNOWN_ENV', environment)
        replace_text_in_file(merged_file_full_path, '\r\n', '\n')

        print("========== Merged extension code was saved to:\n{0}\n".format(merged_file_full_path))

    except Exception as error:
        print('Exception during merge python modules: ' + repr(error))
        raise