Esempio n. 1
0
def run(cmd):
    """fabric执行远程命令"""
    logger.debug("cmd: %s\n", cmd)
    if ENV_USER != "root":
        sudo(cmd)
    else:
        _run(cmd)
Esempio n. 2
0
def run(cmd, capture=True, remote_only=False, **kwargs):
    capture = parse_bool(capture)

    try:
        if dconf.HOST_CONN == 'remote':
            res = _run(cmd, **kwargs)
        elif dconf.HOST_CONN == 'local':
            res = local(cmd, capture=capture, **kwargs)
        else:  # docker or remote_docker
            opts = ''
            cmdd = cmd
            if cmd.endswith('&'):
                cmdd = cmd[:-1].strip()
                opts = '-d '
            if remote_only:
                docker_cmd = cmdd
            else:
                docker_cmd = 'docker exec {} -ti {} /bin/bash -c "{}"'.format(
                    opts, dconf.CONTAINER_NAME, cmdd)
            if dconf.HOST_CONN == 'docker':
                res = local(docker_cmd, capture=capture, **kwargs)
            elif dconf.HOST_CONN == 'remote_docker':
                res = _run(docker_cmd, **kwargs)
            else:
                raise Exception('wrong HOST_CONN type {}'.format(
                    dconf.HOST_CONN))
    except TypeError as e:
        err = str(e).strip()
        if 'unexpected keyword argument' in err:
            offender = err.rsplit(' ', 1)[-1][1:-1]
            kwargs.pop(offender)
            res = run(cmd, **kwargs)
        else:
            raise e
    return res
Esempio n. 3
0
def run(cmd):
    """fabric执行远程命令"""
    logger.debug("cmd: %s\n", cmd)
    if ENV_USER != "root":
        sudo(cmd)
    else:
        _run(cmd)
Esempio n. 4
0
def host_print(msg, remote=True, leading_chars='\n'):
    ''' Print a raw message on the host. '''
    cmd = 'echo "{0}{1}"'.format(leading_chars, msg)

    with hide('running'):
        if remote:
            _run(cmd)
        else:
            _local(cmd)
Esempio n. 5
0
def logs():
    ''' Tail the logs. '''
    stage = shell.get_stage()
    stage_specific_logging = get_stage_config(stage).get('logging')
    logging_config = stage_specific_logging or get_config().get('logging')

    # If log files are configured tail them.
    if logging_config and logging_config.get('files'):
        # Tail the logs from log files
        log_paths = ' '.join(logging_config.get('files'))
        _run('tail -f ' + log_paths)
        return

    # If logs script is defined, run it
    runner.run_script_safely(constants.SCRIPT_LOGS)
Esempio n. 6
0
def run(*args, **kwargs):
#    if env.is_local:
#        kwargs['capture'] = True
#        if env.dryrun:
#            print args, kwargs
#        else:
#            print args, kwargs
#            cmd = ' '.join(args)
#            #cmd = ' '.join(args + ('2>&1',))
#            try:
#                output = StringIO()
#                error = StringIO()
#                sys.stdout = output
#                sys.stderr = error
#                result = local(cmd, **kwargs)
#            except:
#                raise
#            finally:
#                sys.stdout = sys.__stdout__
#                sys.stderr = sys.__stderr__
#                print 'stdout:',output.getvalue()
#                print 'stderr:',error.getvalue()
##            print 'result:',result
##            print 'stdout:',result.stdout
##            print 'stderr:',result.stderr
#            print 
#            return result
    if env.dryrun:
        print ' '.join(map(str, args)), kwargs
    else:
        return _run(*args, **kwargs)
Esempio n. 7
0
def run(command, show=True):
    """ Runs a shell command on the remote server. """
    if show:
        print_command(command)

    with hide("running"):
        return _run(command)
Esempio n. 8
0
def run(command, show=True, *args, **kwargs):
    """
    Runs a shell comand on the remote server.
    """
    if show:
        print_command(command)
    with hide("running"):
        return _run(command, *args, **kwargs)
Esempio n. 9
0
def run(command, show=True):
    """ Runs a shell command on the remote server. """
    if show:
        print_command(command)

    with hide("running"):
        if env.deploy_user:
            return _sudo(command, user=env.deploy_user)
        return _run(command)
