Benoit C avatar Benoit C committed efdf15d

add missing smtp __init__

Fix somes pb with "vc"

Comments (0)

Files changed (6)

 from fabulator.core.http import http_factory
 from fabulator.core.system import os_factory
 from fabulator.core.virtualenv import VirtualEnv
+from fabulator.core.django import Django
 
 import yaml
 import time
     # we can be more magic here
     if "vc" in conf:
         env.vc = vc_factory(conf["vc"].get("type"), conf.get("vc"), env)
-    if "database" in conf:
-        env.db = database_factory(conf["database"].get("type"), conf.get("database"), env)
+    if "db" in conf:
+        env.db = database_factory(conf["db"].get("type"), conf.get("db"), env)
     if "httpd" in conf:
         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"
+    if "distro" in conf:
+        env.os = os_factory(conf["distro"].get("name"), conf.get("distro"), env)
+    if "django" in conf:
+        env.django = Django(conf.get("django"), env)
+
 
 def preprod(conf="conf.yaml"):
     """Preprod tasks"""
     build(env.yaml)
 
 
-@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)
-    print services
-
-@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)
-
-    
-
 def update():
     """updates the code and everything else"""
-    distro_install()
-
-    update_hg()
-    
-    virtualenv()
-
-    install_httpd_vhost()
-
-    # install django configuration
-    django_settings()
-
-    update_database()
- 
-
-    # start/restart the wsgi/fcgi process
-    wsgi_restart()
-
-    # restart other services
-    services_reload()
-    services_restart()
-
-
+    env.vc.update_repository()
 
 
 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.os.install_packages()
     env.vc.clone_repository()
+    env.vc.switch_branch(env.vc.conf.get("branch"))
     env.virtualenv.create_virtualenv()
     env.virtualenv.install_requirements(False)
     
-    env.db.create_database()
+    #env.db.create_database
+    #env.django.configure()
+    #env.django.syncdb()
+    #env.django.runserver()
 
 
-
-#    # install required packages 
-#    distro_install()
-#
-#    # 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()
-#
-#    # start/restart the wsgi/fcgi process
-#    wsgi_restart()
-#
-#    # restart other services
-#    services_reload()
-#    services_restart()
-
 def reset():
     env.vc.remove_repository()
-    env.db.drop_database()
-
-@Permissions("sudo_user", env)
-def nginx_logs():
-    sudo("sudo tail -f /var/log/nginx/*.log")
-
-
-@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" % package)
-
-@Permissions("sudo_user", env)
-@ConfChecker("distro", env)
-def delete_database():
-    db = env.yaml.get('database')
-    mysql.drop_database(db)
-
-@Permissions("sudo_user", env)
-@ConfChecker("distro", env)
-def delete_repos():
-    conf = env.yaml.get('project')
-    run("rm -Rf %(doc_root)s" % conf)
-
-
-
-
-@Permissions("normal_user", env)
-@ConfChecker("database", env)
-def install_database():
-    """Install your database schema"""
-    conf = env.yaml.get("database")
-    django = env.yaml.get("django")
-    venv = env.yaml.get("virtualenv")
-
-    mysql.create_database(conf)
-    if django.get('south'):
-        south.install_south(env)
-
-    with cd("%(src_dir)s" % django):
-        if django.get('south'):
-            run("%(bin_dir)s/python manage.py migrate --all" % venv)
-        else:
-            run("%(bin_dir)s/python manage.py syncdb --noinput" % venv)
+    #env.db.drop_database()
 
 
 @Permissions("normal_user", env)

src/fabulator/core/django.py

+"""
+    Class to manage your django project
+"""
+
+from fabric.api import sudo, run, cd
+from fabric.contrib.files import sed
+
+class Django(object):
+    
+    def __init__(self, conf, env):
+        self.conf = conf
+        self.env = env
+        
+    def configure(self):
+        """configure your django project : deals withs settings.py"""
+        with cd("%(dir)s" % self.conf):
+            run("cp deploy/%s-settings.py %s/settings_local.py" % (self.env.type, self.conf.get('dir')))
+            sed("%(dir)s/settings_local.py" % self.conf, "DOCUMENT_ROOT", "%(dir)s" % self.conf)
+        
+    def syncdb(self):
+        """run syncdb"""
+        conf = self.conf.copy()
+        conf["bin_dir"] = self.env.virtualenv.conf.get("bin_dir")
+        run("%(bin_dir)s/python %(dir)s/manage.py syncdb --noinput" % conf)
+        
+    def load_fixtures(self):
+        """load from fixtures"""
+        pass
+    
+    def dump_fixtures(self, app, format="yaml"):
+        """dump a fixture"""
+        pass
+        
+    def runserver(self, host="localhost", port=8080):
+        """launches the development server"""
+        conf = self.conf.copy()
+        conf["bin_dir"] = self.env.virtualenv.conf.get("bin_dir")
+        conf["host"] = host
+        conf["port"] = port
+        run("%(bin_dir)s/python %(dir)s/manage.py runserver %(host)s:%(port)d" % conf)
+        
+
+    
Add a comment to this file

