view buttercup/source.py @ 18:151862a0a711

begin restructuring to something more modular and extensible
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 30 May 2011 13:40:13 -0700
parents
children d3b1bf9d8235
line wrap: on
line source

import os
import subprocess

class Source(object):
    """abstract base class for VCS source"""
    def __init__(self, uri, srcdir=None):
        self.uri = uri
        self.srcdir = srcdir or os.getcwd()

    @classmethod
    def directory_name(cls, uri):
        """return relative directory name from self.uri"""
        return uri.rstrip('/').split('/')[-1]

    def directory(self):
        return os.path.join(self.srcdir, self.directory_name(self.uri))

class HgSource(Source):
    """mercurial source"""

    def update(self):
        """updates a checkout or does one if it does not exist"""

class GitSource(Source):

    @classmethod
    def directory_name(cls, uri):
        ext = '.git'
        if uri.endswith(uri):
            uri = uri[:-len(ext)]
        return Source.directory_name(uri)

if __name__ == '__main__':
    source = HgSource('http://k0s.org/hg/pyloader')
    print source.directory()
    source = GitSource('git://github.com/mozilla/toolbox.git')
    print source.directory()