示例#1
0
    def test_infrastructure(self):
        class AbortException(Exception):
            pass

        def task():
            return 'result'

        with fab.settings(abort_on_prompts=True, abort_exception=AbortException):
            self.assertTrue(is_task_object(infrastructure(task)))
            self.assertTrue(is_task_object(infrastructure()(task)))
            self.assertIsNone(fab.env.infrastructure)

            with self.assertRaises(AbortException):
                fab.execute(infrastructure(task))

            environ_backup = os.environ.copy()
            try:
                os.environ.pop('FABRICIO_INFRASTRUCTURE_AUTOCONFIRM', None)
                with self.assertRaises(AbortException):
                    fab.execute(infrastructure(task))

                for env in ('yes', 'true', '1', 'YES', 'True'):
                    os.environ['FABRICIO_INFRASTRUCTURE_AUTOCONFIRM'] = env
                    self.assertDictEqual({'<local-only>': 'result'}, fab.execute(infrastructure(task)))

                self.assertEqual('task', fab.env.infrastructure)

                for env in ('no', 'false', '0', 'NO', 'False'):
                    os.environ['FABRICIO_INFRASTRUCTURE_AUTOCONFIRM'] = env
                    with self.assertRaises(AbortException):
                        fab.execute(infrastructure(task))

                infrastructure(task)
                self.assertIsNotNone(fab.env.infrastructure)

                os.environ['CUSTOM_ENV'] = '1'
                self.assertDictEqual(
                    {'<local-only>': 'result'},
                    fab.execute(infrastructure(autoconfirm_env_var='CUSTOM_ENV')(task)),
                )
            finally:
                os.environ = environ_backup

            with mock.patch.object(console, 'confirm', side_effect=(True, False)):
                self.assertDictEqual({'<local-only>': 'result'}, fab.execute(infrastructure(task)))
                with self.assertRaises(AbortException):
                    fab.execute(infrastructure(task))

            self.assertDictEqual({'<local-only>': 'result'}, fab.execute(infrastructure(confirm=False)(task)))
示例#2
0
 def __new__(cls, *args, **kwargs):
     self = super(Tasks, cls).__new__(cls)
     for attr in dir(cls):
         attr_value = getattr(cls, attr)
         if is_task_object(attr_value):
             task_decorator = fab.task(
                 default=attr_value.is_default,
                 name=attr_value.name,
                 aliases=attr_value.aliases,
                 task_class=attr_value.__class__,
             )
             bounded_task = functools.partial(attr_value.wrapped, self)
             task = task_decorator(
                 functools.wraps(attr_value)(bounded_task))
             for wrapped_attr in [
                     'parallel',
                     'serial',
                     'pool_size',
                     'hosts',
                     'roles',
             ]:
                 if hasattr(attr_value.wrapped, wrapped_attr):
                     setattr(
                         task.wrapped,
                         wrapped_attr,
                         getattr(attr_value.wrapped, wrapped_attr),
                     )
             setattr(self, attr, task)
     return self
示例#3
0
 def __new__(cls, *args, **kwargs):
     self = super(Tasks, cls).__new__(cls)
     for attr in dir(cls):
         obj = getattr(self, attr, None)
         if is_task_object(obj):
             setattr(self, attr, obj)
     return self
示例#4
0
文件: tasks.py 项目: renskiy/fabricio
 def __new__(cls, *args, **kwargs):
     self = super(Tasks, cls).__new__(cls)
     for attr in dir(cls):
         obj = getattr(self, attr, None)
         if is_task_object(obj):
             setattr(self, attr, obj)
     return self
示例#5
0
 def __new__(cls, **kwargs):
     self = object.__new__(cls)
     _self = weakref.proxy(self)
     for attr in dir(cls):
         attr_value = getattr(cls, attr)
         if is_task_object(attr_value):
             task_decorator = fab.task(
                 default=attr_value.is_default,
                 name=attr_value.name,
                 aliases=attr_value.aliases,
                 task_class=attr_value.__class__,
             )
             task = task_decorator(functools.wraps(attr_value.wrapped)(
                 # TODO fix Fabric's --display option
                 functools.partial(attr_value.wrapped, _self),
             ))
             setattr(self, attr, task)
     return self
示例#6
0
 def __iter__(self):
     for name, attr_value in vars(self).items():
         if is_task_object(attr_value):
             yield attr_value
示例#7
0
 def __iter__(self):
     for obj in vars(self).values():
         if is_task_object(obj):
             yield obj
示例#8
0
 def __iter__(self):
     for name, attr_value in vars(self).items():
         if is_task_object(attr_value):
             yield attr_value
示例#9
0
文件: tasks.py 项目: renskiy/fabricio
 def __iter__(self):
     for obj in vars(self).values():
         if is_task_object(obj):
             yield obj