Commits

Vladimir Mihailenco committed 63f3a6d

Support multiple task in conf

  • Participants
  • Parent commits a11fdbe

Comments (0)

Files changed (2)

File fabdeploy/containers.py

 class BaseConf(MutableMapping):
     _attrs = (
         '_name',
-        '_task',
+        '_tasks',
         '_global_conf',
         '_versions',
         '_conf_value',
     def __init__(
         self,
         name=None,
-        task=None,
+        tasks=None,
         global_conf=None,
         versions=['active', 'last', 'previous']):
         self._name = name or 'unknown'
-        self._task = task
+        self._tasks = tasks or []
         self._global_conf = global_conf or self
         self._versions = versions
 
     def set_name(self, name):
         self._name = name
 
-    def set_task(self, task):
-        self._task = task
+    def add_task(self, task):
+        self._tasks.append(task)
 
     def set_global_conf(self, conf):
         self._global_conf = conf
         return value
 
     def _conf_raw_value(self, name):
-        if self._task:
+        for task in self._tasks:
             try:
-                return self._task.conf_value(name)
+                return task.conf_value(name)
             except MissingVarException:
-                pass
+                continue
         try:
             return super(BaseConf, self).__getattribute__(name)
         except AttributeError:
         builtins = set([k for k in dir(BaseConf)])
         keys = [k for k in dir(self)
                 if not k.startswith('_') and k not in builtins]
-        if self._task:
-            keys.extend(self._task.conf_keys())
+        for task in self._tasks:
+            keys.extend(task.conf_keys())
         return keys
 
     def setdefault(self, key, default=None):
     def copy(self):
         d = self.__class__(
             global_conf=self._global_conf,
-            task=self._task,
+            tasks=self._tasks,
             name=self._name)
         d._copy_conf(self)
         return d
     # directory name that contains manage.py file (django project root)
     django_dir = ''
     home_path = conf(lambda self: home_path(self.user))
+    fabdeploy_path = ['%(home_path)s', '.fabdeploy.d']
+    fabdeploy_bin_path = ['%(home_path)s', '.fabdeploy.d', 'bin']
     version_path = ['%(home_path)s', '%(version)s']
     version_data_file = ['%(version_path)s', '.fabdeploy']
     src_path = ['%(version_path)s', 'src']

File fabdeploy/task.py

         assert isinstance(env.conf, BaseConf)
         conf = env.conf.copy()
         conf.set_global_conf(env.conf)
-        conf.set_task(self)
+        conf.add_task(self)
         return conf
 
     @contextmanager
                 assert isinstance(conf, BaseConf)
                 self.conf = conf.copy()
                 self.task_kwargs = task_kwargs
+                self.conf.add_task(self)
             elif self.conf is None:
                 self.conf = self._default_conf()
                 self.task_kwargs = task_kwargs
+
             self.conf.set_name('%s.%s' % (self._get_module(), self.name))
             unprefix_conf(self.conf, self._namespaces(self.task_kwargs))