changeset 25:e628ce3ae49f

more stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 14 Nov 2011 20:19:57 -0800
parents b1f65f3bd1bc
children d495b610046a
files fetch.py
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/fetch.py	Thu Nov 10 08:16:48 2011 -0800
+++ b/fetch.py	Mon Nov 14 20:19:57 2011 -0800
@@ -29,6 +29,8 @@
         self.subpath = None
         if '#' in url:
             url, self.subpath = url.rsplit('#')
+            if self.subpath:
+                self.subpath = self.subpath.split('/')
         self.url = url
         self.clobber = clobber 
 
@@ -49,6 +51,7 @@
 
 class FileFetcher(Fetcher):
     """fetch a single file"""
+    # Note: subpath for files is ignored
   
     type = 'file'
 
@@ -57,6 +60,7 @@
         return urllib2.urlopen(url).read()
 
     def __call__(self, dest):
+
         if os.path.isdir(dest):
             filename = self.url.rsplit('/', 1)[-1]
             dest = os.path.join(dest, filename)
@@ -109,8 +113,30 @@
         self.export = export
 
     def __call__(self, dest):
+
+        if self.subpath or self.export:
+            # can only export with a subpath
+            
+
+        if os.path.exists(dest):
+            assert os.path.isdir(dest)
+
+    def export(self, dest):
+        """
+        export a clone of the directory
+        """
+        tmpdir = tempfile.mkdtmp()
+        self.clone(tmpdir)
+        
+        shutil.rmtree(tmpdir)
+
+    def clone(self, dest):
+        """
+        clones into a directory
+        """
         raise NotImplementedError("Abstract base class")
 
+
 if which('hg'):
 
     class HgFetcher(VCSFetcher):
@@ -120,6 +146,7 @@
         def __init__(self, url, export=True):
             VCSFetcher.__init__(self, url, export=True)
             self.hg = which('hg')
+            assert self.hg, "'hg' command not found"
 
         def __call__(self, dest):
             if os.path.exists(dest):