本文整理汇总了Python中six.moves.shlex_quote方法的典型用法代码示例。如果您正苦于以下问题:Python moves.shlex_quote方法的具体用法?Python moves.shlex_quote怎么用?Python moves.shlex_quote使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves
的用法示例。
在下文中一共展示了moves.shlex_quote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_all_bits
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def _get_all_bits(self, bit_accessor):
all_bits = []
for bit in self.bits:
quote = False
if isinstance(bit, QuoteString):
quote = True
bit = bit.object
if isinstance(bit, StringCommand):
bit = bit_accessor(bit)
if quote:
bit = shlex_quote(bit)
all_bits.append(bit)
return all_bits
示例2: run
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def run(self, args, unknown_args):
env = os.environ.copy()
put_virtualenv_bin_on_the_path()
if not os.path.exists(ANSIBLE_ROLES_PATH):
os.makedirs(ANSIBLE_ROLES_PATH)
if not os.path.exists(ANSIBLE_COLLECTIONS_PATHS):
os.makedirs(ANSIBLE_COLLECTIONS_PATHS)
env['ANSIBLE_ROLES_PATH'] = ANSIBLE_ROLES_PATH
env['ANSIBLE_COLLECTIONS_PATHS'] = ANSIBLE_COLLECTIONS_PATHS
cmd_roles_parts = ['ansible-galaxy', 'install', '-f', '-r', os.path.join(ANSIBLE_DIR, 'requirements.yml')]
cmd_collection_parts = ['ansible-galaxy', 'collection', 'install', '-f', '-r', os.path.join(ANSIBLE_DIR, 'requirements.yml')]
for cmd_parts in (cmd_roles_parts, cmd_collection_parts):
cmd = ' '.join(shlex_quote(arg) for arg in cmd_parts)
print_command(cmd)
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True, env=env)
p.communicate()
puts(color_notice("To finish first-time installation, run `manage-commcare-cloud configure`".format()))
return p.returncode
示例3: get_entry_point
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def get_entry_point(self, entry_point):
if entry_point in self._entry_points:
return self._entry_points[entry_point]
_, file_extension = os.path.splitext(entry_point)
ext_to_cmd = {".py": "python", ".sh": os.environ.get("SHELL", "bash")}
if file_extension in ext_to_cmd:
command = "%s %s" % (ext_to_cmd[file_extension], shlex_quote(entry_point))
if not is_string_type(command):
command = command.encode("utf-8")
return EntryPoint(name=entry_point, parameters={}, command=command)
elif file_extension == ".R":
command = "Rscript -e \"mlflow::mlflow_source('%s')\" --args" % shlex_quote(entry_point)
return EntryPoint(name=entry_point, parameters={}, command=command)
raise ExecutionException("Could not find {0} among entry points {1} or interpret {0} as a "
"runnable script. Supported script file extensions: "
"{2}".format(entry_point, list(self._entry_points.keys()),
list(ext_to_cmd.keys())))
示例4: test_entry_point_compute_command
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def test_entry_point_compute_command():
"""
Tests that EntryPoint correctly computes the command to execute in order to run the entry point.
"""
project = load_project()
entry_point = project.get_entry_point("greeter")
with TempDir() as tmp:
storage_dir = tmp.path()
command = entry_point.compute_command({"name": "friend", "excitement": 10}, storage_dir)
assert command == "python greeter.py hi friend --excitement 10"
with pytest.raises(ExecutionException):
entry_point.compute_command({}, storage_dir)
# Test shell escaping
name_value = "friend; echo 'hi'"
command = entry_point.compute_command({"name": name_value}, storage_dir)
assert command == "python greeter.py %s %s" % (shlex_quote("hi"), shlex_quote(name_value))
示例5: print_env_vars
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def print_env_vars(credentials, target_profile):
aws_access_key_id = shlex_quote(credentials.get(
target_profile, 'aws_access_key_id'))
aws_secret_access_key = shlex_quote(credentials.get(
target_profile, 'aws_secret_access_key'))
aws_session_token = shlex_quote(credentials.get(
target_profile, 'aws_session_token'))
print("AWS_ACCESS_KEY_ID=%s; export AWS_ACCESS_KEY_ID;" %
shlex_quote(aws_access_key_id))
print("AWS_SECRET_ACCESS_KEY=%s; export AWS_SECRET_ACCESS_KEY;" %
shlex_quote(aws_secret_access_key))
print("AWS_SESSION_TOKEN=%s; export AWS_SESSION_TOKEN;" %
shlex_quote(aws_session_token))
# for backwards compatibility with older Boto
print("AWS_SECURITY_TOKEN=%s; export AWS_SECURITY_TOKEN;" %
shlex_quote(aws_session_token))
示例6: sed_step
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def sed_step(self, file=None, in_place=True, patterns=[]):
"""Generate sed command line string"""
if not file:
logging.error('file is not defined')
return ''
if not patterns:
logging.error('patterns is not defined')
return ''
# Copy so not to modify the member variable
opts = list(self.sed_opts)
if in_place:
opts.append('-i')
opt_string = ' '.join(opts)
quoted_patterns = ['-e {}'.format(shlex_quote(patterns[0]))]
quoted_patterns.extend(' -e {}'.format(shlex_quote(x)) for x in patterns[1:])
quoted_pattern_string = ' \\\n'.join(quoted_patterns)
return 'sed {0} {1} {2}'.format(opt_string, quoted_pattern_string, file)
示例7: make_win_command
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def make_win_command(
command,
env=None,
shell_executable=Config.SHELL,
):
'''
Builds a windows command with various kwargs.
'''
debug_meta = {}
for key, value in (
('shell_executable', shell_executable),
('env', env),
):
if value:
debug_meta[key] = value
logger.debug('Building command ({0}): {1}'.format(' '.join(
'{0}: {1}'.format(key, value)
for key, value in six.iteritems(debug_meta)
), command))
# Use env & build our actual command
if env:
env_string = ' '.join([
'{0}={1}'.format(key, value)
for key, value in six.iteritems(env)
])
command = 'export {0}; {1}'.format(env_string, command)
# Quote the command as a string
command = shlex_quote(command)
command = '{0}'.format(command)
return command
示例8: command
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def command(self, name, pattern):
name = escape_unix_path(name)
pattern = shlex_quote(pattern)
self.name = name
return (
'grep -e {0} {1} 2> /dev/null || '
'(find {1} -type f > /dev/null && echo "__pyinfra_exists_{1}")'
).format(pattern, name).strip()
示例9: test_run_shell_command
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def test_run_shell_command(self):
inventory = make_inventory(hosts=('@chroot/not-a-chroot',))
state = State(inventory, Config())
host = inventory.get_host('@chroot/not-a-chroot')
host.connect(state)
command = 'echo hoi'
self.fake_popen_mock().returncode = 0
out = host.run_shell_command(
state, command,
stdin='hello',
get_pty=True,
print_output=True,
)
assert len(out) == 3
assert out[0] is True
command = make_unix_command(command).get_raw_value()
command = shlex_quote(command)
docker_command = 'chroot /not-a-chroot sh -c {0}'.format(command)
shell_command = make_unix_command(docker_command).get_raw_value()
self.fake_popen_mock.assert_called_with(
shell_command, shell=True,
stdout=PIPE, stderr=PIPE, stdin=PIPE,
)
示例10: test_run_shell_command
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def test_run_shell_command(self):
inventory = make_inventory(hosts=('@docker/not-an-image',))
state = State(inventory, Config())
command = 'echo hi'
self.fake_popen_mock().returncode = 0
host = inventory.get_host('@docker/not-an-image')
host.connect(state)
out = host.run_shell_command(
state, command,
stdin='hello',
get_pty=True,
print_output=True,
)
assert len(out) == 3
assert out[0] is True
command = make_unix_command(command).get_raw_value()
command = shlex_quote(command)
docker_command = 'docker exec -it containerid sh -c {0}'.format(command)
shell_command = make_unix_command(docker_command).get_raw_value()
self.fake_popen_mock.assert_called_with(
shell_command, shell=True,
stdout=PIPE, stderr=PIPE, stdin=PIPE,
)
示例11: get_nondefault_flags_as_str
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def get_nondefault_flags_as_str():
"""Returns flags as a string that can be passed as command line arguments.
E.g., returns: "--batch_size=256 --use_synthetic_data" for the following code
block:
```
flags.FLAGS.batch_size = 256
flags.FLAGS.use_synthetic_data = True
print(get_nondefault_flags_as_str())
```
Only flags with nondefault values are returned, as passing default flags as
command line arguments has no effect.
Returns:
A string with the flags, that can be passed as command line arguments to a
program to use the flags.
"""
nondefault_flags = _get_nondefault_flags_as_dict()
flag_strings = []
for name, value in sorted(nondefault_flags.items()):
if isinstance(value, bool):
flag_str = '--{}'.format(name) if value else '--no{}'.format(name)
elif isinstance(value, list):
flag_str = '--{}={}'.format(name, ','.join(value))
else:
flag_str = '--{}={}'.format(name, value)
flag_strings.append(flag_str)
return ' '.join(shlex_quote(flag_str) for flag_str in flag_strings)
示例12: set
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def set(self, key, value):
"""Configure an app key/value pair"""
cmd = [
"heroku",
"config:set",
"{}={}".format(key, quote(str(value))),
"--app",
self.name,
]
if self._is_sensitive_key(key):
self._run_quiet(cmd)
else:
self._run(cmd)
示例13: set_multiple
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def set_multiple(self, **kwargs):
"""Configure multiple app key/value pairs"""
quiet = False
if not kwargs:
return
cmd = ["heroku", "config:set"]
for k in sorted(kwargs):
cmd.append("{}={}".format(k, quote(str(kwargs[k]))))
if self._is_sensitive_key(k):
quiet = True
cmd.extend(["--app", self.name])
if quiet:
self._run_quiet(cmd)
else:
self._run(cmd)
示例14: exec_fab_command
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def exec_fab_command(env_name, *extra_args):
cmd_parts = (
'fab', '-f', FABFILE,
env_name,
) + tuple(extra_args)
cmd = ' '.join(shlex_quote(arg) for arg in cmd_parts)
print_command(cmd)
return subprocess.call(cmd_parts)
示例15: run_ansible_module
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import shlex_quote [as 别名]
def run_ansible_module(environment, ansible_context, inventory_group, module, module_args,
become, become_user, factory_auth, *extra_args):
cmd_parts = (
'ansible', inventory_group,
'-m', module,
'-i', environment.paths.inventory_source,
'-a', module_args,
'--diff',
) + tuple(extra_args)
environment.create_generated_yml()
public_vars = environment.public_vars
cmd_parts += get_user_arg(public_vars, extra_args, use_factory_auth=factory_auth)
become = become or bool(become_user)
become_user = become_user
include_vars = False
if become:
cmd_parts += ('--become',)
include_vars = True
if become_user:
cmd_parts += ('--become-user', become_user)
if include_vars:
cmd_parts += (
'-e', '@{}'.format(environment.paths.vault_yml),
'-e', '@{}'.format(environment.paths.public_yml),
'-e', '@{}'.format(environment.paths.generated_yml),
)
ask_vault_pass = include_vars and public_vars.get('commcare_cloud_use_vault', True)
if ask_vault_pass:
cmd_parts += ('--vault-password-file={}/echo_vault_password.sh'.format(ANSIBLE_DIR),)
cmd_parts_with_common_ssh_args = get_common_ssh_args(environment, use_factory_auth=factory_auth)
cmd_parts += cmd_parts_with_common_ssh_args
cmd = ' '.join(shlex_quote(arg) for arg in cmd_parts)
print_command(cmd)
env_vars = ansible_context.env_vars
if ask_vault_pass:
env_vars['ANSIBLE_VAULT_PASSWORD'] = environment.get_ansible_vault_password()
return subprocess.call(cmd_parts, env=env_vars)