# HG changeset patch # User Jeff Hammel # Date 1320941808 28800 # Node ID b1f65f3bd1bcb376e2d11b8593ec8dbe2b40de70 # Parent 12ad9ab11860dea4b04e49811ea80dbec977d8c3 pretend to flesh out git fetcher diff -r 12ad9ab11860 -r b1f65f3bd1bc fetch.py --- a/fetch.py Wed Nov 09 20:21:14 2011 -0800 +++ b/fetch.py Thu Nov 10 08:16:48 2011 -0800 @@ -71,7 +71,10 @@ type = 'tar' def __call__(self, dest): - assert os.path.isdir(dest) + if os.path.exists(dest): + assert os.path.isdir(dest) + else: + os.mkdirs(dest) if self.subpath: raise NotImplementedError("should extract only a subpath of a tarball but I haven't finished it yet") buffer = StringIO() @@ -82,7 +85,7 @@ fetchers = [FileFetcher, TarballFetcher] -### VCS fetchers using executable +### VCS fetchers import subprocess try: @@ -91,6 +94,13 @@ raise # we need check_call, kinda class VCSFetcher(Fetcher): + + command = None + + def call(*args, **kwargs): + assert command is not None, "Abstract base class" + call([self.command] + list(args), **kwargs) + def __init__(self, url, export=True): """ - export : whether to strip the versioning information @@ -98,6 +108,9 @@ Fetcher.__init__(self, url) self.export = export + def __call__(self, dest): + raise NotImplementedError("Abstract base class") + if which('hg'): class HgFetcher(VCSFetcher): @@ -120,6 +133,7 @@ fetchers.append(HgFetcher) + if which('git'): class GitFetcher(Fetcher): @@ -130,7 +144,16 @@ VCSFetcher.__init__(self, url, export=True) self.git = which('git') - def __call__(self, url + def __call__(self, dest): + if os.path.exists(dest): + assert os.path.isdir(dest) and os.path.exists(os.path.join(dest, '.git')) + call([self.git, 'pull', self.url], cwd=dest) + call([self.hg, 'update'], cwd=dest) + else: + if not os.path.exists(dest): + os.mkdirs(dest) + call([self.hg, 'clone', self.url, dest]) + fetchers.append(GitFetcher)