Esempio n. 10
0
def run(command, show=True):
    """ Runs a shell command on the remote server. """
    if show:
        print_command(command)

    with hide("running"):
        if env.deploy_user:
            return _sudo(command, user=env.deploy_user)
        return _run(command)
Esempio n. 11
0
def run(command, quiet=False, show=True):
    """ Runs a shell command on the remote server. """
    if show:
        print_command(command)

    with hide("running"):
        if 'deploy_user' in env:
            # If a deploy_user is specified, run as that user
            return _sudo(command, quiet=quiet, user=env.deploy_user)
        return _run(command, quiet=quiet)
Esempio n. 12
0
def sudo(command, show=True):
    """
    Runs a command as sudo.
    """
    if show:
        print_command(command)
    with hide("running"):
        #return _sudo(command)
        # deployment user doesn't have root in our setup
        return _run(command)
Esempio n. 13
0
def run(command, show=True, args=("running",), quiet=False, shell=True):
    """Runs a shell comand on the remote server."""

    if show:
        print_command(command)
    else:
        args += ('stdout',)

    with hide(*args):
        return _run(command, quiet=quiet, shell=True)
Esempio n. 14
0
def pull():
    with prefix('pyenv shell drf3'), cd(env.remote_dir):
        _run('git pull')
        _run('pip install -r requirements.txt')

    migrate()

    _run('/usr/bin/supervisorctl reØ browser')
Esempio n. 15
0
def virtualenv_exists(virtualenv_dir=None):

    render_paths()

    #base_dir = os.path.split(env.pip_virtual_env_dir)[0]
    base_dir = virtualenv_dir or env.pip_virtual_env_dir

    ret = True
    with settings(warn_only=True):
        ret = _run('ls %s' % base_dir) or ''
        ret = 'cannot access' not in ret.strip().lower()

    if common.get_verbose():
        if ret:
            print('Yes')
        else:
            print('No')

    return ret
Esempio n. 16
0
def venv():
    with prefix('source /usr/local/bin/virtualenvwrapper.sh'):
        _run('mkvirtualenv browser')

    with prefix('pyenv shell drf3'), cd(env.remote_dir):
        _run('pip install -r requirements_dev.txt')
Esempio n. 17
0
def restart():
    with prefix('pyenv shell drf3'), cd(env.remote_dir):
        _run('/usr/bin/supervisorctl restart browser')
Esempio n. 18
0
def migrate():
    with prefix('pyenv shell drf3'), cd(env.remote_dir):
        _run('''DJANGO_SETTINGS_MODULE='config.settings.local' python manage.py migrate''')
Esempio n. 19
0
def test():
    ''' The npm test command. '''
    _run('npm test')
Esempio n. 20
0
def has_virtualenv():
    with settings(warn_only=True):
        ret = _run('which virtualenv').strip()
        return bool(ret)
Esempio n. 21
0
def install():
    ''' The npm install command. '''
    _run('npm install')
Esempio n. 22
0
def start():
    ''' The npm start command. '''
    _run('npm start')
Esempio n. 23
0
def run(command, capture=False, shell=True, pty=True):
    if _is_local(env.host):
        return _local(command % (env), capture=capture)
    else:
        return _run(command % (env), shell=shell, pty=pty)
Esempio n. 24
0
def run(command, show=True):
    with hide("running"):
        return _run(command)
Esempio n. 25
0
def run(script):
    ''' Run an npm script defined in the package.json file. '''
    _run('npm run %s' % script)
Esempio n. 26
0
def run(command, show=True):
    with hide("running"):
        return _run(command)
Esempio n. 27
0
def run(command, remote=True):
    ''' Run a command using fabric. '''
    if remote:
        return _run(command)
    else:
        return _local(command)
Esempio n. 28
0
def run(command):
    return _run(command)
Esempio n. 29
0
def prune():
    ''' The npm prune command. '''
    _run('npm prune')
Esempio n. 30
0
def build():
    ''' The npm build command. '''
    _run('npm run build')
Esempio n. 31
0
def has_pip():
    with settings(warn_only=True):
        ret = _run('which pip').strip()
        return bool(ret)
Esempio n. 32
0
def run(*args, **kwargs):
    if not env.sudo_forced:
        return _run(*args, **kwargs)

    return sudo(*args, **kwargs)
Esempio n. 33
0
def run(*args, **kwargs):
    if not env.sudo_forced:
        return _run(*args, **kwargs)

    return sudo(*args, **kwargs)