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)))
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
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
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
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
def __iter__(self): for name, attr_value in vars(self).items(): if is_task_object(attr_value): yield attr_value
def __iter__(self): for obj in vars(self).values(): if is_task_object(obj): yield obj
def __iter__(self): for name, attr_value in vars(self).items(): if is_task_object(attr_value): yield attr_value
def __iter__(self): for obj in vars(self).values(): if is_task_object(obj): yield obj