def copy_file_or_dir(src_path, dst_path): # start the delete process if os.path.isfile(src_path): fh.copy_file(src_path, dst_path, create_path_if_needed=True, overwrite_if_needed=True) elif os.path.isdir(src_path): fh.copy_dir(src_path, dst_path)
def _build(project_path, output_dir, key_store_properties: KeyStoreProperties, version_properties: VersionProperties, gradle_path, binary_type, remove_older_binaries): logger = lh.Logger(name='[APK Builder]') # build the logger # will prepare any resources according to the binary type if binary_type == _res.APK: release_command = _res.COMMAND_APK_GRADLE_RELEASE binary_release_path = _res.get_apk_output_path(project_path) binary_ext = _res.EXT_APK elif binary_type == _res.APP_BUNDLE: release_command = _res.COMMAND_APP_BUNDLE_GRADLE_RELEASE binary_release_path = _res.get_app_bundle_output_path(project_path) binary_ext = _res.EXT_APP_BUNDLE else: raise NotImplementedError(f"Unrecognized '{binary_type}' binary type") # check if 'signingConfig signingConfigs.release' exists in the build.gradle file is_release_enabled = _build_gradle_utils.check_if_release_enabled(project_path) if not is_release_enabled: logger.warning('*** NOTICE: build.gradle file has the line: "signingConfig signingConfigs.release". If you want to use KeyStoreProperties, remove this line from your build.gradle') logger.info('Preparing build.gradle file for automated release...') _build_gradle_utils.prepare_build_gradle_for_release(project_path, key_store_properties, version_properties, is_release_enabled) # clear latest binary file logger.info(f'Clearing latest {binary_ext} file from project...') fh.remove_file(binary_release_path) # create the binary logger.info(f'Building the {binary_type}...') _general_utils.release_binary(release_command, project_path, gradle_path) # if the apk creation failed, throw an exception if not fh.is_file_exists(binary_release_path): raise Exception(f"ERROR: Failed to create {binary_type} file") if remove_older_binaries: logger.info(f'Gradle finished! removing older {binary_ext} files from {output_dir} dir...') # remove previous apks from the directory fh.remove_all_files_with_extension(binary_release_path, binary_ext) logger.info(f'Copying the new {binary_ext} file...') # copy the binary to the user desired location (with the file name as the version code) # obtain the version code version_code = _build_gradle_utils.obtain_version_code(project_path) binary_dst_path = os.path.join(output_dir, f'{version_code}{binary_ext}') fh.copy_file(binary_release_path, binary_dst_path) logger.info('Sanitizing build.gradle file...') # revert the build.gradle file to it's previous form _build_gradle_utils.remove_sign_in_config_from_gradle(project_path) logger.info(f'{binary_type} file built successfully in:\n {binary_dst_path}')
def replace_info_plist_file(old_info_file, new_info_file): from os_file_handler import file_handler file_handler.copy_file(new_info_file, old_info_file)
def run_cycle(self, launcher_obj: LauncherObj): import random random_suffix = f'_{str(random.randint(0, 99999))}' launcher_name = f'{self.LAUNCHER_ICON_FILE}{random_suffix}' # open image assets btns_automation.hot_key(self.shortcut_keys_to_open_image_asset) time.sleep(1) # navigate to name self.logger.info('Setting temporary name...') btns_automation.press('tab', 2, 0.1) time.sleep(1) tools.copy_to_clipboard(launcher_name) btns_automation.select_all() btns_automation.paste() # navigate to path self.logger.info('Setting Path...') btns_automation.press('tab', 5, 0.1) tools.copy_to_clipboard(launcher_obj.icon_path) time.sleep(1) btns_automation.select_all() btns_automation.paste() self.logger.info('Disabling Trim...') btns_automation.press('tab', 3, 0.1) btns_automation.press('space') self.logger.info('Setting Resize...') btns_automation.press('tab', 2, 0.1) btns_automation.press('pagedown', presses=4, interval=0.1) time.sleep(1) btns_automation.press('right', presses=self.launcher_resize_percent, interval=0.1) time.sleep(2) self.logger.info('Navigating to Background tab...') btns_automation.press('tab', 9, 0.1) btns_automation.press('right') # time.sleep(1) self.logger.info('Setting Background Color...') btns_automation.press('tab', 3, 0.1) btns_automation.press('space') self.logger.info('Clicking and setting the color...') btns_automation.press('tab', 3, 0.1) btns_automation.press('space') color = self.launcher_background_color_hex.replace('#', '') btns_automation.select_all() btns_automation.write(color, interval=0.1) time.sleep(2) btns_automation.press('enter') self.logger.info('Clicking Next...') btns_automation.press('enter') time.sleep(1) self.logger.info('Clicking Finish...') btns_automation.press('enter') self.logger.info('Gathering files...') time.sleep(6) # launcher file continue.... launcher_made_files = fh.search_file(self.main_path, prefix=launcher_name, recursive=True) self.logger.info('Fixing xml files...') # fix xml files fix_xml_files(launcher_made_files, random_suffix) self.logger.info('Copying files...') for launcher_file in launcher_made_files: rel_launcher_path = launcher_file.replace(f'{self.main_path}/', '') dst_launcher_file = os.path.join(launcher_obj.output_path, rel_launcher_path) dst_launcher_file = dst_launcher_file.replace(random_suffix, '') fh.copy_file(launcher_file, dst_launcher_file) self.logger.info('Removing temp files...') fh.remove_files(launcher_made_files) self.logger.info('waiting for next cycle...') time.sleep(1.5) return True