本文整理汇总了Python中pipes.quote方法的典型用法代码示例。如果您正苦于以下问题:Python pipes.quote方法的具体用法?Python pipes.quote怎么用?Python pipes.quote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pipes
的用法示例。
在下文中一共展示了pipes.quote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _logged_catched
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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)
示例2: _clone_cmd
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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)
示例3: _execute
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
def _execute(self, cmd, skip_cwd=False, **kwargs):
"""
Additional Args:
skip_cwd (bool): Whether to skip changing to the current working
directory associated with this client before executing the
command. This is mainly useful to methods internal to this
class.
"""
template = 'ssh {login} -T -o ControlPath={socket} << EOF\n{cwd}{cmd}\nEOF'
config = dict(self._subprocess_config)
config.update(kwargs)
cwd = 'cd "{path}"\n'.format(path=escape_path(self.path_cwd)) if not skip_cwd else ''
return run_in_subprocess(template.format(login=self._login_info,
socket=self._socket_path,
cwd=cwd,
cmd=cmd),
check_output=True,
**config)
示例4: _ExecInDocker
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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)
示例5: main
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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)
示例6: main
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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
示例7: _get_memory_tool_options
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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
示例8: say
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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
示例9: run_warp_optical_flow
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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
示例10: show_image
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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()
示例11: main
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
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")
示例12: escape_shellarg
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
def escape_shellarg(*args):
"""Escape shell arguments."""
import pipes
return " ".join([pipes.quote(str(arg)) for arg in args])
示例13: shellescape
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
def shellescape(args):
from pipes import quote
return ' '.join(quote(timid_relpath(arg)) for arg in args)
示例14: list2cmdline
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
def list2cmdline(cmd_list):
return ' '.join(map(pipes.quote, cmd_list))
示例15: _run_git_cmd
# 需要导入模块: import pipes [as 别名]
# 或者: from pipes import quote [as 别名]
def _run_git_cmd(vc_dir, cmd, regex=None, abortOnError=True):
"""
:type vc_dir: str
:type cmd: list[str]
:type regex: str | None
:type abortOnError: bool
:rtype: str
"""
git = mx.GitConfig()
output = (git.git_command(vc_dir, cmd, abortOnError=abortOnError) or '').strip()
if regex is not None and re.match(regex, output, re.MULTILINE) is None:
if abortOnError:
raise mx.abort("Unexpected output running command '{cmd}'. Expected a match for '{regex}', got:\n{output}".format(cmd=' '.join(map(pipes.quote, ['git', '-C', vc_dir, '--no-pager'] + cmd)), regex=regex, output=output))
return None
return output