~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-20 08:10:38 UTC
  • mfrom: (1740.6.2 bzr.mbp.remove-scratch)
  • Revision ID: pqm@pqm.ubuntu.com-20060620081038-8eb4543e54b8491c
(mbp) remove Scratch objects

Show diffs side-by-side

added added

removed removed

Lines of Context:
1376
1376
        return result
1377
1377
 
1378
1378
 
1379
 
class ScratchDir(BzrDir6):
1380
 
    """Special test class: a bzrdir that cleans up itself..
1381
 
 
1382
 
    >>> d = ScratchDir()
1383
 
    >>> base = d.transport.base
1384
 
    >>> isdir(base)
1385
 
    True
1386
 
    >>> b.transport.__del__()
1387
 
    >>> isdir(base)
1388
 
    False
1389
 
    """
1390
 
 
1391
 
    def __init__(self, files=[], dirs=[], transport=None):
1392
 
        """Make a test branch.
1393
 
 
1394
 
        This creates a temporary directory and runs init-tree in it.
1395
 
 
1396
 
        If any files are listed, they are created in the working copy.
1397
 
        """
1398
 
        if transport is None:
1399
 
            transport = bzrlib.transport.local.ScratchTransport()
1400
 
            # local import for scope restriction
1401
 
            BzrDirFormat6().initialize(transport.base)
1402
 
            super(ScratchDir, self).__init__(transport, BzrDirFormat6())
1403
 
            self.create_repository()
1404
 
            self.create_branch()
1405
 
            self.create_workingtree()
1406
 
        else:
1407
 
            super(ScratchDir, self).__init__(transport, BzrDirFormat6())
1408
 
 
1409
 
        # BzrBranch creates a clone to .bzr and then forgets about the
1410
 
        # original transport. A ScratchTransport() deletes itself and
1411
 
        # everything underneath it when it goes away, so we need to
1412
 
        # grab a local copy to prevent that from happening
1413
 
        self._transport = transport
1414
 
 
1415
 
        for d in dirs:
1416
 
            self._transport.mkdir(d)
1417
 
            
1418
 
        for f in files:
1419
 
            self._transport.put(f, 'content of %s' % f)
1420
 
 
1421
 
    def clone(self):
1422
 
        """
1423
 
        >>> orig = ScratchDir(files=["file1", "file2"])
1424
 
        >>> os.listdir(orig.base)
1425
 
        [u'.bzr', u'file1', u'file2']
1426
 
        >>> clone = orig.clone()
1427
 
        >>> if os.name != 'nt':
1428
 
        ...   os.path.samefile(orig.base, clone.base)
1429
 
        ... else:
1430
 
        ...   orig.base == clone.base
1431
 
        ...
1432
 
        False
1433
 
        >>> os.listdir(clone.base)
1434
 
        [u'.bzr', u'file1', u'file2']
1435
 
        """
1436
 
        from shutil import copytree
1437
 
        from bzrlib.osutils import mkdtemp
1438
 
        base = mkdtemp()
1439
 
        os.rmdir(base)
1440
 
        copytree(self.base, base, symlinks=True)
1441
 
        return ScratchDir(
1442
 
            transport=bzrlib.transport.local.ScratchTransport(base))
1443
 
 
1444
 
 
1445
1379
class Converter(object):
1446
1380
    """Converts a disk format object from one format to another."""
1447
1381