in src/tools/Package-All.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("extension", "src"))
if os.path.exists(os.path.join(source_code_path, "__main__.py")) is False:
print("Invalid extension 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, "ActionHandler.py")) is False:
print("Invalid extension 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
# Invoke core business logic code packager
exec_core_build_path = os.path.join(working_directory, 'tools', 'Package-Core.py')
subprocess.call('python ' + exec_core_build_path, shell=True)
# Generated compiled scripts at the destination
merged_file_details = [('MsftLinuxPatchExt.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])
# GENERATING EXTENSION
print('\n\n=============================== GENERATING LinuxPatchExtension.zip... =============================================================\n')
# Rev handler version
# print('\n========== Revising extension version.')
# manifest_xml_file_path = os.path.join(working_directory, 'extension', 'src', 'manifest.xml')
# manifest_tree = et.parse(manifest_xml_file_path)
# manifest_root = manifest_tree.getroot()
# for i in range(0, len(manifest_root)):
# if 'Version' in str(manifest_root[i]):
# current_version = manifest_root[i].text
# version_split = current_version.split('.')
# version_split[len(version_split)-1] = str(int(version_split[len(version_split)-1]) + 1)
# new_version = '.'.join(version_split)
# print("Changing extension version from {0} to {1}.".format(current_version, new_version))
# replace_text_in_file(manifest_xml_file_path, current_version, new_version)
# Copy extension files
print('\n========== Copying extension files + enforcing UNIX style line endings.\n')
ext_files = ['HandlerManifest.json', 'manifest.xml', 'MsftLinuxPatchExtShim.sh']
for ext_file in ext_files:
ext_file_src = os.path.join(working_directory, 'extension', 'src', ext_file)
ext_file_destination = os.path.join(working_directory, 'out', ext_file)
copyfile(ext_file_src, ext_file_destination)
replace_text_in_file(ext_file_destination, '\r\n', '\n')
# Generate extension zip
ext_zip_file = 'LinuxPatchExtension.zip'
ext_zip_file_path_src = os.path.join(working_directory, ext_zip_file)
ext_zip_file_path_dest = os.path.join(working_directory, 'out', ext_zip_file)
if os.path.exists(ext_zip_file_path_src):
os.remove(ext_zip_file_path_src)
if os.path.exists(ext_zip_file_path_dest):
os.remove(ext_zip_file_path_dest)
# Generate zip
print('\n========== Generating extension zip.\n')
make_archive(os.path.splitext(ext_zip_file_path_src)[0], 'zip', os.path.join(working_directory, 'out'), '.')
copyfile(ext_zip_file_path_src, ext_zip_file_path_dest)
os.remove(ext_zip_file_path_src)
# Remove extension file copies
print('\n========== Cleaning up environment.\n')
for ext_file in ext_files:
ext_file_path = os.path.join(working_directory, 'out', ext_file)
os.remove(ext_file_path)
print("========== Extension ZIP was saved to:\n{0}\n".format(ext_zip_file_path_dest))
except Exception as error:
print('Exception during merge python modules: ' + repr(error))
raise