/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Martin Pool
  • Date: 2005-06-21 06:10:18 UTC
  • Revision ID: mbp@sourcefrog.net-20050621061017-12e8f0ff45228338
- move whitebox/blackbox modules into bzrlib.selftest subdirectory

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tree classes, representing directory at point in time.
18
18
"""
19
19
 
20
 
import os
21
 
 
22
 
import bzrlib
 
20
from sets import Set
 
21
import os.path, os, fnmatch, time
 
22
 
 
23
from osutils import pumpfile, filesize, quotefn, sha_file, \
 
24
     joinpath, splitpath, appendpath, isdir, isfile, file_kind, fingerprint_file
 
25
import errno
 
26
from stat import S_ISREG, S_ISDIR, ST_MODE, ST_SIZE
 
27
 
 
28
from bzrlib.inventory import Inventory
23
29
from bzrlib.trace import mutter, note
24
30
from bzrlib.errors import BzrError
25
 
from bzrlib.inventory import Inventory
26
 
from bzrlib.osutils import pumpfile, appendpath, fingerprint_file
 
31
import branch
27
32
 
 
33
import bzrlib
28
34
 
29
35
exporters = {}
30
36
 
67
73
 
68
74
    def _get_inventory(self):
69
75
        return self._inventory
70
 
    
71
 
    def get_file_by_path(self, path):
72
 
        return self.get_file(self._inventory.path2id(path))
73
76
 
74
77
    inventory = property(_get_inventory,
75
78
                         doc="Inventory of this Tree")
98
101
        pumpfile(self.get_file(fileid), sys.stdout)
99
102
        
100
103
        
101
 
    def export(self, dest, format='dir', root=None):
 
104
    def export(self, dest, format='dir'):
102
105
        """Export this tree."""
103
106
        try:
104
107
            exporter = exporters[format]
105
108
        except KeyError:
106
 
            from bzrlib.errors import BzrCommandError
107
109
            raise BzrCommandError("export format %r not supported" % format)
108
 
        exporter(self, dest, root)
 
110
        exporter(self, dest)
109
111
 
110
112
 
111
113
 
228
230
######################################################################
229
231
# export
230
232
 
231
 
def dir_exporter(tree, dest, root):
 
233
def dir_exporter(tree, dest):
232
234
    """Export this tree to a new directory.
233
235
 
234
236
    `dest` should not exist, and will be created holding the
240
242
    :note: If the export fails, the destination directory will be
241
243
           left in a half-assed state.
242
244
    """
243
 
    import os
244
245
    os.mkdir(dest)
245
246
    mutter('export version %r' % tree)
246
247
    inv = tree.inventory
261
262
except ImportError:
262
263
    pass
263
264
else:
264
 
    def get_root_name(dest):
265
 
        """Get just the root name for a tarball.
266
 
 
267
 
        >>> get_root_name('mytar.tar')
268
 
        'mytar'
269
 
        >>> get_root_name('mytar.tar.bz2')
270
 
        'mytar'
271
 
        >>> get_root_name('tar.tar.tar.tgz')
272
 
        'tar.tar.tar'
273
 
        >>> get_root_name('bzr-0.0.5.tar.gz')
274
 
        'bzr-0.0.5'
275
 
        >>> get_root_name('a/long/path/mytar.tgz')
276
 
        'mytar'
277
 
        >>> get_root_name('../parent/../dir/other.tbz2')
278
 
        'other'
279
 
        """
280
 
        endings = ['.tar', '.tar.gz', '.tgz', '.tar.bz2', '.tbz2']
281
 
        dest = os.path.basename(dest)
282
 
        for end in endings:
283
 
            if dest.endswith(end):
284
 
                return dest[:-len(end)]
285
 
 
286
 
    def tar_exporter(tree, dest, root, compression=None):
 
265
    def tar_exporter(tree, dest, compression=None):
287
266
        """Export this tree to a new tar file.
288
267
 
289
268
        `dest` will be created holding the contents of this tree; if it
290
269
        already exists, it will be clobbered, like with "tar -c".
291
270
        """
292
 
        from time import time
293
 
        now = time()
 
271
        now = time.time()
294
272
        compression = str(compression or '')
295
 
        if root is None:
296
 
            root = get_root_name(dest)
297
273
        try:
298
274
            ball = tarfile.open(dest, 'w:' + compression)
299
275
        except tarfile.CompressionError, e:
302
278
        inv = tree.inventory
303
279
        for dp, ie in inv.iter_entries():
304
280
            mutter("  export {%s} kind %s to %s" % (ie.file_id, ie.kind, dest))
305
 
            item = tarfile.TarInfo(os.path.join(root, dp))
 
281
            item = tarfile.TarInfo(dp)
306
282
            # TODO: would be cool to actually set it to the timestamp of the
307
283
            # revision it was last changed
308
284
            item.mtime = now
325
301
        ball.close()
326
302
    exporters['tar'] = tar_exporter
327
303
 
328
 
    def tgz_exporter(tree, dest, root):
329
 
        tar_exporter(tree, dest, root, compression='gz')
 
304
    def tgz_exporter(tree, dest):
 
305
        tar_exporter(tree, dest, compression='gz')
330
306
    exporters['tgz'] = tgz_exporter
331
307
 
332
 
    def tbz_exporter(tree, dest, root):
333
 
        tar_exporter(tree, dest, root, compression='bz2')
 
308
    def tbz_exporter(tree, dest):
 
309
        tar_exporter(tree, dest, compression='bz2')
334
310
    exporters['tbz2'] = tbz_exporter
335
311
 
336
312