Source

fabulator / src / fabfile.py

Diff from to

src/fabfile.py

 from fabric.api import *
 from fabric.contrib.files import exists, sed
 from fabulator.decorators import Permissions, ConfChecker
+from fabulator.core import mysql, south
+
 
 import yaml
 import time
                 run("kill -0 `cat %s`" % pidfile)
                 run("kill -HUP `head -1 %s`" % pidfile)
             else:
-                run("%s/gunicorn_django --workers=%d --port=%d --pid=%s --log-file=%s -D" % \
-                        (conf.get('path'), conf.get('workers'),
-                         port, pidfile, conf.get('logfile')))
+                with cd(django.get('src_dir')):
+                    run("%s/gunicorn_django --workers=%d --port=%d --pid=%s --log-file=%s -D" % \
+                            (conf.get('path'), conf.get('workers'),
+                             port, pidfile, conf.get('logfile')))
 
 @Permissions("sudo_user", env)
 @ConfChecker("httpd", env)
 def install_httpd_vhost():
     """Install the vhost for your favorite httpd"""
-    with cd(env.path):
+    proj = env.yaml.get('project')
+    with cd(proj.get('doc_root')):
         conf = env.yaml.get("httpd")
-        fname = "%s/deploy/vhost-%s-%s" % (env.path, env.type, env.project_name)
+        fname = "%s/deploy/vhost-%s-%s" % (proj.get('doc_root'), env.type, env.project_name)
         run("mkdir -p %s/logs/" % env.path)
         sed(fname, "DOCUMENT_ROOT", "%s" % env.path)
         sudo("cp %s %s/%s" % (fname, conf.get("av"), env.project_name))
     deploy_dir = env.path + "/" + env.project_name + "/deploy"
     if not exists(conf.get('dir')):
         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"""
+    """Updates your database schema using south"""
+    conf = env.yaml.get("database")
     # first backup the database
-    #backup_database()
+    mysql.backup_database(conf)
+    return
 
     conf = env.yaml.get("database")
     django = env.yaml.get("django")
     #first, create a local change in the database with south
     #apply the change
 
-@Permissions("normal_user", env)
-@ConfChecker("django", env)
-def install_south():
-    """Install the required tables and initialize south"""
-    django = env.yaml.get("django")
-    venv = env.yaml.get("virtualenv")
-    with cd("%(src_dir)s" % django):
-        run("%(bin_dir)s/python manage.py syncdb" % venv)
-        for app in django.get('apps'):
-            venv["app"] = app
-            run("%(bin_dir)s/python manage.py convert_to_south %(app)s" % venv)
-            del venv["app"]
 
 @Permissions("normal_user", env)
 @ConfChecker("database", env)
     conf = env.yaml.get("database")
     django = env.yaml.get("django")
     venv = env.yaml.get("virtualenv")
-    install_south()
+    
+    mysql.create_database(conf)
+    south.install_south(env)
+    
     with cd("%(src_dir)s" % django):
         run("%(bin_dir)s/python manage.py migrate --all" % venv)
 
     """updates the code and everything else"""
     distro_install()
 
-    update_hg
+    update_hg()
+    
+    virtualenv()
 
-    install_httpd_vhost()
+    #install_httpd_vhost()
+
+    # install django configuration
+    django_settings()
 
     update_database()
-    # install django configuration
-    django_settings()
+    return
+
 
     # start/restart the wsgi/fcgi process
     wsgi_restart()
 
     # update the hg repos
     update_hg()
+    
+    # install or update the virtualenv
+    virtualenv()
 
     # install the vhost required for the django application
     install_httpd_vhost()
 
+
+    # install django configuration
+    django_settings()
+    
     # install the database schema
     install_database()
 
-    # install django configuration
-    django_settings()
+
 
     # start/restart the wsgi/fcgi process
     wsgi_restart()