changeset 37:f30fe9183e64

remove clobber functionality for now; this should live in the master Fetch class so that resources arent multiply clobbered
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 15 Nov 2011 12:31:35 -0800
parents d3558b202acb
children 645d02834042
files fetch.py
diffstat 1 files changed, 12 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/fetch.py	Tue Nov 15 12:19:38 2011 -0800
+++ b/fetch.py	Tue Nov 15 12:31:35 2011 -0800
@@ -25,26 +25,17 @@
     def match(cls, _type):
         return _type == cls.type
 
-    def __init__(self, url, clobber=True):
+    def __init__(self, url):
         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
 
     def __call__(self, dest):
         raise NotImplementedError("Should be called by implementing class")
 
-    def clobber(self, dest):
-        """clobbers if self._clobber is set"""
-        if self._clobber and os.path.exists(dest):
-            if os.path.isfile(dest):
-                os.remove(dest)
-            else:
-                shutil.rmtree(dest)
-
     @classmethod
     def doc(cls):
         """return docstring for the instance"""
@@ -59,7 +50,7 @@
 
 class FileFetcher(Fetcher):
     """fetch a single file"""
-    # Note: subpath and clobber for single files are ignored
+    # Note: subpath for single files is ignored
 
     type = 'file'
 
@@ -83,7 +74,6 @@
     type = 'tar'
 
     def __call__(self, dest):
-        self.clobber(dest)
         if os.path.exists(dest):
             assert os.path.isdir(dest), "Destination must be a directory"
         else:
@@ -125,7 +115,6 @@
 
     def __call__(self, dest):
 
-        self.clobber(dest)
         if self.subpath or self.export:
             # can only export with a subpath
             self.export(dest, subpath=self.subpath)
@@ -147,7 +136,6 @@
         if self.subpath:
             path = os.path.join([tmpdir] + self.subpath)
             assert os.path.exists(path), "subpath %s of %s not found" % (os.path.sep.join(self.subpath), self.url)
-        self.clobber(dest)
         if os.path.isdir(path):
             if os.path.exists(dest):
                 assert os.path.isdir(dest), "source is a directory; destination is a file"
@@ -233,10 +221,11 @@
 
 class Fetch(object):
 
-    def __init__(self, fetchers=fetchers[:], relative_to=None, strict=True):
+    def __init__(self, fetchers=fetchers[:], relative_to=None, strict=True, clobber=True):
         self.fetchers = fetchers
         self.relative_to = relative_to
         self.strict = strict
+        self._clobber = clobber
 
     def fetcher(self, _type):
         """find the fetcher for the appropriate type"""
@@ -250,6 +239,14 @@
         fetcher = fetcher(url, **options)
         fetcher(destination)
 
+    def clobber(self, dest):
+        """clobbers if self._clobber is set"""
+        if self._clobber and os.path.exists(dest):
+            if os.path.isfile(dest):
+                os.remove(dest)
+            else:
+                shutil.rmtree(dest)
+
     def fetch(self, *items):
 
         if self.strict: