Python fabric.api 模块,env() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用fabric.api.env()

项目:fabricio    作者:renskiy    | 项目源码 | 文件源码
def test_pull_image(self):
        cases = dict(
            no_errors=dict(
                side_effect=(SucceededResult(), ),
                expected_pull_error=None,
            ),
            error=dict(
                side_effect=(RuntimeError(), ),
                expected_pull_error=True,
            ),
        )
        for case, test_data in cases.items():
            with self.subTest(case=case):
                service = docker.Service(name='service', image='image')
                with mock.patch.object(
                    fabricio,
                    'run',
                    side_effect=test_data['side_effect']
                ):
                    service.pull_image()
                    self.assertEqual(
                        test_data['expected_pull_error'],
                        service.pull_errors.get(fab.env.host),
                    )
项目:stregsystemet    作者:f-klubben    | 项目源码 | 文件源码
def deploy():
    with cd("/data/stregsystem"):
        sudo("systemctl stop apache2.service")
        with settings(sudo_user='stregsystem'):
            sudo("git pull --ff-only")
            with prefix("source /data/stregsystem/env/bin/activate"):
                sudo("pip install -rrequirements.txt")
                sudo("python manage.py collectstatic --noinput")
                sudo("python manage.py migrate")
        sudo("systemctl start apache2.service")
项目:CommunityCellularManager    作者:facebookincubator    | 项目源码 | 文件源码
def localhost():
    api.env.hosts = ['localhost']
    global RUNCMD
    RUNCMD = api.local
项目:CommunityCellularManager    作者:facebookincubator    | 项目源码 | 文件源码
def package_common_lib():
    RUNCMD("fpm"
           " -s python"      # read from standard Python setup.py
           " --python-pip pip3 --python-bin python3"
           " --python-package-name-prefix python3"
           " -t %(pkgfmt)s"  # set output package format
           " -f"             # overwrite any existing file
           " -p ~/endaga-packages"  # put output in endaga-packages
           " %(fpm_flags)s"  # pass in extra flags
           " ~/common/setup.py" %
           api.env)
项目:astoptool    作者:zouliuyun    | 项目源码 | 文件源码
def add_mobileStaticResources_parser(parser):
    """
    ?????????
    """
    sub_parser = parser.add_parser("mobileStaticResources", help="????????")

    sub_parser.add_argument(
        "-g", 
        "--game", 
        dest="game", 
        required=True, 
        help="game, eg: gcmob"
    )
    sub_parser.add_argument(
        "-l", 
        "--region", 
        dest="language", 
        required=True, 
        help="region, eg: cn, vn, ft"
    )
    sub_parser.add_argument(
        '--env',
        type=str,
        dest='game_env',
        choices=['prod', 'test'],
        help='Production Environment or Test Environment?'
    )
    sub_parser.add_argument(
        '-t',
        type=str,
        dest='component',
        required=True,
        help='component name, eg: activity_post'
    )
    sub_parser.set_defaults(func=main)
项目:fapistrano    作者:liwushuo    | 项目源码 | 文件源码
def _format_target():
    return '{app_name}-{env}'.format(**env)
项目:fabricio    作者:renskiy    | 项目源码 | 文件源码
def test_is_manager_returns_false_if_pull_error(self, *args):
        with mock.patch.object(fabricio, 'run') as run:
            service = docker.Service(name='service')
            service.pull_errors[fab.env.host] = True
            self.assertFalse(service.is_manager())
            run.assert_not_called()
项目:fabricio    作者:renskiy    | 项目源码 | 文件源码
def test_is_manager_raises_error_if_all_pulls_failed(self, *args):
        with mock.patch.object(fabricio, 'run') as run:
            service = docker.Service(name='service')
            service.pull_errors[fab.env.host] = True
            with self.assertRaises(docker.ServiceError):
                service.is_manager()
            run.assert_not_called()
项目:fabricio    作者:renskiy    | 项目源码 | 文件源码
def test_infrastructure(self):
        class AbortException(Exception):
            pass

        def task():
            pass

        cases = dict(
            default=dict(
                decorator=tasks.infrastructure,
                expected_infrastructure='task',
            ),
            invoked=dict(
                decorator=tasks.infrastructure(),
                expected_infrastructure='task',
            ),
            with_custom_name=dict(
                decorator=tasks.infrastructure(name='infrastructure'),
                expected_infrastructure='infrastructure',
            ),
        )

        with fab.settings(abort_on_prompts=True, abort_exception=AbortException):
            with mock.patch.object(fab, 'abort', side_effect=AbortException):
                for case, data in cases.items():
                    with self.subTest(case=case):
                        decorator = data['decorator']
                        infrastructure = decorator(task)

                        self.assertTrue(is_task_object(infrastructure.confirm))
                        self.assertTrue(is_task_object(infrastructure.default))

                        fab.execute(infrastructure.confirm)
                        self.assertEqual(data['expected_infrastructure'], fab.env.infrastructure)

                        fab.env.infrastructure = None
                        with mock.patch.object(console, 'confirm', side_effect=[True, False]):
                            fab.execute(infrastructure.default)
                            self.assertEqual(data['expected_infrastructure'], fab.env.infrastructure)
                            with self.assertRaises(AbortException):
                                fab.execute(infrastructure.default)
项目:geonode-devops    作者:pjdufour    | 项目源码 | 文件源码
def _run_task(task, args=None, kwargs=None):
    from fabfile import targets
    if targets:
        for target in targets:
            env = _build_env(target)
            if env:
                with fab_settings(** env):
                    _run_task_core(task, args, kwargs)
    else:
        _run_task_core(task, args, kwargs)
项目:insmartapps    作者:kantanand    | 项目源码 | 文件源码
def env():
    print('creating env')
    run('virtualenv env')
项目:insmartapps    作者:kantanand    | 项目源码 | 文件源码
def newsetup():
    execute(dependencies)
    execute(install_mysql)
    execute(install_nginx)
    execute(env)
项目:fabricio    作者:renskiy    | 项目源码 | 文件源码
def test_options(self):
        cases = dict(
            default=dict(
                kwargs=dict(),
                expected={},
            ),
            custom=dict(
                kwargs=dict(options=dict(foo='bar')),
                expected={
                    'foo': 'bar',
                },
            ),
            collision=dict(
                kwargs=dict(options=dict(execute='execute')),
                expected={
                    'execute': 'execute',
                },
            ),
            override=dict(
                kwargs=dict(options=dict(env='custom_env')),
                expected={
                    'env': 'custom_env',
                },
            ),
            complex=dict(
                kwargs=dict(options=dict(
                    env='custom_env',
                    user=lambda service: 'user',
                    foo='foo',
                    bar=lambda service: 'bar',
                )),
                expected={
                    'env': 'custom_env',
                    'user': 'user',
                    'foo': 'foo',
                    'bar': 'bar',
                },
            ),
        )
        for case, data in cases.items():
            with self.subTest(case=case):
                container = TestContainer(**data['kwargs'])
                self.assertDictEqual(data['expected'], dict(container.options))