Commits

Benoit C committed bb01180

docstrings, typos exceptions, tasks virtualenv django_settings update_hg

Comments (0)

Files changed (2)

     généralement, il me suffit de faire:
     fab {pre,}prod install
 
-
     todo: 
         - ajouter south
 """
     env.yaml = yaml.load(file(conf).read()).get(env_type)
 
 def preprod(conf="conf.yaml"):
+    """Preprod tasks"""
     load_yaml('preprod', conf)
     env.project_name = env.yaml.get('project').get('name')
     env.type = 'preprod'
     env.virtualhost_path = env.path
 
 def prod(conf="conf.yaml"):
+    """Prod tasks"""
     load_yaml('prod', conf)
     env.type = 'prod'
 
 @Permissions("sudo_user", env)
 @ConfChecker("wsgi", env)
 def wsgi_restart():
+    """Restarts the wsgi process"""
     conf = env.yaml.get("wsgi")
     django = env.yaml.get("django")
     if exists(conf.get('pidfile')):
                 run("kill -0 `cat %s`" % pidfile)
                 run("kill -HUP `head -1 %s`" % pidfile)
         return
-
-    with cd("%s/src/inventeev" % env.path):
+    with cd("%(src_dir)s" % django):
         if isinstance(conf.get('port'), list):
             for port in conf.get('port'):
                 run("%s/gunicorn_django --workers=%d --port=%d --pid=%s --log-file=%s -D" % \
 @Permissions("sudo_user", env)
 @ConfChecker("httpd", env)
 def install_httpd_vhost():
+    """Install the vhost for your favorite httpd"""
     with cd(env.path):
         conf = env.yaml.get("httpd")
         fname = "%s/deploy/vhost-%s-%s" % (env.path, env.type, env.project_name)
 @Permissions("normal_user", env)
 @ConfChecker("django", env)
 def django_settings():
+    """Copies your django settings"""
     conf = env.yaml.get('django')
-    with cd(env.path):
-        run("cp deploy/%s-settings.py %s/settings.py" % (env.type, conf.get('src_dir')))
-        sed("%s/settings.py" % conf.get('src_dir'), "DOCUMENT_ROOT", "%s" % env.path)
+    with cd("%(doc_root)s" % conf):
+        run("cp deploy/%s-settings.py %s/settings_local.py" % (env.type, conf.get('src_dir')))
+        sed("%s/settings_local.py" % conf.get('src_dir'), "DOCUMENT_ROOT", "%s" % env.path)
 
 
 @Permissions("normal_user", env)
 @ConfChecker("hg", env)
 def update_hg():
+    """update your sources"""
     conf = env.yaml.get('hg')
+    proj = env.yaml.get('project')
     if exists(conf.get('dest')):
-        with cd(env.path):
+        with cd(conf.get('dest')):
             run("hg pull -u")
             run("hg update -C")
     else:
 @Permissions("normal_user", env)
 @ConfChecker("virtualenv", env)
 def virtualenv():
+    """Create or update your virtualenv"""
     conf = env.yaml.get('virtualenv')
     deploy_dir = env.path + "/" + env.project_name + "/deploy"
     if not exists(conf.get('dir')):
-        run("virtualenv %(dir)s" % conf)
+        ret = run("virtualenv %(dir)s" % conf)
+        print ret
         run("%(bin_dir)s/easy_install pip" % conf)
-        
-    
+
     run("%s/pip install -r %s/requirements.txt" % (conf.get('bin_dir'), deploy_dir))
 
 @Permissions("normal_user", env)
 @ConfChecker("database", env)
 def backup_database():
+    """Backups your mysql database"""
     conf = env.yaml.get("database")
     date = datetime.datetime.now()
-    
+
     conf['backup_fname'] = "%s/backup-%s-%d-%d-%d-%s.sql" % \
         (conf.get('backup'), conf.get('db'), date.day, date.month, date.year, time.time())
     run("mkdir -p %(backup)s" % conf)
     run("""mysqldump --host=%(host)s --user=%(user)s --password=%(pw)s %(db)s > %(backup_fname)s""" % conf)
 
-        
+
 @Permissions("normal_user", env)
 @ConfChecker("database", env)
 def update_database():
+    """Updates your database schema"""
     # first backup the database
     backup_database()
-    
+
     conf = env.yaml.get("database")
     django = env.yaml.get("django")
     venv = env.yaml.get("virtualenv")
-    
+
     with cd(django.get("src_dir")):
         run("%(bin_dir)s/python manage.py migrate --all" % venv)
         pass
 
-    
     #first, create a local change in the database with south
     #apply the change
 
 @Permissions("normal_user", env)
 @ConfChecker("dataabse", env)
 def install_database():
+    """Install your database schema"""
     conf = env.yaml.get("database")
     django = env.yaml.get("django")
 
 @Permissions("sudo_user", env)
 @ConfChecker("services", env)
 def services_reload():
+    """Reloads your services"""
     services = env.yaml.get('services').get('reload')
     for service in services:
         sudo("/etc/init.d/%s reload" % service)
 @Permissions("sudo_user", env)
 @ConfChecker("services", env)
 def services_restart():
+    """Restarts your services"""
     services = env.yaml.get('services').get('restart')
     for service in services:
         sudo("/etc/init.d/%s restart" % service)
 @Permissions("sudo_user", env)
 @ConfChecker("distro", env)
 def distro_install():
+    """Installs required packages"""
     # install packages specified in the yaml conf
     dist_conf = env.yaml.get('distro')
     if dist_conf.get('name') in ('ubuntu', 'debian'):
         for package in dist_conf.get('packages'):
-            sudo("apt-get install %s" % packages)
-    
+            sudo("apt-get install %s" % package)
+
 
 def install():
     """for the first install onto the machines"""
 
     # update the hg repos
     update_hg()
-    
+
     # install the vhost required for the django application
     install_httpd_vhost()
-    
+
     # update the database schema
     update_database()
-    
-    
+
+
     # install django configuration
-    
+
     # start/restart the wsgi/fcgi process
-    
+
     # restart other services
 
 

src/fabulator/decorators.py

 """
 import traceback
 
-from fabulator.exeptions import ImproperlyConfigured
+from fabulator.exceptions import ImproperlyConfigured
 
 # how it sux !
 class Decorate(object):
     def __init__(self):
         pass
-        
+
     def __call__(self, func):
         pass
 
 
 class Permissions(Decorate):
+    """decorators which sets the env.user for the task"""
     def __init__(self, username, env):
         self.username = username
         self.env = env
-        
+
     def __call__(self, func):
         def _wrapper(*args, **kwargs):
             try:
         return _wrapper
 
 class ConfChecker(Decorate):
+    """decorators which checks if the configuration exists in env.yaml"""
     def __init__(self, conf, env):
         self.conf = conf
         self.env = env
-    
+
     def __call__(self, func):
         def _wrapper(*args, **kwargs):
             conf = self.env.yaml