~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2005-10-16 09:30:48 UTC
  • mto: This revision was merged to the branch mainline in revision 1459.
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051016093048-9d12448dab8f8b97
rebuild ScratchBranch on top of ScratchTransport

Show diffs side-by-side

added added

removed removed

Lines of Context:
1329
1329
    >>> isdir(b.base)
1330
1330
    True
1331
1331
    >>> bd = b.base
1332
 
    >>> b.destroy()
 
1332
    >>> b._transport.__del__()
1333
1333
    >>> isdir(bd)
1334
1334
    False
1335
1335
    """
1336
 
    def __init__(self, files=[], dirs=[], base=None):
 
1336
 
 
1337
    def __init__(self, files=[], dirs=[], transport=None):
1337
1338
        """Make a test branch.
1338
1339
 
1339
1340
        This creates a temporary directory and runs init-tree in it.
1340
1341
 
1341
1342
        If any files are listed, they are created in the working copy.
1342
1343
        """
1343
 
        from tempfile import mkdtemp
1344
 
        init = False
1345
 
        if base is None:
1346
 
            base = mkdtemp()
1347
 
            init = True
1348
 
        if isinstance(base, basestring):
1349
 
            base = get_transport(base)
1350
 
        _Branch.__init__(self, base, init=init)
 
1344
        if transport is None:
 
1345
            transport = bzrlib.transport.local.ScratchTransport()
 
1346
            super(ScratchBranch, self).__init__(transport, init=True)
 
1347
        else:
 
1348
            super(ScratchBranch, self).__init__(transport)
 
1349
 
1351
1350
        for d in dirs:
1352
1351
            self._transport.mkdir(d)
1353
1352
            
1373
1372
        base = mkdtemp()
1374
1373
        os.rmdir(base)
1375
1374
        copytree(self.base, base, symlinks=True)
1376
 
        return ScratchBranch(base=base)
1377
 
 
1378
 
    def __del__(self):
1379
 
        self.destroy()
1380
 
 
1381
 
    def destroy(self):
1382
 
        """Destroy the test branch, removing the scratch directory."""
1383
 
        from shutil import rmtree
1384
 
        try:
1385
 
            if self.base:
1386
 
                mutter("delete ScratchBranch %s" % self.base)
1387
 
                rmtree(self.base)
1388
 
        except OSError, e:
1389
 
            # Work around for shutil.rmtree failing on Windows when
1390
 
            # readonly files are encountered
1391
 
            mutter("hit exception in destroying ScratchBranch: %s" % e)
1392
 
            for root, dirs, files in os.walk(self.base, topdown=False):
1393
 
                for name in files:
1394
 
                    os.chmod(os.path.join(root, name), 0700)
1395
 
            rmtree(self.base)
1396
 
        self._transport = None
1397
 
 
 
1375
        return ScratchBranch(
 
1376
            transport=bzrlib.transport.local.ScratchTransport(base))
1398
1377
    
1399
1378
 
1400
1379
######################################################################