root/galaxy-central/lib/galaxy/util/streamball.py

リビジョン 2, 0.9 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1"""
2A simple wrapper for writing tarballs as a stream.
3"""
4
5import logging, tarfile
6
7log = logging.getLogger( __name__ )
8
9class StreamBall( object ):
10    def __init__( self, mode, members=None ):
11        self.members = members
12        if members is None:
13            self.members = {}
14        self.mode = mode
15        self.wsgi_status = None
16        self.wsgi_headeritems = None
17    def add( self, file, relpath ):
18        self.members[file] = relpath
19    def stream( self, environ, start_response ):
20        response_write = start_response( self.wsgi_status, self.wsgi_headeritems )
21        class tarfileobj:
22            def write( self, *args, **kwargs ):
23                response_write( *args, **kwargs )
24        tf = tarfile.open( mode=self.mode, fileobj=tarfileobj() )
25        for file, rel in self.members.items():
26            tf.add( file, arcname=rel )
27        tf.close()
28        return []
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。