Commits

Benoit C  committed b3307ed

simple function re-order / re-naming

  • Participants
  • Parent commits 1a01758

Comments (0)

Files changed (1)

File src/fabfile.py

 import yaml
 
 
+def load_yaml(env_type):
+    # sure we can do more there
+    env.yaml = yaml.load(file("conf.yaml").read()).get(env_type)
+
+def preprod():
+    load_yaml('preprod')
+    env.project_name = env.yaml.get('project').get('name')
+    env.type = 'preprod'
+    env.hosts = env.yaml.get('hosts').get('web')
+    env.user = env.yaml.get('project').get('sudo_user')
+    env.path = env.yaml.get('project').get('root_dir')
+    env.virtualhost_path = env.path
+
+def prod():
+    print "updating for %s => preprod" % env.project_name
+    load_yaml('prod')
+    env.type = 'prod'
+
+    env.hosts = env.yaml.get('hosts').get('web')
+    env.user = env.yaml.get('project').get('user')
+    env.path = '/home/%(user)s/django/%(project_name)s' % env
+    env.virtualhost_path = env.path
+
+
 @Permssions("sudo_user", env)
 @ConfChecker("wsgi", env)
 def wsgi_restart():
-    conf = env.yaml.get("gunicorn")
+    conf = env.yaml.get("wsgi")
     django = env.yaml.get("django")
     if exists(conf.get('pidfile')):
         if isinstance(conf.get('port'), list):
                     (conf.get('path'), conf.get('workers'),
                      conf.get('port'), conf.get('pid'), conf.get('logfile')))
 
-
+@Permssions("sudo_user", env)
+@ConfChecker("httpd", env)
 def install_httpd_vhost():
     print "installing nginx vhost for %s" % env.project_name
     with cd(env.path):
-        conf = env.yaml.get("nginx")
+        conf = env.yaml.get("httpd")
         fname = "%s/deploy/vhost-%s-%s" % (env.path, 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))
         sudo("ln -sFf %s/%s %s" % (conf.get("av"), env.project_name, conf.get("en")))
 
-def preprod():
-    load_yaml('preprod')
-    env.project_name = env.yaml.get('project').get('name')
-    env.type = 'preprod'
-    env.hosts = env.yaml.get('hosts').get('web')
-    env.user = env.yaml.get('project').get('sudo_user')
-    env.path = '/home/%(user)s/preprod/%(project_name)s' % env
-    env.virtualhost_path = env.path
 
-def prod():
-    print "updating for %s => preprod" % env.project_name
-    load_yaml('prod')
-    env.type = 'prod'
-
-    env.hosts = env.yaml.get('hosts').get('web')
-    env.user = env.yaml.get('project').get('user')
-    env.path = '/home/%(user)s/django/%(project_name)s' % env
-    env.virtualhost_path = env.path
 
 @Permssions("normal_user", env)
 @ConfChecker("django", env)
 @Permssions("normal_user", env)
 @ConfChecker("hg", env)
 def update_hg():
-    if remote_path_exist(env.path):
+    conf = env.yaml.get('hg')
+    if exists(conf.get('dest')):
         with cd(env.path):
             run("hg pull -u")
             run("hg update -C")
     else:
         conf = env.yaml.get("hg")
         run("mkdir -p %s" % os.path.dirname(env.path))
-        run("hg clone http://%s:%s@%s/%s %s" % \
-                (conf.get('user'), conf.get('pw'), conf.get('url'),
-                 conf.get('repos'), env.path))
+        run("hg clone http://%(user)s:%(pw)s@%(url)s/%(repos)s %(dest)s" % conf)
 
 @Permssions("normal_user", env)
-@ConfChecker("hg", env)
+@ConfChecker("virtualenv", env)
 def virtualenv():
-    if not exists(env.path + "/sandbox/"):
-        with cd(env.path):
-            run("virtualenv sandbox")
-            run("sandbox/bin/easy_install pip")
-    with cd(env.path):
-        run("sandbox/bin/pip install -r deploy/requirements.txt")
+    conf = env.yaml.get('virtualenv')
+    deploy_dir = env.path + "/" + env.project_name + "/deploy"
+    if not exists(conf.get('dir')):
+        run("virtualenv %(dir)s" % conf)
+        run("%(bin_dir)s/easy_install pip" % conf)
+        
+    
+    run("%s/pip install -r %s/requirements.txt" % (conf.get('bin_dir'), deploy_dir))
 
-@Permssions("sudo_user", env)
+@Permssions("normal_user", env)
 @ConfChecker("database", env)
 def update_database():
     conf = env.yaml.get("database")
+    
     #first, create a local change in the database with south
     #apply the change
 
+@Permissions("normal_user", env)
+@ConfChecker("dataabse", env)
+def install_database():
+    conf = env.yaml.get("database")
 
 @Permssions("sudo_user", env)
 @ConfChecker("services", env)
         sudo("/etc/init.d/%s restart" % service)
     print services
 
-    
-def load_yaml(env_type):
-    # sure we can do more there
-    env.yaml = yaml.load(file("conf.yaml").read()).get(env_type)
 
 @Permssions("sudo_user", env)
 @ConfChecker("distro", env)
 
 def install():
     """for the first install onto the machines"""
-    # install required 
+    # install required packages 
+    distro_install()
+
+    # update the hg repos
+    update_hg()
     
-    # update te hg repos
+    # install the vhost required for the django application
+    install_httpd_vhost()
     
-    # install_httpd_vhost
+    # update the database schema
+    update_database()
+    
     
     # install django configuration