~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Martin Pool
  • Date: 2005-07-06 10:07:31 UTC
  • Revision ID: mbp@sourcefrog.net-20050706100731-ce25f8bf569ad1ae
- start adding refactored/simplified hash cache
  not used yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""
19
19
 
20
20
from osutils import pumpfile, appendpath, fingerprint_file
21
 
import os
22
21
 
23
22
from bzrlib.trace import mutter, note
24
23
from bzrlib.errors import BzrError
94
93
        pumpfile(self.get_file(fileid), sys.stdout)
95
94
        
96
95
        
97
 
    def export(self, dest, format='dir', root=None):
 
96
    def export(self, dest, format='dir'):
98
97
        """Export this tree."""
99
98
        try:
100
99
            exporter = exporters[format]
101
100
        except KeyError:
102
 
            from bzrlib.errors import BzrCommandError
103
101
            raise BzrCommandError("export format %r not supported" % format)
104
 
        exporter(self, dest, root)
 
102
        exporter(self, dest)
105
103
 
106
104
 
107
105
 
143
141
 
144
142
 
145
143
class EmptyTree(Tree):
146
 
    def __init__(self, root_id):
 
144
    def __init__(self):
147
145
        from bzrlib.inventory import Inventory
148
 
        self._inventory = Inventory(root_id)
 
146
        self._inventory = Inventory()
149
147
 
150
148
    def has_filename(self, filename):
151
149
        return False
225
223
######################################################################
226
224
# export
227
225
 
228
 
def dir_exporter(tree, dest, root):
 
226
def dir_exporter(tree, dest):
229
227
    """Export this tree to a new directory.
230
228
 
231
229
    `dest` should not exist, and will be created holding the
258
256
except ImportError:
259
257
    pass
260
258
else:
261
 
    def get_root_name(dest):
262
 
        """Get just the root name for a tarball.
263
 
 
264
 
        >>> get_root_name('mytar.tar')
265
 
        'mytar'
266
 
        >>> get_root_name('mytar.tar.bz2')
267
 
        'mytar'
268
 
        >>> get_root_name('tar.tar.tar.tgz')
269
 
        'tar.tar.tar'
270
 
        >>> get_root_name('bzr-0.0.5.tar.gz')
271
 
        'bzr-0.0.5'
272
 
        >>> get_root_name('a/long/path/mytar.tgz')
273
 
        'mytar'
274
 
        >>> get_root_name('../parent/../dir/other.tbz2')
275
 
        'other'
276
 
        """
277
 
        endings = ['.tar', '.tar.gz', '.tgz', '.tar.bz2', '.tbz2']
278
 
        dest = os.path.basename(dest)
279
 
        for end in endings:
280
 
            if dest.endswith(end):
281
 
                return dest[:-len(end)]
282
 
 
283
 
    def tar_exporter(tree, dest, root, compression=None):
 
259
    def tar_exporter(tree, dest, compression=None):
284
260
        """Export this tree to a new tar file.
285
261
 
286
262
        `dest` will be created holding the contents of this tree; if it
289
265
        from time import time
290
266
        now = time()
291
267
        compression = str(compression or '')
292
 
        if root is None:
293
 
            root = get_root_name(dest)
294
268
        try:
295
269
            ball = tarfile.open(dest, 'w:' + compression)
296
270
        except tarfile.CompressionError, e:
299
273
        inv = tree.inventory
300
274
        for dp, ie in inv.iter_entries():
301
275
            mutter("  export {%s} kind %s to %s" % (ie.file_id, ie.kind, dest))
302
 
            item = tarfile.TarInfo(os.path.join(root, dp))
 
276
            item = tarfile.TarInfo(dp)
303
277
            # TODO: would be cool to actually set it to the timestamp of the
304
278
            # revision it was last changed
305
279
            item.mtime = now
322
296
        ball.close()
323
297
    exporters['tar'] = tar_exporter
324
298
 
325
 
    def tgz_exporter(tree, dest, root):
326
 
        tar_exporter(tree, dest, root, compression='gz')
 
299
    def tgz_exporter(tree, dest):
 
300
        tar_exporter(tree, dest, compression='gz')
327
301
    exporters['tgz'] = tgz_exporter
328
302
 
329
 
    def tbz_exporter(tree, dest, root):
330
 
        tar_exporter(tree, dest, root, compression='bz2')
 
303
    def tbz_exporter(tree, dest):
 
304
        tar_exporter(tree, dest, compression='bz2')
331
305
    exporters['tbz2'] = tbz_exporter
332
306
 
333
307