Commits

Benoit C committed 4c9f866

adding operating system management

Comments (0)

Files changed (5)

 from fabulator.core.db import database_factory
 from fabulator.core.vc import vc_factory
 from fabulator.core.http import http_factory
-
+from fabulator.core.system import os_factory
 from fabulator.core.virtualenv import VirtualEnv
 
 import yaml
         env.httpd = http_factory(conf["httpd"].get("type"), conf.get("httpd"), env)
     if "virtualenv" in conf:
         env.virtualenv = VirtualEnv(conf.get("virtualenv"), env)
+    if "os" in conf:
+        
+        env.os = os_factory(conf["os"].get("type"), conf.get("os"), env)
+    else:
+        print "fu"
 
 def preprod(conf="conf.yaml"):
     """Preprod tasks"""
     build(env.yaml)
 
 
-@Permissions("normal_user", env)
-@ConfChecker("httpd", env)
-def install_httpd_vhost():
-    """Install the vhost for your favorite httpd"""
-    proj = env.yaml.get('project')
-    with cd(proj.get('doc_root')):
-        conf = env.yaml.get("httpd")
-        fname = "%s/deploy/vhost-%s-%s" % (proj.get('doc_root'), env.type, env.project_name)
-#        if not exists(env.path + "/logs"):
-#            run("mkdir -p %s/logs/" % env.path)
-        sed(fname, "DOCUMENT_ROOT", "%s" % env.path)
-        sed(fname, "PROJECT_NAME", "%s" % proj.get('name'))
-        copy_vhost()
-
-@Permissions("sudo_user", env)
-@ConfChecker("httpd", env)
-def copy_vhost():
-    proj = env.yaml.get('project')
-    conf = env.yaml.get("httpd")
-    fname = "%s/deploy/vhost-%s-%s" % (proj.get('doc_root'), env.type, env.project_name)
-    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")))
-
-
-@Permissions("normal_user", env)
-@ConfChecker("django", env)
-def django_settings():
-    """Copies your django settings"""
-    conf = env.yaml.get('django')
-    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" % conf.get('src_dir'))
-
-
-
-@Permissions("normal_user", env)
-@ConfChecker("database", env)
-def update_database():
-    """Updates your database schema using south"""
-    conf = env.yaml.get("database")
-    # first backup the database
-    mysql.backup_database(conf)
-    return
-
-    conf = env.yaml.get("database")
-    django = env.yaml.get("django")
-    venv = env.yaml.get("virtualenv")
-    date = datetime.datetime.now()
-
-    with cd(django.get("src_dir")):
-        for app in django.get('apps'):
-            venv["app"] = app
-            run("%(bin_dir)s/python manage.py startmigration %(app)s automigration --auto" % venv)
-            del venv["app"]
-
-        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("sudo_user", env)
 @ConfChecker("services", env)
 def services_reload():
 def install():
     """for the first install onto the machines"""
 
+    print env.os
     print env.httpd
     print env.db
     print env.vc
     
+    env.os.install_packages()
     env.vc.clone_repository()
     env.virtualenv.create_virtualenv()
     env.virtualenv.install_requirements(False)

src/fabulator/core/system/__init__.py

+from debian import Debian
+
+
+oses = {
+    "debian" : Debian,
+}
+
+def os_factory(os, conf, env):
+    return oses[os.lower()](conf, env)

src/fabulator/core/system/base.py

+"""
+
+"""
+
+class BaseOs(object):
+    
+    def __init__(self, conf, env):
+        self.conf = conf
+        self.env = env
+        self.packages = conf.get("packages")
+
+
+    def install_packages(self, package_list=[]):
+        raise NotImplementedError
+        
+    def remove_packages(self, package_list=[]):
+        raise NotImplementedError
+        
+    def update_packages(self, package_list=[]):
+        raise NotImplementedError
+        
+    def update_os(self):
+        raise NotImplementedError 
+    

src/fabulator/core/system/debian.py

+"""
+    
+"""
+
+from fabric.api import run, sudo, cd
+
+from base import BaseOs
+
+
+
+class Debian(BaseOs):
+    
+    def install_packages(self, package_list=[]):
+        packages = package_list or self.packages
+        sudo("apt-get install %s" % " ".join(packages), False)
+        
+    def remove_packages(self, package_list=[]):
+        packages = package_list or self.packages
+        sudo("apt-get remove %s" % " ".join(packages), False)
+        
+    def update_packages(self, package_list=[]):
+        packages = package_list or self.packages
+        sudo("apt-get update %s" % " ".join(packages), False)
+        
+    def update_os(self):
+        sudo("apt-get update", False)
+        sudo("apt-get upgrade", False)
+        sudo("apt-get dist-upgrade", False)
+        

src/fabulator/core/system/ubuntu.py

+from debian import Debian
+
+class Ubuntu(Debian):
+    pass