~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/exporter.py

  • Committer: Martin Albisetti
  • Date: 2009-09-01 21:44:23 UTC
  • Revision ID: martin.albisetti@canonical.com-20090901214423-mo6dctq8xvpm2jse
Super-trivial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Exports an archive from a bazaar branch"""
2
 
 
3
 
from bzrlib.export import get_export_generator
4
 
 
5
 
class ExporterFileObject(object):
6
 
    
7
 
    def __init__(self):
8
 
        self._buffer = []
9
 
        
10
 
    def write(self, str):
11
 
        self._buffer.append(str)
12
 
        
13
 
    def get_buffer(self):
14
 
        try:
15
 
            return ''.join(self._buffer)
16
 
        finally:
17
 
            self._buffer = []
18
 
        
19
 
def export_archive(history, revid, format=".tar.gz"):
20
 
    """Export tree contents to an archive
21
 
 
22
 
    :param history: Instance of history to export
23
 
    :param revid: Revision to export
24
 
    :param format: Format of the archive
25
 
    """
26
 
    
27
 
    fileobj = ExporterFileObject()
28
 
    
29
 
    tree = history._branch.repository.revision_tree(revid)
30
 
    
31
 
    for _ in get_export_generator(tree=tree, fileobj=fileobj, format=format):
32
 
        
33
 
        yield fileobj.get_buffer()
34
 
 
35
 
    
36
 
        
 
 
b'\\ No newline at end of file'