本文整理汇总了Python中shlex.quote函数的典型用法代码示例。如果您正苦于以下问题:Python quote函数的具体用法?Python quote怎么用?Python quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quote函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _novoalign_command
def _novoalign_command(path, args, ncpu, reference, sample_name, read1, read2=None):
"""
Args:
path (str): path to aligner executable
args (str): raw arguments to be passed to the aligner
ncpu: number of alignment threads to launch
reference: (str): reference filename
sample_name (str):
read1 (str): absolute path to read1 fastq[.gz|.bz2]
read2 (str): absolute path to read2 fastq[.gz|.bz2]
Returns:
string: command to execute bowtie2 aligner
"""
import os
aligner_command = '{novoalign} -d {dbname} -f {read1} {read2} {paired_string} -c {ncpu} -o SAM {bam_string} {novoalign_args}'.format(**{
'novoalign': path,
'dbname': shlex.quote(reference + '.idx'),
'read1': shlex.quote(read1),
'read2': shlex.quote(read2) if read2 else '',
'paired_string': '-i PE 500,100' if read2 else '',
'ncpu': shlex.quote(str(ncpu)),
'bam_string': shlex.quote('@RG\\tID:{sample_name}\\tSM:{sample_name}'.format(sample_name=sample_name)),
'novoalign_args': ' '.join(map(shlex.quote, shlex.split(args)))
})
return aligner_command
示例2: bash_complete
def bash_complete(self, prefix, line, begidx, endidx):
"""Attempts BASH completion."""
splt = line.split()
cmd = splt[0]
func = self.bash_complete_funcs.get(cmd, None)
fnme = self.bash_complete_files.get(cmd, None)
if func is None or fnme is None:
return set()
idx = n = 0
for n, tok in enumerate(splt):
if tok == prefix:
idx = line.find(prefix, idx)
if idx >= begidx:
break
prev = tok
if len(prefix) == 0:
prefix = '""'
n += 1
else:
prefix = shlex.quote(prefix)
script = BASH_COMPLETE_SCRIPT.format(
filename=fnme, line=' '.join(shlex.quote(p) for p in splt),
comp_line=shlex.quote(line), n=n, func=func, cmd=cmd,
end=endidx + 1, prefix=prefix, prev=shlex.quote(prev))
try:
out = subprocess.check_output(
['bash'], input=script, universal_newlines=True,
stderr=subprocess.PIPE, env=builtins.__xonsh_env__.detype())
except subprocess.CalledProcessError:
out = ''
rtn = set(out.splitlines())
return rtn
示例3: png_add_mask_and_drop_shadow
def png_add_mask_and_drop_shadow(source_filepath, mask_filepath, destination_filepath, shadow_offset=10):
"""
Resize source png at 205x280 (75dpi), then cut out with 75 dpi mask, then add drop shadow
:param str source_filepath: Path to source png file
:param str mask_filepath: Path to mask png file
:param str destination_filepath: Path to save result file
:param int shadow_offset: Offset of shadow in pixels
:return:
"""
quoted_source_filepath = shlex.quote(source_filepath)
quoted_mask_filepath = shlex.quote(mask_filepath)
quoted_destination_filepath = shlex.quote(destination_filepath)
command = "convert \( {source_filepath} -resize 205x280 {mask_filepath} -alpha Off -compose copyopacity -composite \) \
-background black \( +clone -shadow 60x{offset}+{offset}+{offset} \) +swap \
-compose Over -composite +repage \
{destination_filepath}".format(
source_filepath=quoted_source_filepath,
mask_filepath=quoted_mask_filepath,
destination_filepath=quoted_destination_filepath,
offset=shadow_offset)
# execute command
status = subprocess.call(shlex.split(command))
if status != 0:
exit(status)
示例4: file
def file(self, root, filename):
self.file_count += 1
fullpath = os.path.join(root, filename)
byte_size = os.lstat(fullpath).st_size
self.size_total += byte_size
self.ctx.current_file = fullpath
local_vars = {
'_': os.path.basename(filename),
'p': fullpath,
'ap': os.path.abspath(fullpath),
'apq': shlex.quote(os.path.abspath(fullpath)),
'pq': shlex.quote(fullpath),
'q': shlex.quote(filename),
}
fmt = string.Formatter()
for (literal_text, field_name, format_spec, _) in fmt.parse(self.fmt_str):
if literal_text is not None:
sys.stdout.write(literal_text)
if field_name is not None:
value = eval(field_name, self.global_vars, local_vars) # pylint: disable=W0123
sys.stdout.write(format(value, format_spec))
示例5: update_platform
def update_platform(workspace_id: int, platform_id: int, platform_data) -> dict:
"""
Update the platform entry
:param workspace_id:
:param platform_id:
:return: The updated platform definition
"""
platform_name = shlex.quote(platform_data['name'])
platform_url = shlex.quote(platform_data['url'])
session = db_session()
workspace = session.query(Workspace).filter(Workspace.id == workspace_id).first()
if workspace is None:
raise NotFound("workspace with id {} could not be found".format(workspace_id))
platform = session.query(Platform). \
filter(Platform.workspace == workspace). \
filter(Platform.id == platform_id). \
first()
if platform is None:
raise NotFound("Platform with id {} could not be found".format(platform_id))
if platform_name != platform.name:
existing_platforms = session.query(Platform). \
filter(Platform.workspace == workspace). \
filter(Platform.name == platform_data['name']). \
all()
if len(existing_platforms) > 0:
raise NameConflict("Platform with name {} already exists".format(platform_data['name']))
platform.name = platform_name
platform.url = platform_url
update_workspace_descriptor(platform.workspace)
session.commit()
return platform.as_dict()
示例6: run_configure_script
def run_configure_script(self):
"runs configure-landscape, returns output (LDS hostname)"
ldscreds = self.config.getopt('landscapecreds')
args = {"bin": self.lscape_configure_bin,
"admin_email": shlex.quote(ldscreds['admin_email']),
"admin_name": shlex.quote(ldscreds['admin_name']),
"sys_email": shlex.quote(ldscreds['system_email']),
"maas_host": shlex.quote(
self.config.getopt('maascreds')['api_host'])}
cmd = ("{bin} --admin-email {admin_email} "
"--admin-name {admin_name} "
"--system-email {sys_email} "
"--maas-host {maas_host}".format(**args))
log.debug("Running landscape configure: {}".format(cmd))
out = utils.get_command_output(cmd, timeout=None)
if out['status']:
log.error("Problem with configuring Landscape: {}.".format(out))
raise Exception("Error configuring Landscape.")
return out['output'].strip()
示例7: get_command
def get_command(self, file, **options):
# on darwin open returns immediately resulting in the temp
# file removal while app is opening
command = "open -a /Applications/Preview.app"
command = "(%s %s; sleep 20; rm -f %s)&" % (command, quote(file),
quote(file))
return command
示例8: xcheck_host_prog
def xcheck_host_prog(conf, name, tool, wafname=None):
wafname = wafname or name
chost, chost_envar = get_chost_stuff(conf)
specific = None
if chost:
specific = os.environ.get('%s_%s' % (chost_envar, name))
if specific:
value = Utils.to_list(specific)
conf.env[wafname] += value
conf.msg('Will use cross-compilation %s from %s_%s' % (name, chost_envar, name),
" ".join(quote(x) for x in value))
return
else:
envar = os.environ.get('HOST_%s' % name)
if envar is not None:
value = Utils.to_list(envar)
conf.env[wafname] = value
conf.msg('Will use cross-compilation %s from HOST_%s' % (name, name),
" ".join(quote(x) for x in value))
return
if conf.env[wafname]:
return
value = None
if chost:
value = '%s-%s' % (chost, tool)
if value:
conf.env[wafname] = value
conf.msg('Will use cross-compilation %s from CHOST' % wafname, value)
示例9: __str__
def __str__(self):
ret = ''
for attr in 'cmd', 'ret_code', 'out', 'err':
value = getattr(self, attr, None)
if value is not None and str(value).strip():
mesg = ''
if attr == 'cmd' and self.cmd_kwargs.get('stdin_files'):
mesg += 'cat'
for file_path in self.cmd_kwargs.get('stdin_files'):
mesg += ' ' + quote(file_path)
mesg += ' | '
if attr == 'cmd' and isinstance(value, list):
mesg += ' '.join(quote(item) for item in value)
else:
mesg = str(value).strip()
if attr == 'cmd' and self.cmd_kwargs.get('stdin_str'):
mesg += ' <<<%s' % quote(self.cmd_kwargs.get('stdin_str'))
if len(mesg.splitlines()) > 1:
fmt = self.JOB_LOG_FMT_M
else:
fmt = self.JOB_LOG_FMT_1
if not mesg.endswith('\n'):
mesg += '\n'
ret += fmt % {
'cmd_key': self.cmd_key,
'attr': attr,
'mesg': mesg}
return ret.rstrip()
示例10: run
def run(self):
from subprocess import call
from pathlib import Path
import os.path
import inspect
import shlex
tm_path = shlex.quote(self.input()['tm'].fn)
lm_path = shlex.quote(self.input()['lm']['blm'].fn)
home = os.path.expanduser('~')
dir_name = Path(inspect.stack()[-1][1]).absolute().parent
current_dir_from_home = dir_name.relative_to(home)
print(current_dir_from_home)
toktagger_cmd = 'cd {cdir}; source {venv}; ./toktagger.py -t {tm} -l {lm} -f /'.format(
cdir='~/' + shlex.quote(str(current_dir_from_home)),
venv=shlex.quote('venv/bin/activate'),
tm=tm_path,
lm=lm_path)
print(toktagger_cmd)
parallel_cmd = 'parallel {params} -k --block-size {blocksize} --pipe {cmd}'.format(
params=self.parallel_params,
blocksize=self.parallel_blocksize,
cmd=shlex.quote(toktagger_cmd))
cmd = shlex.split(parallel_cmd)
print('running... ', parallel_cmd)
with self.input()['input'].open(
'r') as in_file, self.output().open('w') as out_file:
retcode = call(cmd, stdin=in_file, stdout=out_file)
assert retcode == 0
示例11: disp_kv
def disp_kv(key, val):
""" display a shell-escaped version of value ``val`` of ``key``,
using terminal 'dim' attribute for read-only variables.
"""
return (self.dim(shlex.quote(val))
if key in self.server.readonly_env
else shlex.quote(val))
示例12: keygen
def keygen(self, filename='', passphrase=''):
"""
Generate a public/private key pair and store them in ``filename``, encrypted by ``passphrase``
:param str filename: File name to store the private key in. The file name for the public key
will be derived from this name by suffixing it with ``.pub``
:param str passphrase: The passphrase used for encrypting the private key. Please note this passphrase
will only be accepted if it's longer than 4 characters. In case the passphrase
being empty or too short, ssh-keygen will ask for a passphrase using the system's
ssh-askpass mechanism.
"""
self._arguments.extend([
'-q',
'-t', self._algorithm,
'-b', str(self._keylength),
'-O', 'clear',
'-O', 'permit-pty',
'-C', shlex.quote('{user}@{host}'.format(user=os.getlogin(), host=os.uname().nodename)),
'-f', shlex.quote(filename)
])
if passphrase and len(passphrase) > 4:
self._arguments.extend([
'-N', shlex.quote(passphrase)
])
self._execute()
示例13: daemux_start
def daemux_start(transitions, session="pmjq", shell='sh'):
"""Instantiate the transitions, each in its own tmux window"""
for t in transitions:
t = normalize(t)
commands = []
# Template "directories" deals with watch-able templates
# that use a list as input
for dirs_key in [x for x in ["inputs", "outputs", "errors"]
if x in t]:
commands.append("watch -n1 "+shlex.quote(
COMMAND_TEMPLATES['directories'].format(
dirs=' '.join(
map(lambda d:
os.path.dirname(smart_unquote(d)),
t[dirs_key])))))
# Template "stderr" deals with the log files
if "stderr" in t:
commands.append("watch -n1 "+shlex.quote(
COMMAND_TEMPLATES['stderr'].format(
stderr=os.path.dirname(
smart_unquote(t['stderr'])))))
# The command
if shell == "sh":
commands.append(pmjq_command(t))
elif shell == 'fish':
commands.append(pmjq_command(t, redirect='^'))
# The other templates can be used as is
for k in [k for k in COMMAND_TEMPLATES
if k not in ['directories', 'stderr', 'cmd']]:
if k in t:
commands.append(COMMAND_TEMPLATES[k].format(**t))
for i, cmd in enumerate(commands):
daemux.start(cmd, session=session, window=t['id'], pane=i,
layout='tiled')
示例14: _snap_command
def _snap_command(path, args, ncpu, reference, output_folder, sample_name, read1, read2=None):
"""
Args:
path (str): path to aligner executable
args (str): raw arguments to be passed to the aligner
ncpu: number of alignment threads to launch
reference: (str): reference filename
output_folder (str): directory for aligner output
sample_name (str):
read1 (str): absolute path to read1 fastq[.gz|.bz2]
read2 (str): absolute path to read2 fastq[.gz|.bz2]
Returns:
string: command to execute bowtie2 aligner
"""
import os
aligner_command = '{snap} {single_or_paired} {ref_dir} {read1} {read2} -t {ncpu} -b {snap_args} -o sam -'.format(**{
'snap': path,
'single_or_paired': 'paired' if read2 else 'single',
'ref_dir': shlex.quote(os.path.join(output_folder, 'reference', 'snap')),
'read1': shlex.quote(read1),
'read2': shlex.quote(read2) if read2 else '',
'ncpu': shlex.quote(str(ncpu)),
'snap_args': ' '.join(map(shlex.quote, shlex.split(args)))
})
return aligner_command
示例15: start
def start(self, collection, docker, ping, database_name):
options = self.options
"""Launches a cAdvisor container on the instance."""
volumes = {
'/': {'bind': '/rootfs', 'ro': True},
'/var/run': {'bind': '/var/run', 'ro': False},
'/sys': {'bind': '/sys', 'ro': True},
'/var/lib/docker': {'bind': '/var/lib/docker', 'ro': True}
}
logger.debug("cAdvisor: Writing stats to %s" % database_name)
command_args = " ".join([
"-storage_driver=influxdb",
"-log_dir=/",
"-storage_driver_db=%s" % quote(database_name),
"-storage_driver_host=%s:%d" % (quote(options.host),
options.port),
"-storage_driver_user=%s" % quote(options.user),
"-storage_driver_password=%s" % quote(options.password),
"-storage_driver_secure=%d" % options.secure,
# TODO: Calculate based on the run time.
"-storage_driver_buffer_duration=5s"
])
yield docker.run_containers(collection, self.info.name,
None, command_args, volumes,
ports={8080: 8080})
yield self.wait(collection, ping)