def download_url_to_file(self, src_url, trg_file):
        """ Create command to download a single file.
            src_url is expected to be already escaped (spaces as %20...)
        """
        connect_time_out = var_stack.ResolveVarToStr("CURL_CONNECT_TIMEOUT", "16")
        max_time = var_stack.ResolveVarToStr("CURL_MAX_TIME", "180")
        retries = var_stack.ResolveVarToStr("CURL_RETRIES", "2")
        retry_delay = var_stack.ResolveVarToStr("CURL_RETRY_DELAY", "8")

        download_command_parts = list()
        download_command_parts.append("$(DOWNLOAD_TOOL_PATH)")
        download_command_parts.append("--insecure")
        download_command_parts.append("--fail")
        download_command_parts.append("--raw")
        download_command_parts.append("--silent")
        download_command_parts.append("--show-error")
        download_command_parts.append("--compressed")
        download_command_parts.append("--connect-timeout")
        download_command_parts.append(connect_time_out)
        download_command_parts.append("--max-time")
        download_command_parts.append(max_time)
        download_command_parts.append("--retry")
        download_command_parts.append(retries)
        download_command_parts.append("--retry-delay")
        download_command_parts.append(retry_delay)
        download_command_parts.append("write-out")
        download_command_parts.append(DownloadToolBase.curl_write_out_str)
        download_command_parts.append("-o")
        download_command_parts.append(utils.quoteme_double(trg_file))
        download_command_parts.append(utils.quoteme_double(src_url))
        return " ".join(download_command_parts)
Example #2
0
 def rmdir(self, directory, recursive=False):
     """ If recursive==False, only empty directory will be removed """
     if recursive:
         rmdir_command = " ".join(("rm", "-fr", utils.quoteme_double(directory) ))
     else:
         rmdir_command = " ".join(("rmdir", utils.quoteme_double(directory) ))
     return rmdir_command
 def mkdir(self, directory):
     norm_directory = os.path.normpath(directory)
     quoted_norm_directory = utils.quoteme_double(norm_directory)
     quoted_norm_directory_slash = utils.quoteme_double(norm_directory+"\\")
     mk_command = " ".join(("if not exist", quoted_norm_directory, "mkdir", quoted_norm_directory))
     check_mk_command = " ".join(("if not exist", quoted_norm_directory_slash, "(", "echo Error: failed to create ", quoted_norm_directory, "1>&2",
                                 "&", "GOTO", "EXIT_ON_ERROR", ")"))
     return mk_command, check_mk_command
 def copy_file_to_file(self, src_file, trg_file, hard_link=False, check_exist=False):
     copy_command_parts = list()
     norm_src_file = utils.quoteme_double(os.path.normpath(src_file))
     norm_trg_file = utils.quoteme_double(os.path.normpath(trg_file))
     if check_exist:
         copy_command_parts.extend(("if", "exist", norm_src_file))
     copy_command_parts.extend(("copy", norm_src_file, norm_trg_file))
     copy_command = " ".join(copy_command_parts)
     return copy_command
 def mkdir_with_owner(self, directory, progress_num=0):
     norm_directory = os.path.normpath(directory)
     quoted_norm_directory = utils.quoteme_double(norm_directory)
     quoted_norm_directory_slash = utils.quoteme_double(norm_directory+"\\")
     mk_command = " ".join(("if not exist", quoted_norm_directory, "(",
                            "mkdir", quoted_norm_directory,
                            "&", "echo", "Progress: ", str(progress_num), " of $(TOTAL_ITEMS_FOR_PROGRESS_REPORT); Create folder ", quoted_norm_directory, ")"))
     check_mk_command = " ".join(("if not exist", quoted_norm_directory_slash, "(", "echo Error: failed to create ", quoted_norm_directory, "1>&2",
                                 "&", "GOTO", "EXIT_ON_ERROR", ")"))
     return mk_command, check_mk_command
 def cd(self, directory):
     norm_directory = utils.quoteme_double(os.path.normpath(directory))
     is_exists_command = " ".join(("if not exist", norm_directory,
                                 "(", "echo directory does not exists", norm_directory, "1>&2",
                                 "&", "GOTO", "EXIT_ON_ERROR", ")"))
     cd_command = " ".join(("cd", '/d', norm_directory))
     check_cd_command = " ".join(("if /I not", norm_directory, "==", utils.quoteme_double("%CD%"),
                                 "(", "echo Error: failed to cd to", norm_directory, "1>&2",
                                 "&", "GOTO", "EXIT_ON_ERROR", ")"))
     return is_exists_command, cd_command, check_cd_command
