changeset 24:b1f65f3bd1bc

pretend to flesh out git fetcher
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 10 Nov 2011 08:16:48 -0800
parents 12ad9ab11860
children e628ce3ae49f
files fetch.py
diffstat 1 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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)