python类local()的实例源码

runner.py 文件源码 项目:boss 作者: kabirbaidhya 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def run(command, remote=True):
    ''' Run a command using fabric. '''
    if remote:
        return _run(command)
    else:
        return _local(command)
fabfile.py 文件源码 项目:dprr-django 作者: kingsdigitallab 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def localhost():
    """ local server """
    env.srvr = 'local'
    env.path = os.path.dirname(os.path.realpath(__file__))
    env.within_virtualenv = 'workon dprr'
    env.hosts = [gethostname()]
    env.user = getuser()
fabfile.py 文件源码 项目:dprr-django 作者: kingsdigitallab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def collect_static(process=False):
    require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)

    if env.srvr in ['local', 'vagrant']:
        print(yellow('Do not run collect_static on local servers'))
        return

    with cd(env.path), prefix(env.within_virtualenv):
        run('./manage.py collectstatic {process} --noinput'.format(
            process=('--no-post-process' if not process else '')))
fabfile.py 文件源码 项目:dprr-django 作者: kingsdigitallab 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
def own_django_log():
    """ make sure logs/django.log is owned by www-data """

    require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)

    if env.srvr in ['local', 'vagrant']:
        print(yellow('Do not change ownership of django log on local servers'))
        return
    sudo(
        'chown www-data:www-data {}'.format(
            os.path.join(env.path, 'logs', 'django.log')))
zfs.py 文件源码 项目:znappy 作者: eBayClassifiedsGroup 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def zfs_unmount(self, target):
        cmd = '/sbin/zfs unmount {}'.format(target)

        logger.debug('Unmounting {}'.format(target))
        logger.debug('Executing: {}'.format(cmd))

        if local(cmd).return_code != 0:
            raise SnapshotException('Failed to unmount filesystem')
zfs.py 文件源码 项目:znappy 作者: eBayClassifiedsGroup 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def zfs_promote(self, target):
        cmd = '/sbin/zfs promote {target}'.format(target=target)

        logger.debug('Promoting {}'.format(target))
        logger.debug('Executing: {}'.format(cmd))

        if local(cmd).return_code != 0:
            raise SnapshotException('Failed to promote {}'.format(target))
zfs.py 文件源码 项目:znappy 作者: eBayClassifiedsGroup 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def zfs_rename(self, source, target):
        cmd = '/sbin/zfs rename {source} {target}'.format(
            source=source,
            target=target
        )

        logger.debug('Renaming {source} to {target}'.format(source=source, target=target))
        logger.debug('Executing: {}'.format(cmd))

        if local(cmd).return_code != 0:
            raise SnapshotException('Failed to clone snapshot')
zfs.py 文件源码 项目:znappy 作者: eBayClassifiedsGroup 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def zfs_destroy(self, target):
        cmd = '/sbin/zfs destroy -r {target}'.format(target=target)

        logger.debug('Destroying {}'.format(target))
        logger.debug('Executing: {}'.format(cmd))

        if local(cmd).return_code != 0:
            raise SnapshotException('Failed to destroy {}'.format(target))
zfs.py 文件源码 项目:znappy 作者: eBayClassifiedsGroup 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def zfs_snapshot_list(self, target):
        cmd = '/sbin/zfs get -r -H -o value name -t snapshot {target}'.format(target=target)

        logger.debug("Executing {}".format(cmd))
        result = local(cmd, capture=True)

        if result.return_code != 0:
            raise SnapshotException('Failed to list snapshots')

        return result.split('\n')
zfs.py 文件源码 项目:znappy 作者: eBayClassifiedsGroup 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def start_restore(self, *args, **kwargs):
        cmd = local("fuser -k -9 -m /$(zfs get -H -o value mountpoint {})".format(self.filesystem))

        logger.debug(cmd)

        return True, ''
mysql.py 文件源码 项目:znappy 作者: eBayClassifiedsGroup 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def stop_mysql(self):
        with settings(hide('running', 'stdout')):
            result = local('service mysql stop')

        return result.return_code == 0, "stop_mysql"
mysql.py 文件源码 项目:znappy 作者: eBayClassifiedsGroup 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def failover(self, *args, **kwargs):
        cred_file = self.config.get('failover_creds', '/etc/mysql/failover.cnf')
        master = kwargs.get('master_host')
        if not master:
            return False, "No master_host given"

        with settings(hide('running')):
            return local("/usr/bin/mysqlmaster.py switch --new-master {} --defaults-extra-file={} "
                         "--dead-master --assume-yes".format(master, cred_file)).return_code == 0, ""
fabfile.py 文件源码 项目:pyconjp-website 作者: pyconjp 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def ssh():
    """Ssh to a given server"""
    require('environment')
    local("ssh %s" % env.hosts[0])
fabfile.py 文件源码 项目:pyconjp-website 作者: pyconjp 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def make_messages():
    """Extract English text from code and templates, and update the
    .po files for translators to translate"""
    # Make sure gettext is installed
    local("gettext --help >/dev/null 2>&1")
    if os.path.exists("locale/fr/LC_MESSAGES/django.po"):
        local("python manage.py makemessages -a")
    else:
        local("python manage.py makemessages -l fr")
fabfile.py 文件源码 项目:pyconjp-website 作者: pyconjp 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def compile_messages():
    """Compile the translated .po files into more efficient .mo
        files for runtime use"""
    # Make sure gettext is installed
    local("gettext --help >/dev/null 2>&1")
    local("python manage.py compilemessages")
fabfile.py 文件源码 项目:rq-scheduler-dashboard 作者: lamflam 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def todo(*args):
    """List the TODOs and FIXMEs in the code and documentation."""
    with lcd(_relative_to_fabfile()):
        local(
            'grin -e ".pyc,.pyo" "FIXME|TODO" *')
        local(
            'grind -0 \'*.feature\' | '
            'grin -I \'*.feature\' -0 -f - "FIXME|TODO"')
fabfile.py 文件源码 项目:rq-scheduler-dashboard 作者: lamflam 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def isort():
    """Use isort to automatically (re-)order the import statements on the top of files"""
    with lcd(_relative_to_fabfile()):
        local('isort **/*.py')
fabfile.py 文件源码 项目:rq-scheduler-dashboard 作者: lamflam 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def clean():
    """Remove all generated files (.pyc, .coverage, .egg, etc)."""
    with lcd(_relative_to_fabfile()):
        local('find -name "*.pyc" | xargs rm -f')
        local('find -name .coverage | xargs rm -f')
        local('find -name .DS_Store | xargs rm -f')  # Created by OSX
        local('find -name ._DS_Store | xargs rm -f') # Created by OSX
        local('find -name "._*.*" | xargs rm -f')    # E.g. created by Caret
        local('rm -f .coverage.*')
        local('rm -rf build')
        local('rm -rf dist')


问题


面经


文章

微信
公众号

扫码关注公众号