src/fabulator/core/smtp/__init__.py

Empty file added.

src/fabulator/core/vc/base.py

         self.user = conf.get('user')
         self.pw = conf.get('pw')
         self.scheme = conf.get('scheme')
+        self.conf['doc_root'] = env.yaml.get('project').get("doc_root")
+        self.conf['root_dir'] = env.yaml.get('project').get('root_dir')
 
     def clone_repository(self, dest=None):
         """fetches the full repository"""
         raise NotImplementedError
 
-    def switch_branch(self, branch_name):
+    def switch_branch(self, branch_name=None):
         """switch from the current branch"""
         raise NotImplementedError
 

src/fabulator/core/vc/mercurial.py

 
 """
 import os
+import pprint
 
 from fabric.api import run, sudo, cd
 
 
     def clone_repository(self, dest=None):
         """fetches the full repository"""
-        run("mkdir -p %s" % os.path.dirname("%s" % self.dest))
-        with cd("%(dest)s" % self.conf):
+        if self.conf.get('create_directory'):
+            run("mkdir -p %s" % os.path.dirname("%s" % self.dest))
+        
+        with cd("%(root_dir)s" % self.env.yaml.get('project')):
             if self.scheme:
-                run("hg clone %(scheme)s://%(user)s:%(pw)s@%(url)s/%(repos)s %(dest)s" % self.conf)
+                run("hg clone %(scheme)s://%(user)s@%(url)s/%(repos)s %(doc_root)s" % self.conf)
             else:
                 run("hg clone %(url)s/%(repos)s" % self.conf)
 
 
-    def switch_branch(self, branch_name):
+    def switch_branch(self, branch_name=None):
         """switch from the current branch"""
-        with cd("%(dest)s/%(repos)s" % self.conf):
+        if not branch_name:
+            print "no branch selected"
+            return
+        with cd("%(doc_root)s" % self.conf):
             run("hg update -C %s" % branch_name)
 
     def update_repository(self):
         """update the repository"""
-        with cd("%(dest)s/%(repos)s" % self.conf):
+        with cd("%(doc_root)s" % self.conf):
             run("hg pull -u")
 
     def remove_repository(self):
         """remove the repository (yeah sometimes we expect some cleanups)"""
-        run("rm -Rf %(dest)s/%(repos)s" % self.conf)
+        run("rm -Rf %(doc_root)s" % self.conf)
 
     def update_to_revision(self, revision):
         """update the code to a specified revision"""
-        with cd("%(dest)s/%(repos)s" % self.conf):
+        with cd("%(doc_root)s" % self.conf):
             run("hg update -C %s" % revision)

src/fabulator/core/virtualenv.py

         self.dir = conf.get("dir")
         self.bin_dir = self.dir + os.sep + "bin"
         self.bin = conf.get("bin") or "virtualenv"
-        self.requirements = conf.get("requirements")
+        self.requirements = conf.get("requirements", [])
+        self.requirements_file = conf.get("requirements_file")
     
     def create_virtualenv(self, folder=None, pip=True):
         """creates the virtualenv"""
     def install_pip(self):
         """checks if pip exists or install it using easy_install"""
         if not exists("%s/pip" % self.bin_dir):
-            run("source %s/activate && easy_install pip" % (self.bin_dir))
+            run("%s/easy_install pip" % (self.bin_dir))
 
     def install_requirements(self, use_file=True):
-        if use_file:
-            run("pip install -E %s -r %s" % (self.dir, self.conf.get("requirements-file")))
-        else:
-            for requirement in self.requirements:
-                run("pip install -E %s %s" % (self.dir, requirement))
+        
+        if self.requirements_file:
+            run("%s/pip install -r %s" % (self.bin_dir, self.conf.get("requirements_file")))
+        for requirement in self.requirements:
+            run("%s/pip install %s" % (self.bin_dir, requirement))
         
     def update_requirements(self, use_file=True):
         if use_file:
-            run("pip install -E %s -r %s --upgrade" % (self.dir, self.conf.get("requirements-file")))
+            run("%s/pip install  -r %s --upgrade" % (self.bin_dir, self.conf.get("requirements-file")))
         else:
             for requirement in self.requirements:
-                run("pip install -E %s %s --upgrade" % (self.dir, requirement))
+                run("%s/pip install %s --upgrade" % (self.bin_dir, requirement))
 
     def remove_virtualenv(self):
         run("rm -Rf %s" % self.dir)
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.