Python pipes.quote() Examples
The following are 30
code examples of pipes.quote().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pipes
, or try the search function
.
Example #1
Source File: espeak.py From xuebao with MIT License | 7 votes |
def say(self, phrase): if isinstance(phrase, unicode): phrase = phrase.encode('utf8') with tempfile.SpooledTemporaryFile() as out_f: cmd = ['espeak', '-v', self.voice, '-p', self.pitch_adjustment, '-s', self.words_per_minute, '--stdout', phrase] cmd = [str(x) for x in cmd] self._logger.debug('Executing %s', ' '.join([pipes.quote(arg) for arg in cmd])) subprocess.call(cmd, stdout=out_f) out_f.seek(0) data = out_f.read() return data
Example #2
Source File: msvc_wrapper_for_nvcc.py From lingvo with Apache License 2.0 | 6 votes |
def main(): parser = ArgumentParser() parser.add_argument('-x', nargs=1) parser.add_argument('--cuda_log', action='store_true') args, leftover = parser.parse_known_args(sys.argv[1:]) if args.x and args.x[0] == 'cuda': if args.cuda_log: Log('-x cuda') leftover = [pipes.quote(s) for s in leftover] if args.cuda_log: Log('using nvcc') return InvokeNvcc(leftover, log=args.cuda_log) # Strip our flags before passing through to the CPU compiler for files which # are not -x cuda. We can't just pass 'leftover' because it also strips -x. # We not only want to pass -x to the CPU compiler, but also keep it in its # relative location in the argv list (the compiler is actually sensitive to # this). cpu_compiler_flags = [flag for flag in sys.argv[1:] if not flag.startswith(('--cuda_log')) and not flag.startswith(('-nvcc_options'))] return subprocess.call([CPU_COMPILER] + cpu_compiler_flags)
Example #3
Source File: kinetics400.py From gluon-cv with Apache License 2.0 | 6 votes |
def run_warp_optical_flow(vid_item, dev_id=0): full_path, vid_path, vid_id = vid_item vid_name = vid_path.split('.')[0] out_full_path = osp.join(args.out_dir, vid_name) try: os.mkdir(out_full_path) except OSError: pass current = current_process() dev_id = (int(current._identity[0]) - 1) % args.num_gpu flow_x_path = '{}/flow_x'.format(out_full_path) flow_y_path = '{}/flow_y'.format(out_full_path) cmd = osp.join(args.df_path + 'build/extract_warp_gpu') + \ ' -f={} -x={} -y={} -b=20 -t=1 -d={} -s=1 -o={}'.format( quote(full_path), quote(flow_x_path), quote(flow_y_path), dev_id, args.out_format) os.system(cmd) print('warp on {} {} done'.format(vid_id, vid_name)) sys.stdout.flush() return True
Example #4
Source File: cli.py From construi with Apache License 2.0 | 6 votes |
def main(): # type: () -> None setup_logging() args = parse_args() try: config = parse(args.basedir, "construi.yml") if args.list_targets: list_targets(config) sys.exit(0) target = args.target or config.default os.environ["CONSTRUI_ARGS"] = " ".join([quote(a) for a in args.construi_args]) Target(config.for_target(target)).invoke(RunContext(config, args.dry_run)) except Exception as e: on_exception(e) else: console.info("\nBuild Succeeded.\n")
Example #5
Source File: utils.py From llvm-zorg with Apache License 2.0 | 6 votes |
def _logged_catched(func, commandline, *args, **kwargs): commandline_string = commandline if isinstance(commandline, list) or isinstance(commandline, tuple): commandline_string = " ".join([quote(arg) for arg in commandline]) if verbose: cwd = kwargs.get('cwd', None) if cwd is not None: sys.stderr.write("In Directory: %s\n" % cwd) sys.stderr.write("$ %s\n" % commandline_string) try: return func(commandline, *args, **kwargs) except subprocess.CalledProcessError as e: sys.stderr.write("Error while executing: $ %s\n" % commandline_string) if e.output is not None: sys.stderr.write(str(e.output)) sys.exit(e.returncode) except OSError as e: sys.stderr.write("Error while executing $ %s\n" % commandline_string) sys.stderr.write("Error: %s\n" % e) sys.exit(1)
Example #6
Source File: run_distributed.py From lingvo with Apache License 2.0 | 6 votes |
def _ExecInDocker(container_name, cmd_array, workdir=None, logfile=None, detach=False): """Execute in docker container.""" if not workdir: workdir = "/tmp" opts = ["-t", "-w", workdir] if detach: opts += ["-d"] # TODO(drpng): avoid quoting hell. base_cmd = ["exec"] + opts + [container_name] if logfile: # The logfile is in the container. cmd = " ".join(shell_quote(x) for x in cmd_array) cmd += " >& %s" % logfile full_cmd = base_cmd + ["bash", "-c", cmd] else: full_cmd = base_cmd + cmd_array ret = _RunDocker(full_cmd) if ret != 0: sys.stderr.write( "Failed to exec within %s: %s" % (container_name, cmd_array)) sys.exit(ret)
Example #7
Source File: data_handler.py From clusterfuzz with Apache License 2.0 | 6 votes |
def _get_memory_tool_options(testcase): """Return memory tool options as a string to pass on command line.""" env = testcase.get_metadata('env') if not env: return [] result = [] for options_name, options_value in sorted(six.iteritems(env)): # Strip symbolize flag, use default symbolize=1. options_value.pop('symbolize', None) if not options_value: continue options_string = environment.join_memory_tool_options(options_value) result.append('{options_name}="{options_string}"'.format( options_name=options_name, options_string=quote(options_string))) return result
Example #8
Source File: pipstrap.py From sugardough with Apache License 2.0 | 6 votes |
def main(): temp = mkdtemp(prefix='pipstrap-') try: downloads = [hashed_download(url, temp, digest) for url, digest in PACKAGES] check_output('pip install --no-index --no-deps -U ' + ' '.join(quote(d) for d in downloads), shell=True) except HashError as exc: print(exc) except Exception: rmtree(temp) raise else: rmtree(temp) return 0 return 1
Example #9
Source File: wxbot.py From DevilYuan with MIT License | 6 votes |
def show_image(file_path): """ 跨平台显示图片文件 :param file_path: 图片文件路径 """ if sys.version_info >= (3, 3): from shlex import quote else: from pipes import quote if sys.platform == "darwin": command = "open -a /Applications/Preview.app %s&" % quote(file_path) os.system(command) else: img = PIL.Image.open(file_path) img.show()
Example #10
Source File: hmdb51.py From gluon-cv with Apache License 2.0 | 6 votes |
def run_warp_optical_flow(vid_item, dev_id=0): full_path, vid_path, vid_id = vid_item vid_name = vid_path.split('.')[0] out_full_path = osp.join(args.out_dir, vid_name) try: os.mkdir(out_full_path) except OSError: pass current = current_process() dev_id = (int(current._identity[0]) - 1) % args.num_gpu flow_x_path = '{}/flow_x'.format(out_full_path) flow_y_path = '{}/flow_y'.format(out_full_path) cmd = osp.join(args.df_path + 'build/extract_warp_gpu') + \ ' -f={} -x={} -y={} -b=20 -t=1 -d={} -s=1 -o={}'.format( quote(full_path), quote(flow_x_path), quote(flow_y_path), dev_id, args.out_format) os.system(cmd) print('warp on {} {} done'.format(vid_id, vid_name)) sys.stdout.flush() return True
Example #11
Source File: gittag.py From coursys with GNU General Public License v3.0 | 6 votes |
def _clone_cmd(self, slug=None): if slug: dirname = slug else: dirname = 'repo' content = [] content.append("# Submitted Git tag can be retrieved with the command below.") content.append("git clone %s %s && cd %s && git checkout tags/%s" % ( pipes.quote(self.url), pipes.quote(dirname), pipes.quote(dirname), pipes.quote(self.tag), )) content.append("# url:%s" % (self.url,)) content.append("# tag:%s" % (self.tag,)) return '\n'.join(content)
Example #12
Source File: base.py From testinfra with Apache License 2.0 | 5 votes |
def quote(command, *args): if args: return command % tuple(pipes.quote(a) for a in args) return command
Example #13
Source File: base.py From testinfra with Apache License 2.0 | 5 votes |
def run_local(self, command, *args): command = self.quote(command, *args) command = self.encode(command) p = subprocess.Popen( command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) stdout, stderr = p.communicate() result = self.result(p.returncode, command, stdout, stderr) return result
Example #14
Source File: gdbcontroller.py From pygdbmi with MIT License | 5 votes |
def get_subprocess_cmd(self): """Returns the shell-escaped string used to invoke the gdb subprocess. This is a string that can be executed directly in a shell. """ return " ".join(quote(c) for c in self.cmd)
Example #15
Source File: ImageShow.py From teleport with Apache License 2.0 | 5 votes |
def get_command_ex(self, file, title=None, **options): # note: xv is pretty outdated. most modern systems have # imagemagick's display command instead. command = executable = "xv" if title: command += " -name %s" % quote(title) return command, executable
Example #16
Source File: base.py From testinfra with Apache License 2.0 | 5 votes |
def get_sudo_command(self, command, sudo_user): if sudo_user is None: return self.quote("sudo /bin/sh -c %s", command) return self.quote( "sudo -u %s /bin/sh -c %s", sudo_user, command)
Example #17
Source File: base.py From testinfra with Apache License 2.0 | 5 votes |
def get_command(self, command, *args): command = self.quote(command, *args) if self.sudo: command = self.get_sudo_command(command, self.sudo_user) return command
Example #18
Source File: discovery.py From universe with MIT License | 5 votes |
def pretty_command(command): return ' '.join(pipes.quote(c) for c in command)
Example #19
Source File: docker_remote.py From universe with MIT License | 5 votes |
def pretty_command(command): return ' '.join(pipes.quote(c) for c in command)
Example #20
Source File: test_pipes.py From BinderFilter with MIT License | 5 votes |
def testQuoting(self): safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./' unsafe = '"`$\\!' self.assertEqual(pipes.quote(''), "''") self.assertEqual(pipes.quote(safeunquoted), safeunquoted) self.assertEqual(pipes.quote('test file name'), "'test file name'") for u in unsafe: self.assertEqual(pipes.quote('test%sname' % u), "'test%sname'" % u) for u in unsafe: self.assertEqual(pipes.quote("test%s'name'" % u), "'test%s'\"'\"'name'\"'\"''" % u)
Example #21
Source File: ucf101.py From gluon-cv with Apache License 2.0 | 5 votes |
def run_optical_flow(vid_item, dev_id=0): full_path, vid_path, vid_id = vid_item vid_name = vid_path.split('.')[0] out_full_path = osp.join(args.out_dir, vid_name) try: os.mkdir(out_full_path) except OSError: pass current = current_process() dev_id = (int(current._identity[0]) - 1) % args.num_gpu image_path = '{}/img'.format(out_full_path) flow_x_path = '{}/flow_x'.format(out_full_path) flow_y_path = '{}/flow_y'.format(out_full_path) cmd = osp.join(args.df_path, 'build/extract_gpu') + \ ' -f={} -x={} -y={} -i={} -b=20 -t=1 -d={} -s=1 -o={} -w={} -h={}' \ .format( quote(full_path), quote(flow_x_path), quote(flow_y_path), quote(image_path), dev_id, args.out_format, args.new_width, args.new_height) os.system(cmd) print('{} {} done'.format(vid_id, vid_name)) sys.stdout.flush() return True
Example #22
Source File: kinetics400.py From gluon-cv with Apache License 2.0 | 5 votes |
def run_optical_flow(vid_item, dev_id=0): full_path, vid_path, vid_id = vid_item vid_name = vid_path.split('.')[0] out_full_path = osp.join(args.out_dir, vid_name) try: os.mkdir(out_full_path) except OSError: pass current = current_process() dev_id = (int(current._identity[0]) - 1) % args.num_gpu image_path = '{}/img'.format(out_full_path) flow_x_path = '{}/flow_x'.format(out_full_path) flow_y_path = '{}/flow_y'.format(out_full_path) cmd = osp.join(args.df_path, 'build/extract_gpu') + \ ' -f={} -x={} -y={} -i={} -b=20 -t=1 -d={} -s=1 -o={} -w={} -h={}' \ .format( quote(full_path), quote(flow_x_path), quote(flow_y_path), quote(image_path), dev_id, args.out_format, args.new_width, args.new_height) os.system(cmd) print('{} {} done'.format(vid_id, vid_name)) sys.stdout.flush() return True
Example #23
Source File: hmdb51.py From gluon-cv with Apache License 2.0 | 5 votes |
def run_optical_flow(vid_item, dev_id=0): full_path, vid_path, vid_id = vid_item vid_name = vid_path.split('.')[0] out_full_path = osp.join(args.out_dir, vid_name) try: os.mkdir(out_full_path) except OSError: pass current = current_process() dev_id = (int(current._identity[0]) - 1) % args.num_gpu image_path = '{}/img'.format(out_full_path) flow_x_path = '{}/flow_x'.format(out_full_path) flow_y_path = '{}/flow_y'.format(out_full_path) cmd = osp.join(args.df_path, 'build/extract_gpu') + \ ' -f={} -x={} -y={} -i={} -b=20 -t=1 -d={} -s=1 -o={} -w={} -h={}' \ .format( quote(full_path), quote(flow_x_path), quote(flow_y_path), quote(image_path), dev_id, args.out_format, args.new_width, args.new_height) os.system(cmd) print('{} {} done'.format(vid_id, vid_name)) sys.stdout.flush() return True
Example #24
Source File: setupbase.py From K3D-jupyter with MIT License | 5 votes |
def list2cmdline(cmd_list): return ' '.join(map(pipes.quote, cmd_list))
Example #25
Source File: environment.py From clusterfuzz with Apache License 2.0 | 5 votes |
def get_sanitizer_options_for_display(): """Return a list of sanitizer options with quoted values.""" result = [] for tool in SUPPORTED_MEMORY_TOOLS_FOR_OPTIONS: options_variable = tool + '_OPTIONS' options_value = os.getenv(options_variable) if not options_value: continue result.append('{options_variable}="{options_value}"'.format( options_variable=options_variable, options_value=quote(options_value))) return result
Example #26
Source File: engine_test.py From clusterfuzz with Apache License 2.0 | 5 votes |
def setUp(self): android_helpers.AndroidTest.setUp(self) BaseIntegrationTest.setUp(self) if android.settings.get_sanitizer_tool_name() != 'hwasan': raise Exception('Device is not set up with HWASan.') environment.set_value('BUILD_DIR', ANDROID_DATA_DIR) environment.set_value('JOB_NAME', 'libfuzzer_hwasan_android_device') environment.reset_current_memory_tool_options() self.crash_dir = TEMP_DIR self.adb_path = android.adb.get_adb_path() self.hwasan_options = 'HWASAN_OPTIONS="%s"' % quote( environment.get_value('HWASAN_OPTIONS'))
Example #27
Source File: data_handler.py From clusterfuzz with Apache License 2.0 | 5 votes |
def _get_bazel_test_args(arguments, sanitizer_options): """Return arguments to pass to a bazel test.""" result = [] for sanitizer_option in sanitizer_options: result.append('--test_env=%s' % sanitizer_option) for argument in shlex.split(arguments): result.append('--test_arg=%s' % quote(argument)) return ' '.join(result)
Example #28
Source File: common.py From clusterfuzz with Apache License 2.0 | 5 votes |
def _run_and_handle_exception(arguments, exception_class): """Run a command and handle its error output.""" print('Running:', ' '.join(quote(arg) for arg in arguments)) try: return subprocess.check_output(arguments) except subprocess.CalledProcessError as e: raise exception_class(e.output)
Example #29
Source File: utils.py From mobly with Apache License 2.0 | 5 votes |
def cli_cmd_to_string(args): """Converts a cmd arg list to string. Args: args: list of strings, the arguments of a command. Returns: String representation of the command. """ if isinstance(args, basestring): # Return directly if it's already a string. return args return ' '.join([pipes.quote(arg) for arg in args])
Example #30
Source File: cmd.py From deimos with Apache License 2.0 | 5 votes |
def escape(argv): # NB: The pipes.quote() function is deprecated in Python 3 return " ".join(pipes.quote(_) for _ in argv)