Example #7
0
 def create_folder_manifest_command(self, which_folder_to_manifest, output_folder, output_file_name):
     """ create batch commands to write a manifest of specific folder to a file """
     self.batch_accum += self.platform_helper.mkdir(output_folder)
     ls_output_file = os.path.join(output_folder, output_file_name)
     create_folder_ls_command_parts = [self.platform_helper.run_instl(), "ls",
                                   "--in",  utils.quoteme_double(which_folder_to_manifest),
                                   "--out", utils.quoteme_double(ls_output_file)]
     if var_stack.ResolveVarToStr("__CURRENT_OS__") == "Mac":
         create_folder_ls_command_parts.extend(("||", "true"))
     self.batch_accum += " ".join(create_folder_ls_command_parts)
Example #8
0
 def create_folder_manifest_command(self, which_folder_to_manifest, output_folder, output_file_name, back_ground=False):
     """ create batch commands to write a manifest of specific folder to a file """
     self.batch_accum += self.platform_helper.mkdir(output_folder)
     ls_output_file = os.path.join(output_folder, output_file_name)
     create_folder_ls_command_parts = [self.platform_helper.run_instl(), "ls",
                                   "--in",  utils.quoteme_double(which_folder_to_manifest),
                                   "--out", utils.quoteme_double(ls_output_file)]
     if var_stack.ResolveVarToStr("__CURRENT_OS__") == "Mac":
         if False:  # back_ground: temporary disabled background, it causes DB conflicts when two "ls" command happen in parallel
             create_folder_ls_command_parts.extend("&")
         else:
             create_folder_ls_command_parts.extend(("||", "true"))
     self.batch_accum += " ".join(create_folder_ls_command_parts)
    def repr_own_args(self, all_args: List[str]) -> None:
        all_args.append(f"""path={utils.quoteme_raw_by_type(self.path)}""")

        the_mode = self.mode
        if isinstance(the_mode, str):
            the_mode = utils.quoteme_double(the_mode)
        all_args.append(f"""mode={the_mode}""")
Example #10
0
def get_instl_launch_command():
    """
    @return: returns the path to this
    """
    launch_command = None
    exec_path = get_path_to_instl_app()
    if getattr(sys, 'frozen', False):
        launch_command = utils.quoteme_double(os.fspath(exec_path))
    elif __file__:
        if os_family_name == "Win":
            launch_command = " ".join(
                (utils.quoteme_double(sys.executable),
                 utils.quoteme_double(os.fspath(exec_path))))
        else:
            launch_command = utils.quoteme_double(os.fspath(exec_path))
    return launch_command
Example #11
0
 def set_exec_for_folder(self, info_map_file):
     set_exec_for_folder_command = " ".join((self.run_instl(),
                                             "set-exec",
                                             "--in", utils.quoteme_double(info_map_file),
                                             "--start-progress", str(self.num_items_for_progress_report),
                                             "--total-progress", "$(TOTAL_ITEMS_FOR_PROGRESS_REPORT)",
     ))
     return set_exec_for_folder_command
Example #12
0
 def create_folders(self, info_map_file):
     create_folders_command = " ".join((self.run_instl(),
                                        "create-folders",
                                        "--in", utils.quoteme_double(info_map_file),
                                        "--start-progress", str(self.num_items_for_progress_report),
                                        "--total-progress", "$(TOTAL_ITEMS_FOR_PROGRESS_REPORT)",
     ))
     return create_folders_command
