Commits

Benoit C committed 951280c

mercurial: implement the abstract class BaseVC

Comments (0)

Files changed (8)

 
 def build(conf):
     """instanciate the backend"""
-    env.vc = vc_factory(conf["vc"].get("type"), conf)
-    env.db = database_factory(conf["database"].get("type"), conf)
-    env.httpd = http_factory(conf["httpd"].get("type"), conf)
+    env.vc = vc_factory(conf["vc"].get("type"), conf.get("vc"), env)
+    env.db = database_factory(conf["database"].get("type"), conf.get("database"), env)
+    env.httpd = http_factory(conf["httpd"].get("type"), conf.get("httpd"), env)
 
 def preprod(conf="conf.yaml"):
     """Preprod tasks"""
     print env.httpd
     print env.db
     print env.vc
+    
+    env.vc.clone_repository()
 #    # install required packages 
 #    distro_install()
 #

src/fabulator/core/db/__init__.py

     "pgsql" : PgSQL,
 }
 
-def database_factory(database, conf):
-    return databases[database.lower()](conf)
+def database_factory(database, conf, env):
+    return databases[database.lower()](conf, env)
     

src/fabulator/core/db/base.py

 class BaseDB(object):
     """Base class for database"""
 
-    def __init__(self, conf):
+    def __init__(self, conf, env):
         self.conf = conf
+        self.env = env
 
     def create_database(self, database_name=None):
         """create database"""

src/fabulator/core/http/__init__.py

     "nginx" : Nginx,
 }
 
-def http_factory(webserver, conf):
-    return webservers[webserver.lower()](conf)
+def http_factory(webserver, conf, env):
+    return webservers[webserver.lower()](conf, env)

src/fabulator/core/http/base.py

 
 class BaseHTTP(object):
 
-    def __init__(self, conf):
+    def __init__(self, conf, env):
         self.conf = conf
+        self.env = env
 
     def install_vhost(self, vhost_name):
         """Install the vhost for your http webserver"""

src/fabulator/core/vc/__init__.py

     "mercurial" : Mercurial
 }
 
-def vc_factory(vc, conf):
-    return vcs[vc.lower()](conf)
+def vc_factory(vc, conf, env):
+    return vcs[vc.lower()](conf, env)

src/fabulator/core/vc/base.py

 """
 class BaseVC(object):
 
-    def __init__(self, conf):
+    def __init__(self, conf, env):
+        self.env = env
         self.conf = conf
-        pass
+        self.url = conf.get('url')
+        self.repos = conf.get('repos')
+        self.dest = conf.get('dest')
+        self.user = conf.get('user')
+        self.pw = conf.get('pw')
+        self.scheme = conf.get('scheme')
 
+    def clone_repository(self, dest=None):
+        """fetches the full repository"""
+        raise NotImplementedError
+
+    def switch_branch(self, branch_name):
+        """switch from the current branch"""
+        raise NotImplementedError
+
+    def update_repository(self):
+        """update the repository"""
+        raise NotImplementedError
+        
+    def remove_repository(self):
+        """remove the repository (yeah sometimes we expect some cleanups)"""
+        raise NotImplementedError
+        
+    def update_to_revision(self, revision):
+        """update the code to a specified revision"""
+        raise NotImplementedError

src/fabulator/core/vc/mercurial.py

 
 
 """
+import os
+
+from fabric.api import run, sudo, cd
 
 from base import BaseVC
 
 class Mercurial(BaseVC):
     """base class for controlling your Mercurial"""
 
-    pass
+    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.scheme:
+                run("hg clone %(scheme)s://%(user)s:%(pw)s@%(url)s/%(repos)s %(dest)s" % self.conf)
+            else:
+                run("hg clone %(url)s/%(repos)s" % self.conf)
+
+
+    def switch_branch(self, branch_name):
+        """switch from the current branch"""
+        with cd("%(dest)s/%(repos)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):
+            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):
+        raise NotImplementedError
+
+    def update_to_revision(self, revision):
+        """update the code to a specified revision"""
+        with cd("%(dest)s/%(repos)s" % self.conf):
+            run("hg update -C %s" % revision)
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.