1. Benoit C
  2. fabulator


fabulator / src / fabulator / core / vc / mercurial.py

# -*- coding: latin-1 -*-

import os
import pprint

from fabric.api import run, sudo, cd

from base import BaseVC

class Mercurial(BaseVC):
    """base class for controlling your Mercurial"""

    def clone_repository(self, dest=None):
        """fetches the full repository"""
        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@%(url)s/%(repos)s %(doc_root)s" % self.conf)
                run("hg clone %(url)s/%(repos)s" % self.conf)

    def switch_branch(self, branch_name=None):
        """switch from the current branch"""
        if not branch_name:
            print "no branch selected"
        with cd("%(doc_root)s" % self.conf):
            run("hg update -C %s" % branch_name)

    def update_repository(self):
        """update the repository"""
        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 %(doc_root)s" % self.conf)

    def update_to_revision(self, revision):
        """update the code to a specified revision"""
        with cd("%(doc_root)s" % self.conf):
            run("hg update -C %s" % revision)