def _customcmd_apply_args(self, cmd_lines, args_str): try: args = kpu.cmdline_split(args_str) except: traceback.print_exc() return cmd_lines final_cmd_lines = [] for cmdline in cmd_lines: try: arg0 = kpu.cmdline_split(cmdline)[0] resolved_arg0 = kpu.shell_resolve_exe_path(arg0) if resolved_arg0 is not None: arg0 = resolved_arg0 except: traceback.print_exc() return cmd_lines start_pos = 0 while True: rem = self.REGEX_PLACEHOLDER.search(cmdline, start_pos) if not rem: break placeholder = rem.group(1) if placeholder in ("*", "args"): args_str = args_str.strip() cmdline = cmdline[0:rem.start()] + args_str + cmdline[rem.end():] start_pos = rem.start() + len(args_str) elif placeholder in ("q*", "qargs"): if not len(args): cmdline = cmdline[0:rem.start()] + cmdline[rem.end():] start_pos = rem.start() else: quoted_args = kpu.cmdline_quote(args, force_quote=True) cmdline = cmdline[0:rem.start()] + quoted_args + cmdline[rem.end():] start_pos = rem.start() + len(quoted_args) else: force_quote = False if placeholder[0] == "q": force_quote = True placeholder = placeholder[1:] arg_idx = int(placeholder) if arg_idx == 0: quoted_arg = kpu.cmdline_quote(arg0, force_quote=force_quote) else: arg_idx = arg_idx - 1 quoted_arg = kpu.cmdline_quote( args[arg_idx] if arg_idx < len(args) else "", force_quote=force_quote) cmdline = cmdline[0:rem.start()] + quoted_arg + cmdline[rem.end():] start_pos = rem.start() + len(quoted_arg) final_cmd_lines.append(cmdline) return final_cmd_lines
def convert(self, data): return (kpu.cmdline_quote(data), )