Example #13
0
 def positional_members_repr(self, all_args: List[str]) -> None:
     """ helper function to create repr for BaseRegistryKey common to all subclasses """
     all_args.append(utils.quoteme_double(self.top_key))
     all_args.append(self.unnamed__init__param(self.sub_key))
     if self.value_name is not None:
         all_args.append(self.unnamed__init__param(self.value_name))
     if self.value_data is not None:
         all_args.append(self.unnamed__init__param(self.value_data))
Example #14
0
 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
Example #15
0
 def resolve_symlink_files(self, in_dir="$PWD"):
     """ create instructions to turn .symlinks files into real symlinks.
         Main problem was with files that had space in their name, just
         adding \" was no enough, had to separate each step to a single line
         which solved the spaces problem. Also find returns an empty string
         even when there were no files found, and therefor the check
     """
     resolve_command = " ".join(("resolve_symlinks", utils.quoteme_double(in_dir)))
     return resolve_command
Example #16
0
 def check_checksum_for_file(self, file_path, checksum):
     check_command_parts = (  "CHECKSUM_CHECK=`$(CHECKSUM_TOOL_PATH) sha1",
                              utils.quoteme_double(file_path),
                              "` ;",
                              "if [ ${CHECKSUM_CHECK: -40} !=",
                              utils.quoteme_double(checksum),
                              "];",
                              "then",
                              "echo bad checksum",
                              utils.quoteme_double("${PWD}/" + file_path),
                              "1>&2",
                              ";",
                              "exit 1",
                              ";",
                              "fi"
     )
     check_command = " ".join(check_command_parts)
     return check_command
 def download_url_to_file(self, src_url, trg_file):
     """ Create command to download a single file.
         src_url is expected to be already escaped (spaces as %20...)
     """
     download_command_parts = list()
     download_command_parts.append("$(DOWNLOAD_TOOL_PATH)")
     download_command_parts.append("--quiet")
     download_command_parts.append('--header "Accept-Encoding: gzip"'),
     download_command_parts.append("--connect-timeout")
     download_command_parts.append("3")
     download_command_parts.append("--read-timeout")
     download_command_parts.append("900")
     download_command_parts.append("-O")
     download_command_parts.append(utils.quoteme_double(trg_file))
     # urls need to escape spaces as %20, but windows batch files already escape % characters
     # so use urllib.quote to escape spaces and then change %20 to %%20.
     download_command_parts.append(utils.quoteme_double(src_url.replace("%", "%%")))
     return " ".join(download_command_parts), self.platform_helper.exit_if_error()
Example #18
0
 def unwtar_something(self, what_to_unwtar, no_artifacts=False):
     unwtar_command_parts = [self.instlObj.platform_helper.run_instl(),
                             "unwtar",
                             "--in", utils.quoteme_double(what_to_unwtar),
                             #"--start-progress", str(self.num_items_for_progress_report),
                             #"--total-progress", "$(TOTAL_ITEMS_FOR_PROGRESS_REPORT)",
     ]
     if no_artifacts:
         unwtar_command_parts.append("--no-artifacts")
     unwtar_command = " ".join(unwtar_command_parts)
     return unwtar_command
 def rmdir(self, directory, recursive=False, check_exist=False):
     rmdir_command_parts = list()
     norm_directory = utils.quoteme_double(os.path.normpath(directory))
     if check_exist:
         rmdir_command_parts.extend(("if", "exist", norm_directory))
     rmdir_command_parts.append("rmdir")
     if recursive:
         rmdir_command_parts.extend(("/S", "/Q"))
     rmdir_command_parts.append(norm_directory)
     rmdir_command = " ".join(rmdir_command_parts)
     return rmdir_command
