本文整理汇总了Python中shlex._cmd_quote函数的典型用法代码示例。如果您正苦于以下问题:Python _cmd_quote函数的具体用法?Python _cmd_quote怎么用?Python _cmd_quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_cmd_quote函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chgid
def chgid(name, gid):
'''
Change the default group of the user
CLI Example:
.. code-block:: bash
salt '*' user.chgid foo 4376
'''
if not isinstance(gid, int):
raise SaltInvocationError('gid must be an integer')
pre_info = info(name)
if not pre_info:
raise CommandExecutionError('User {0!r} does not exist'.format(name))
if gid == pre_info['gid']:
return True
_dscl(
'/Users/{0} PrimaryGroupID {1!r} {2!r}'.format(
_cmd_quote(name), _cmd_quote(pre_info['gid']),
_cmd_quote(gid)),
ctype='change'
)
# dscl buffers changes, sleep 1 second before checking if new value
# matches desired value
time.sleep(1)
return info(name).get('gid') == gid
示例2: chhome
def chhome(name, home):
'''
Change the home directory of the user
CLI Example:
.. code-block:: bash
salt '*' user.chhome foo /Users/foo
'''
pre_info = info(name)
if not pre_info:
raise CommandExecutionError('User {0!r} does not exist'.format(name))
if home == pre_info['home']:
return True
_dscl(
'/Users/{0} NFSHomeDirectory {1!r} {2!r}'.format(
_cmd_quote(name),
_cmd_quote(pre_info['home']),
_cmd_quote(home)),
ctype='change'
)
# dscl buffers changes, sleep 1 second before checking if new value
# matches desired value
time.sleep(1)
return info(name).get('home') == home
示例3: update
def update(gems, ruby=None, runas=None, gem_bin=None):
'''
Update one or several gems.
:param gems: string
The gems to update.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.update vagrant
'''
# Check for injection
if gems:
gems = ' '.join([_cmd_quote(gem) for gem in gems.split()])
if ruby:
ruby = _cmd_quote(ruby)
if gem_bin:
gem_bin = _cmd_quote(gem_bin)
return _gem('update {gems}'.format(gems=gems),
ruby,
gem_bin=gem_bin,
runas=runas)
示例4: _rbenv_exec
def _rbenv_exec(command, args='', env=None, runas=None, ret=None):
if not is_installed(runas):
return False
binary = _rbenv_bin(runas)
path = _rbenv_path(runas)
environ = {}
for token in _cmd_split(env):
try:
var, val = token.split('=')
environ[var] = val
except Exception:
pass # if token != var=val, it's not a proper env anyway
environ['RBENV_ROOT'] = path
args = ' '.join([_cmd_quote(arg) for arg in _cmd_split(args)])
result = __salt__['cmd.run_all'](
'{0} {1} {2}'.format(binary, _cmd_quote(command), args),
runas=runas,
env=environ
)
if isinstance(ret, dict):
ret.update(result)
return ret
if result['retcode'] == 0:
return result['stdout']
else:
return False
示例5: pair
def pair(address, key):
'''
Pair the bluetooth adapter with a device
CLI Example:
.. code-block:: bash
salt '*' bluetooth.pair DE:AD:BE:EF:CA:FE 1234
Where DE:AD:BE:EF:CA:FE is the address of the device to pair with, and 1234
is the passphrase.
TODO: This function is currently broken, as the bluez-simple-agent program
no longer ships with BlueZ >= 5.0. It needs to be refactored.
'''
if not salt.utils.validate.net.mac(address):
raise CommandExecutionError(
'Invalid BD address passed to bluetooth.pair'
)
try:
int(key)
except Exception:
raise CommandExecutionError(
'bluetooth.pair requires a numerical key to be used'
)
addy = address_()
cmd = 'echo {0} | bluez-simple-agent {1} {2}'.format(
_cmd_quote(addy['device']), _cmd_quote(address), _cmd_quote(key)
)
out = __salt__['cmd.run'](cmd, python_shell=True).splitlines()
return out
示例6: removegroup
def removegroup(name, group):
'''
Remove user from a group
:param str name:
user name to remove from the group
:param str group:
name of the group from which to remove the user
:return:
True if successful. False is unsuccessful.
:rtype: bool
CLI Example:
.. code-block:: bash
salt '*' user.removegroup jsnuffy 'Power Users'
'''
name = _cmd_quote(name)
group = _cmd_quote(group).lstrip('\'').rstrip('\'')
user = info(name)
if not user:
return False
if group not in user['groups']:
return True
cmd = 'net localgroup "{0}" {1} /delete'.format(group, name)
ret = __salt__['cmd.run_all'](cmd, python_shell=True)
return ret['retcode'] == 0
示例7: do
def do(cmdline=None, runas=None):
'''
Execute a python command with pyenv's shims from the user or the system.
CLI Example:
.. code-block:: bash
salt '*' pyenv.do 'gem list bundler'
salt '*' pyenv.do 'gem list bundler' deploy
'''
path = _pyenv_path(runas)
cmd_split = cmdline.split()
quoted_line = ''
for cmd in cmd_split:
quoted_line = quoted_line + ' ' + _cmd_quote(cmd)
result = __salt__['cmd.run_all'](
'env PATH={0}/shims:$PATH {1}'.format(_cmd_quote(path), quoted_line),
runas=runas,
python_shell=True
)
if result['retcode'] == 0:
rehash(runas=runas)
return result['stdout']
else:
return False
示例8: sources_remove
def sources_remove(source_uri, ruby=None, runas=None, gem_bin=None):
'''
Remove a gem source.
:param source_uri: string
The source URI to remove.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_remove http://rubygems.org/
'''
# Check for injection
if source_uri:
source_uri = _cmd_quote(source_uri)
if ruby:
ruby = _cmd_quote(ruby)
if gem_bin:
gem_bin = _cmd_quote(gem_bin)
return _gem('sources --remove {source_uri}'.format(source_uri=source_uri),
ruby,
gem_bin=gem_bin,
runas=runas)
示例9: removegroup
def removegroup(name, group):
'''
Remove user from a group
CLI Example:
.. code-block:: bash
salt '*' user.removegroup username groupname
'''
name = _cmd_quote(name)
group = _cmd_quote(group).lstrip('\'').rstrip('\'')
user = info(name)
if not user:
return False
if group not in user['groups']:
return True
cmd = 'net localgroup "{0}" {1} /delete'.format(group, name)
ret = __salt__['cmd.run_all'](cmd, python_shell=True)
return ret['retcode'] == 0
示例10: chfullname
def chfullname(name, fullname):
'''
Change the full name of the user
CLI Example:
.. code-block:: bash
salt '*' user.chfullname user 'First Last'
'''
pre_info = info(name)
if not pre_info:
return False
name = _cmd_quote(name)
fullname_qts = _cmd_quote(fullname).replace("'", "\"")
if fullname == pre_info['fullname']:
return True
if __salt__['cmd.retcode']('net user {0} /fullname:{1}'.format(
name, fullname_qts), python_shell=True) != 0:
return False
post_info = info(name)
if post_info['fullname'] != pre_info['fullname']:
return post_info['fullname'] == fullname
return False
示例11: version_cmp
def version_cmp(pkg1, pkg2):
'''
Do a cmp-style comparison on two packages. Return -1 if pkg1 < pkg2, 0 if
pkg1 == pkg2, and 1 if pkg1 > pkg2. Return None if there was a problem
making the comparison.
CLI Example:
.. code-block:: bash
salt '*' pkg.version_cmp '0.2.4-0' '0.2.4.1-0'
'''
cmd_compare = ['opkg-compare-versions']
for oper, ret in (("<<", -1), ("=", 0), (">>", 1)):
cmd = cmd_compare[:]
cmd.append(_cmd_quote(pkg1))
cmd.append(oper)
cmd.append(_cmd_quote(pkg2))
retcode = __salt__['cmd.retcode'](cmd,
output_loglevel='trace',
ignore_retcode=True,
python_shell=False)
if retcode == 0:
return ret
return None
示例12: sources_list
def sources_list(ruby=None, runas=None, gem_bin=None):
'''
List the configured gem sources.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_list
'''
# Check for injection
if ruby:
ruby = _cmd_quote(ruby)
if gem_bin:
gem_bin = _cmd_quote(gem_bin)
ret = _gem('sources', ruby, gem_bin=gem_bin, runas=runas)
return [] if ret is False else ret.splitlines()[2:]
示例13: version_cmp
def version_cmp(pkg1, pkg2, ignore_epoch=False):
'''
Do a cmp-style comparison on two packages. Return -1 if pkg1 < pkg2, 0 if
pkg1 == pkg2, and 1 if pkg1 > pkg2. Return None if there was a problem
making the comparison.
ignore_epoch : False
Set to ``True`` to ignore the epoch when comparing versions
.. versionadded:: 2016.3.4
CLI Example:
.. code-block:: bash
salt '*' pkg.version_cmp '0.2.4-0' '0.2.4.1-0'
'''
normalize = lambda x: str(x).split(':', 1)[-1] if ignore_epoch else str(x)
pkg1 = normalize(pkg1)
pkg2 = normalize(pkg2)
cmd_compare = ['opkg-compare-versions']
for oper, ret in (("<<", -1), ("=", 0), (">>", 1)):
cmd = cmd_compare[:]
cmd.append(_cmd_quote(pkg1))
cmd.append(oper)
cmd.append(_cmd_quote(pkg2))
retcode = __salt__['cmd.retcode'](cmd,
output_loglevel='trace',
ignore_retcode=True,
python_shell=False)
if retcode == 0:
return ret
return None
示例14: _rbenv_exec
def _rbenv_exec(command, args='', env=None, runas=None, ret=None):
if not is_installed(runas):
return False
binary = _rbenv_bin(runas)
path = _rbenv_path(runas)
environ = _parse_env(env)
environ['RBENV_ROOT'] = path
args = ' '.join([_cmd_quote(arg) for arg in _shlex_split(args)])
result = __salt__['cmd.run_all'](
'{0} {1} {2}'.format(binary, _cmd_quote(command), args),
runas=runas,
env=environ
)
if isinstance(ret, dict):
ret.update(result)
return ret
if result['retcode'] == 0:
return result['stdout']
else:
return False
示例15: chshell
def chshell(name, shell):
'''
Change the default shell of the user
CLI Example:
.. code-block:: bash
salt '*' user.chshell foo /bin/zsh
'''
pre_info = info(name)
if not pre_info:
raise CommandExecutionError('User {0!r} does not exist'.format(name))
if shell == pre_info['shell']:
return True
_dscl(
'/Users/{0} UserShell {1!r} {2!r}'.format(
_cmd_quote(name),
_cmd_quote(pre_info['shell']),
_cmd_quote(shell)),
ctype='change'
)
# dscl buffers changes, sleep 1 second before checking if new value
# matches desired value
time.sleep(1)
return info(name).get('shell') == shell