Source

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

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


"""
import os

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"""
        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)