Example #20
0
 def download_url_to_file(self, src_url, trg_file):
     """ Create command to download a single file.
         src_url is expected to be already escaped (spaces as %20...)
     """
     download_command_parts = list()
     download_command_parts.append("$(DOWNLOAD_TOOL_PATH)")
     download_command_parts.append("--insecure")
     download_command_parts.append("--fail")
     download_command_parts.append("--raw")
     download_command_parts.append("--silent")
     download_command_parts.append("--connect-timeout")
     download_command_parts.append("3")
     download_command_parts.append("--max-time")
     download_command_parts.append("60")
     # download_command_parts.append(" --write-out")
     #download_command_parts.append(utils.quoteme_double("%{http_code}"))
     download_command_parts.append("-o")
     download_command_parts.append(utils.quoteme_double(trg_file))
     download_command_parts.append(utils.quoteme_double(src_url))
     return " ".join(download_command_parts)
Example #21
0
 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
Example #22
0
 def echo(self, message):
     echo_command = " ".join(('echo', utils.quoteme_double(message)))
     return echo_command
Example #23
0
 def cd(self, directory):
     cd_command = " ".join(("cd", utils.quoteme_double(directory) ))
     return cd_command
    def download_from_config_files(self, parallel_run_config_file_path, config_files):
        import win32api
        with utils.utf8_open(parallel_run_config_file_path, "w") as wfd:
            utils.make_open_file_read_write_for_all(wfd)
            for config_file in config_files:
                # curl on windows has problem with path to config files that have unicode characters
                normalized_path = win32api.GetShortPathName(config_file)
                wfd.write(var_stack.ResolveStrToStr('''"$(DOWNLOAD_TOOL_PATH)" --config "{}"\n'''.format(normalized_path)))

        download_command = " ".join((self.platform_helper.run_instl(),  "parallel-run", "--in", utils.quoteme_double(parallel_run_config_file_path)))
        return download_command, self.platform_helper.exit_if_error()
Example #25
0
 def rmdir(self, directory, recursive=False):
     if recursive:
         rmdir_command = " ".join(("rm", "-fr", utils.quoteme_double(directory) ))
     else:
         rmdir_command = " ".join(("rmdir", utils.quoteme_double(directory) ))
     return rmdir_command
Example #26
0
 def pushd(self, directory):
     pushd_command = " ".join(("pushd", utils.quoteme_double(directory), ">", "/dev/null"))
     return pushd_command
 def touch(self, file_path):
     touch_command = " ".join(("type", "NUL", ">", utils.quoteme_double(file_path)))
     return touch_command
 def append_file_to_file(self, source_file, target_file):
     append_command = " ".join(("type", utils.quoteme_double(source_file), ">>", utils.quoteme_double(target_file)))
     return append_command
 def unlock(self, file_path, recursive=False, ignore_errors=True):
     recurse_flag = ""
     if recursive:
         recurse_flag = "/S /D"
     writable_command = " ".join(("$(ATTRIB_PATH)", "-R", recurse_flag, utils.quoteme_double(file_path)))
     return writable_command
Example #30
0
 def rmfile(self, a_file):
     rmfile_command = " ".join(("rm", "-f", utils.quoteme_double(a_file) ))
     return rmfile_command
 def rm_file_or_dir(self, file_or_dir):
     norm_path = utils.quoteme_double(os.path.normpath(file_or_dir))
     rmdir_command = " ".join(("rmdir", '/S', '/Q', norm_path, '>nul', '2>&1'))
     rmfile_command = " ".join(("del", '/F', '/Q', norm_path, '>nul', '2>&1'))
     return rmdir_command, rmfile_command
Example #32
0
 def mkdir(self, directory):
     mk_command = " ".join(("mkdir", "-p", utils.quoteme_double(directory) ))
     return mk_command
 def pushd(self, directory):
     norm_directory = utils.quoteme_double(os.path.normpath(directory))
     pushd_command = " ".join(("pushd", norm_directory))
     return pushd_command