# HG changeset patch # User Jeff Hammel # Date 1321334756 28800 # Node ID d495b610046a249813762f63a6b085e96266672a # Parent e628ce3ae49ffef87bd644abcd18322edb4e4d36 more stubbing; tests work again diff -r e628ce3ae49f -r d495b610046a fetch.py --- a/fetch.py Mon Nov 14 20:19:57 2011 -0800 +++ b/fetch.py Mon Nov 14 21:25:56 2011 -0800 @@ -32,11 +32,19 @@ if self.subpath: self.subpath = self.subpath.split('/') self.url = url - self.clobber = clobber + 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""" @@ -51,7 +59,7 @@ class FileFetcher(Fetcher): """fetch a single file""" - # Note: subpath for files is ignored + # Note: subpath and clobber for single files are ignored type = 'file' @@ -75,8 +83,10 @@ type = 'tar' def __call__(self, dest): + if self.clobber: + shutil.rmtree(dest) if os.path.exists(dest): - assert os.path.isdir(dest) + assert os.path.isdir(dest), "Destination must be a directory" else: os.mkdirs(dest) if self.subpath: @@ -116,18 +126,35 @@ if self.subpath or self.export: # can only export with a subpath + self.export(dest, subpath=self.subpath) + return - if os.path.exists(dest): assert os.path.isdir(dest) + self.clone(dest) def export(self, dest): """ export a clone of the directory """ + dest = os.path.abspath(dest) tmpdir = tempfile.mkdtmp() self.clone(tmpdir) - + path = tmpdir + 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" + else: + os.makedirs(dest) + else: + if os.path.exists(dest): + assert os.path.isfile(dest), "" + else: + directory, filename = os.path.split(dest) shutil.rmtree(tmpdir) def clone(self, dest): @@ -136,6 +163,12 @@ """ raise NotImplementedError("Abstract base class") + def update(self, dest): + """ + updates a checkout + """ + raise NotImplementedError("Abstract base class") + if which('hg'):