コード例 #1
0
ファイル: __init__.py プロジェクト: svetlyak40wt/fabricant
def _run_with_agent(command, shell=True, pty=True, ssh_options='-A'):
    """
    Helper function.
    Runs a command with SSH agent forwarding enabled.

    Note:: Fabric (and paramiko) can't forward your SSH agent.~
    This helper uses your system's ssh to do so.
    """
    env = fabric.api.env
    real_command = command
    if shell:
        cwd = env.get('cwd', '')
        if cwd:
            cwd = 'cd %s && ' % _shell_escape(cwd)
        real_command = '%s "%s"' % (env.shell,
            _shell_escape(cwd + real_command))

    if fabric.api.output.debug:
        print("[%s] run: %s" % (env.host_string, real_command))
    elif fabric.api.output.running:
        print("[%s] run: %s" % (env.host_string, command))

    return fabric.api.local("ssh {options} -p {env.port} -l {env.user} {env.host} '{command}'".format(
            env=env,
            command=real_command,
            options=ssh_options,
        )
    )
コード例 #2
0
def _run_with_agent(command, shell=True, pty=True, ssh_options='-A'):
    """
    Helper function.
    Runs a command with SSH agent forwarding enabled.

    Note:: Fabric (and paramiko) can't forward your SSH agent.~
    This helper uses your system's ssh to do so.
    """
    env = fabric.api.env
    real_command = command
    if shell:
        cwd = env.get('cwd', '')
        if cwd:
            cwd = 'cd %s && ' % _shell_escape(cwd)
        real_command = '%s "%s"' % (env.shell,
                                    _shell_escape(cwd + real_command))

    if fabric.api.output.debug:
        print("[%s] run: %s" % (env.host_string, real_command))
    elif fabric.api.output.running:
        print("[%s] run: %s" % (env.host_string, command))

    return fabric.api.local(
        "ssh {options} -p {env.port} -l {env.user} {env.host} '{command}'".
        format(
            env=env,
            command=real_command,
            options=ssh_options,
        ))
コード例 #3
0
ファイル: fabfile.py プロジェクト: Barrels-wine/Barrels
def docker_compose_run(command_name, service, user="******", no_deps=False):
    args = ['run ' '--rm ' '-u %s ' % _shell_escape(user)]

    if no_deps:
        args.append('--no-deps ')

    docker_compose(
        '%s %s /bin/bash -c "%s"' %
        (' '.join(args), _shell_escape(service), _shell_escape(command_name)))
コード例 #4
0
ファイル: test_operations.py プロジェクト: xpoft/fabric
def test_shell_wrap_escapes_command_if_shell_is_true():
    """
    _shell_wrap() escapes given command if shell=True
    """
    cmd = "cd \"Application Support\""
    eq_(_shell_wrap(cmd, shell=True),
        '%s "%s"' % (env.shell, _shell_escape(cmd)))
コード例 #5
0
ファイル: test_operations.py プロジェクト: itsmeallan/fabric
def test_shell_wrap_escapes_command_if_shell_is_true():
    """
    _shell_wrap() escapes given command if shell=True
    """
    cmd = "cd \"Application Support\""
    eq_(
        _shell_wrap(cmd, shell_escape=True, shell=True),
        '%s "%s"' % (env.shell, _shell_escape(cmd))
    )
コード例 #6
0
ファイル: fabfile.py プロジェクト: poirier/voices
def sshagent_run(command, shell=True, pty=True):
    """
    Helper function.
    Runs a command with SSH agent forwarding enabled.

    Note:: Fabric (and paramiko) can't forward your SSH agent.
    This helper uses your system's ssh to do so.
    """
    real_command = command
    if shell:
        cwd = env.get('cwd', '')
        if cwd:
            cwd = 'cd %s && ' % _shell_escape(cwd)
        real_command = '%s "%s"' % (env.shell,
            _shell_escape(cwd + real_command))
    if output.debug:
        print("[%s] run: %s" % (env.host_string, real_command))
    elif output.running:
        print("[%s] run: %s" % (env.host_string, command))
    local("ssh -A %s '%s'" % (env.host_string, real_command))
コード例 #7
0
ファイル: fabfile.py プロジェクト: olivmai/docker-starter
def docker_compose_run(command_name, service="builder", user="******", no_deps=False, workdir=None, port_mapping=False):
    args = [
        'run ',
        '--rm ',
        '-u %s ' % _shell_escape(user),
    ]

    if no_deps:
        args.append('--no-deps ')

    if port_mapping:
        args.append('--service-ports ')

    if workdir is not None:
        args.append('-w %s ' % _shell_escape(workdir))

    docker_compose('%s %s /bin/bash -c "exec %s"' % (
        ' '.join(args),
        _shell_escape(service),
        _shell_escape(command_name)
    ))
