Commits

Benoit C committed 3135dbd

begining a refactor: create classes to easily manage your database, your http server (for the moment)

Comments (0)

Files changed (14)

 from fabric.api import *
 from fabric.contrib.files import exists, sed
 from fabulator.decorators import Permissions, ConfChecker
-from fabulator.core import mysql, south, haystack
-
+from fabulator.core import south, haystack
+from fabulator.core.db import mysql
 
 import yaml
 import time
 def uname():
     run("uname -a")
 
-def pwd():
-    run("pwd")
-    run("id")
-
 def load_yaml(env_type, conf):
     # sure we can do more there
     env.yaml = yaml.load(file(conf).read()).get(env_type)

src/fabulator/core/__init__.pyc

Binary file added.

src/fabulator/core/db/__init__.py

Empty file added.

src/fabulator/core/db/base.py

+# -*- coding: latin-1 -*-
+"""
+
+
+
+"""
+
+from fabric.api import sudo, run
+
+class BaseDB(object):
+    """Base class for database"""
+
+    def __init__(self, conf):
+        self.conf = conf
+
+    def create_database(self, database_name=None):
+        """create database"""
+        raise NotImplementedError
+
+    def backup(self, filename="plop"):
+        """backup the database"""
+        raise NotImplementedError
+
+    def migrate(self, revision):
+        """migrate the database"""
+        raise NotImplementedError
+
+    def fallback(self, revision):
+        """fallback to an old revision"""
+        raise NotImplementedError
+
+    def drop_table(self, table_name):
+        """Drop a table"""
+        raise NotImplementedError
+
+    def drop_database(self, database_name):
+        raise NotImplementedError
+
+    def list_revision(self):
+        """Return a list of available database revision"""
+        raise NotImplementedError
+
+    def rc(self, service_name, rc_name=None, command="start", require_space=None):
+        """manage the daemon using system RC"""
+        rc_name = rc_name or "/etc/init.d/"
+        service_name = service_name or "mysql"
+        if require_space:
+            sudo("%s %s %s" % (rc_name, service_name, command))
+        sudo("%s/%s %s" % (rc_name, service_name, command))
+

src/fabulator/core/db/mysql.py

+"""
+    mysql management functions
+"""
+import datetime
+import time
+
+from fabric.api import run
+
+from base import BaseDB
+
+class MySQL(BaseDB):
+    """Base class for database"""
+
+    def create_database(self, database_name=None):
+        """create database"""
+        run("echo 'CREATE DATABASE IF NOT EXISTS %(db)s' | mysql --user=%(user)s --password=%(pw)s" % self.conf)
+
+    def backup(self, filename="plop"):
+        """Backups your mysql database"""
+        date = datetime.datetime.now()
+
+        conf['backup_fname'] = "%s/backup-%s-%d-%d-%d-%s.sql" % \
+            (self.conf.get('backup'), self.conf.get('db'), date.day, date.month,
+             date.year, time.time())
+        run("mkdir -p %(backup)s" % self.conf)
+        run("""mysqldump --host=%(host)s --user=%(user)s --password=%(pw)s %(db)s > %(backup_fname)s""" % self.conf)
+
+    def migrate(self, revision):
+        """migrate the database"""
+        raise NotImplementedError
+
+    def fallback(self, revision):
+        """fallback to an old revision"""
+        raise NotImplementedError
+
+    def drop_table(self, table_name):
+        """Drop a table"""
+        raise NotImplementedError
+
+    def drop_database(self, database_name):
+        run("echo 'DROP DATABASE %(db)s' | mysql --user=%(user)s --password=%(pw)s" % self.conf)
+
+    def list_revision(self):
+        """Return a list of available database revision"""
+        run("ls -l %(backup)s" % self.conf)
+        raise NotImplementedError
+
+
+
+

src/fabulator/core/haystack.pyc

Binary file added.

src/fabulator/core/http/__init__.py

Empty file added.

src/fabulator/core/http/base.py

+# -*- coding: latin-1 -*-
+"""
+
+
+
+"""
+from interface import BaseHTTP
+
+class BaseHTTP(object):
+    """Nginx class for web servers management"""
+
+    def install_vhost(self, vhost_name):
+        """Install the vhost for your http webserver"""
+        raise NotImplementedError
+
+    def rc(self, service_name, rc_name=None, command="start", require_space=None):
+        """manage the daemon using system RC"""
+        rc_name = rc_name or "/etc/init.d/"
+        service_name = service_name or "nginx"
+        if require_space:
+            sudo("%s %s %s" % (rc_name, service_name, command))
+        sudo("%s/%s %s" % (rc_name, service_name, command))
+
+
+
+

src/fabulator/core/http/nginx.py

+# -*- coding: latin-1 -*-
+"""
+
+
+
+"""
+
+from base import BaseHTTP
+
+class Nginx(BaseHTTP):
+    """
+
+    """
+
+    def install_vhost(self):
+        raise NotImplementedError
+ 
+
+def main():
+    """some quick mains"""
+    pass
+
+if __name__ == '__main__':
+    main()

src/fabulator/core/south.pyc

Binary file added.

src/fabulator/core/vc/__init__.py

Empty file added.

src/fabulator/core/vc/interface.py

+# -*- coding: latin-1 -*-
+"""
+
+
+
+"""
+
+class BaseVC(object):
+    """Base class for versionning control system"""
+
+    def __init__(self):
+        pass
+

src/fabulator/core/virtualenv.py

+"""
+    virtualenv management functions
+
+"""
+
+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')):
+        ret = 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))

src/fabulator/core/wsgi/__init__.py

Empty file added.