Vladimir Mihailenco avatar Vladimir Mihailenco committed 454dbbf

MultiSourceDict will prompt for input if config variable is missing

Comments (0)

Files changed (3)

-from fabdeploy.base import setup_conf
+from fabdeploy import fabd, system, git, virtualenv, nginx, django, pip, \
+    postgres, supervisor, users, ssh, tar, gunicorn, uwsgi
+from fabdeploy.base import setup_fabdeploy, setup_conf
 from fabdeploy.containers import conf
 from fabdeploy.task import Task


 from fabric import network
 from fabric.state import _AttributeDict
+from fabdeploy.containers import MultiSourceDict
 from fabdeploy.utils import get_home_dir
 logger = logging.getLogger('fabdeploy')
+def setup_fabdeploy():
+    if not hasattr(env, 'conf'):
+        env.conf = MultiSourceDict()
+    if not env.hosts:
+        env.hosts = ['%s@localhost' % os.environ['USER']]
 def get_config_template_path(name):
     for dir in env.conf.config_templates_pathes:
         path = os.path.join(dir, name)


+import copy
+from fabric.api import prompt
 import inspect
 from collections import MutableMapping
 class MultiSourceDict(MutableMapping):
-    def __init__(self, data, obj=None):
-        self.data = data
+    def __init__(self, data=None, obj=None):
+        if data:
+            self.data = data
+        else:
+            self.data = {}
         self.obj = obj
         self.obj_conf_keys = set()
             if hasattr(value, '_is_conf'):
-        self.conf_keys = set(self.data.keys())
-        self.conf_keys.update(self.obj_conf_keys)
     def get_value(self, name):
         if name in self.obj_conf_keys:
             # delete to avoid recursion
             r = getattr(self.obj, name)()
             return r
-        if name in self.data:
-            return self.data[name]
-        raise MissingVarException()
+        if name not in self.data:
+            if name.startswith('_'):
+                raise MissingVarException()
+            self.data[name] = prompt('%s = ' % name)
+        return self.data[name]
     def set_value(self, name, value):
         self.data[name] = value
+    def get_keys(self):
+        keys = self.obj_conf_keys.copy()
+        keys.update(self.data.keys())
+        return keys
     def __setitem__(self, key, value):
         self.set_value(key, value)
         raise NotImplementedError()
     def __iter__(self):
-        return iter(self.conf_keys)
+        return iter(self.get_keys())
     def __len__(self):
-        return len(self.conf_keys)
+        return len(self.get_keys())
     def __getattr__(self, name):
             raise AttributeError(name)
     def __setattr__(self, name, value):
-        if name in ['data', 'obj', 'obj_conf_keys', 'conf_keys']:
+        if name in ['data', 'obj', 'obj_conf_keys']:
             self.__dict__[name] = value
             self.set_value(name, value)
+    def copy(self):
+        return copy.deepcopy(self)
 def conf(func):
     func._is_conf = True
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.