def setup_echo(self): retVal = [] echo_template = ['echo', '"{}"'] if var_stack.defined('ECHO_LOG_FILE'): retVal.append(self.touch("$(ECHO_LOG_FILE)")) retVal.append(self.chmod("0666", "$(ECHO_LOG_FILE)")) echo_template.extend(("|", "tee", "-a", utils.quoteme_double("$(ECHO_LOG_FILE)"))) self.echo_template = " ".join(echo_template) return retVal
def write_copy_debug_info(self): try: if var_stack.defined('ECHO_LOG_FILE'): log_file_path = var_stack.ResolveVarToStr("ECHO_LOG_FILE") log_folder, log_file = os.path.split(log_file_path) with open(os.path.join(log_folder, "sync-folder-manifest.txt"), "w", encoding='utf-8') as wfd: repo_sync_dir = var_stack.ResolveVarToStr("COPY_SOURCES_ROOT_DIR") wfd.write(utils.folder_listing(repo_sync_dir)) except Exception: pass # if it did not work - forget it
def create_sync_folder_manifest_command(self, manifest_file_name_prefix): """ create batch commands to write a manifest of the sync folder to a file """ which_folder_to_manifest = "$(COPY_SOURCES_ROOT_DIR)" output_file_name = manifest_file_name_prefix+"-sync-folder-manifest.txt" for param_to_extract_output_folder_from in ('ECHO_LOG_FILE', '__MAIN_INPUT_FILE__', '__MAIN_OUT_FILE__'): if var_stack.defined(param_to_extract_output_folder_from): log_file_path = var_stack.ResolveVarToStr(param_to_extract_output_folder_from) output_folder, _ = os.path.split(log_file_path) if os.path.isdir(output_folder): break output_folder = None if output_folder is not None: self.create_folder_manifest_command(which_folder_to_manifest, output_folder, output_file_name)
def write_copy_to_folder_debug_info(self, folder_path): try: if var_stack.defined('ECHO_LOG_FILE'): log_file_path = var_stack.ResolveVarToStr("ECHO_LOG_FILE") log_folder, log_file = os.path.split(log_file_path) manifests_log_folder = os.path.join(log_folder, "manifests") os.makedirs(manifests_log_folder, exist_ok=True) folder_path_parent, folder_name = os.path.split(var_stack.ResolveStrToStr(folder_path)) ls_output_file = os.path.join(manifests_log_folder, folder_name+"-folder-manifest.txt") create_folder_ls_command_parts = [self.platform_helper.run_instl(), "ls", "--in", '"."', "--out", utils.quoteme_double(ls_output_file)] self.batch_accum += " ".join(create_folder_ls_command_parts) except Exception: pass # if it did not work - forget it
def do_ls(self): if "__MAIN_OUT_FILE__" in var_stack: out_file = var_stack.ResolveVarToStr("__MAIN_OUT_FILE__") else: out_file = "stdout" main_folder_to_list = var_stack.ResolveVarToStr("__MAIN_INPUT_FILE__") folders_to_list = [] if var_stack.defined("__LIMIT_COMMAND_TO__"): limit_list = var_stack.ResolveVarToList("__LIMIT_COMMAND_TO__") for limit in limit_list: limit = utils.unquoteme(limit) folders_to_list.append(os.path.join(main_folder_to_list, limit)) else: folders_to_list.append(main_folder_to_list) the_listing = utils.folder_listing(*folders_to_list) with utils.write_to_file_or_stdout(out_file) as wfd: wfd.write(the_listing)
def do_ls(self): main_folder_to_list = var_stack.ResolveVarToStr("__MAIN_INPUT_FILE__") folders_to_list = [] if var_stack.defined("__LIMIT_COMMAND_TO__"): limit_list = var_stack.ResolveVarToList("__LIMIT_COMMAND_TO__") for limit in limit_list: limit = utils.unquoteme(limit) folders_to_list.append(os.path.join(main_folder_to_list, limit)) else: folders_to_list.append(main_folder_to_list) ls_format = var_stack.ResolveVarToStr("LS_FORMAT", default='*') the_listing = utils.disk_item_listing(*folders_to_list, ls_format=ls_format) out_file = var_stack.ResolveVarToStr("__MAIN_OUT_FILE__") try: with utils.write_to_file_or_stdout(out_file) as wfd: wfd.write(the_listing) except NotADirectoryError: print("Cannot output to {}".format(out_file))