コード例 #8
0
ファイル: fabfile.py プロジェクト: cash2one/source
def _run(command,
         shell=True,
         pty=True,
         combine_stderr=True,
         sudo=False,
         user=None):
    real_command = command
    if shell:
        # Handle cwd munging via 'cd' context manager
        cwd = env.get('cwd', '')
        if cwd:
            cwd = 'cd %s && ' % _shell_escape(cwd)
        # Construct final real, full command
        real_command = '%s "%s"' % (env.shell,
                                    _shell_escape(cwd + real_command))
        # Remove cwd from context
        env.cwd = ''
    if output.debug:
        print("[%s] run: %s" % (env.host_string, real_command))
    elif output.running:
        print("[%s] run: %s" % (env.host_string, command))
    local("ssh -A %s@%s '%s'" % (env.user, env.host_string, real_command))
コード例 #9
0
def _sshagent_run(command, shell=True, pty=True):
    """
    Helper function.
    Runs a command with SSH agent forwarding enabled.

    Note:: Fabric (and paramiko) can't forward your SSH agent.
    This helper uses your system's ssh to do so.
    """
    real_command = command
    if shell:
        cwd = api.env.get('cwd', '')
        if cwd:
            cwd = 'cd %s && ' % _shell_escape(cwd)
        real_command = '%s "%s"' % (api.env.shell,
            _shell_escape(cwd + real_command))
    if output.debug:
        print("[%s] run: %s" % (api.env.host_string, real_command))
    elif output.running:
        print("[%s] run: %s" % (api.env.host_string, command))
    with api.settings(api.hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=True):
        return api.local(
            "ssh -A %s '%s'" % (api.env.host_string, real_command))
コード例 #10
0
ファイル: test_operations.py プロジェクト: itsmeallan/fabric
def test_shell_escape_escapes_doublequotes():
    """
    _shell_escape() escapes double-quotes
    """
    cmd = "cd \"Application Support\""
    eq_(_shell_escape(cmd), 'cd \\"Application Support\\"')
コード例 #11
0
ファイル: test_operations.py プロジェクト: xpoft/fabric
def test_shell_escape_escapes_backticks():
    """
    _shell_escape() escapes backticks
    """
    cmd = "touch test.pid && kill `cat test.pid`"
    eq_(_shell_escape(cmd), "touch test.pid && kill \`cat test.pid\`")
コード例 #12
0
ファイル: test_operations.py プロジェクト: xpoft/fabric
def test_shell_escape_escapes_dollar_signs():
    """
    _shell_escape() escapes dollar signs
    """
    cmd = "cd $HOME"
    eq_(_shell_escape(cmd), 'cd \$HOME')
コード例 #13
0
ファイル: test_operations.py プロジェクト: xpoft/fabric
def test_shell_escape_escapes_doublequotes():
    """
    _shell_escape() escapes double-quotes
    """
    cmd = "cd \"Application Support\""
    eq_(_shell_escape(cmd), 'cd \\"Application Support\\"')
コード例 #14
0
ファイル: test_operations.py プロジェクト: imankulov/fabric
def test_shell_escape_escapes_backslashes():
    """
    _shell_escape() escapes backslashes
    """
    cmd = r'echo "\""'
    eq_(_shell_escape(cmd), r'echo \"\\\"\"')
コード例 #15
0
ファイル: test_operations.py プロジェクト: itsmeallan/fabric
def test_shell_escape_escapes_dollar_signs():
    """
    _shell_escape() escapes dollar signs
    """
    cmd = "cd $HOME"
    eq_(_shell_escape(cmd), 'cd \$HOME')
コード例 #16
0
ファイル: test_operations.py プロジェクト: itsmeallan/fabric
def test_shell_escape_escapes_backticks():
    """
    _shell_escape() escapes backticks
    """
    cmd = "touch test.pid && kill `cat test.pid`"
    eq_(_shell_escape(cmd), "touch test.pid && kill \`cat test.pid\`")
コード例 #17
0
ファイル: test_operations.py プロジェクト: imankulov/fabric
def test_shell_escape_escapes_backslashes():
    """
    _shell_escape() escapes backslashes
    """
    cmd = r'echo "\""'
    eq_(_shell_escape(cmd), r"echo \"\\\"\"")