~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-05-08 23:19:40 UTC
  • Revision ID: mbp@sourcefrog.net-20050508231938-45078cb8791615c4
- Using the destructor on a ScratchBranch is not reliable;
  so now there's a destroy() method as well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
967
967
    >>> isdir(b.base)
968
968
    True
969
969
    >>> bd = b.base
970
 
    >>> del b
 
970
    >>> b.destroy()
971
971
    >>> isdir(bd)
972
972
    False
973
973
    """
987
987
 
988
988
 
989
989
    def __del__(self):
 
990
        self.destroy()
 
991
 
 
992
    def destroy(self):
990
993
        """Destroy the test branch, removing the scratch directory."""
991
994
        try:
 
995
            mutter("delete ScratchBranch %s" % self.base)
992
996
            shutil.rmtree(self.base)
993
 
        except OSError:
 
997
        except OSError, e:
994
998
            # Work around for shutil.rmtree failing on Windows when
995
999
            # readonly files are encountered
 
1000
            mutter("hit exception in destroying ScratchBranch: %s" % e)
996
1001
            for root, dirs, files in os.walk(self.base, topdown=False):
997
1002
                for name in files:
998
1003
                    os.chmod(os.path.join(root, name), 0700)
999
1004
            shutil.rmtree(self.base)
 
1005
        self.base = None
1000
1006
 
1001
1007
    
1002
1008