diff --git a/lib/galaxy/util/streamball.py b/lib/galaxy/util/streamball.py index 528b0f90120..2fbaca8c1e9 100644 --- a/lib/galaxy/util/streamball.py +++ b/lib/galaxy/util/streamball.py @@ -2,11 +2,13 @@ A simple wrapper for writing tarballs as a stream. """ import os -import logging, tarfile +import logging +import tarfile from galaxy.exceptions import ObjectNotFound log = logging.getLogger( __name__ ) + class StreamBall( object ): def __init__( self, mode, members=None ): self.members = members @@ -15,16 +17,19 @@ class StreamBall( object ): self.mode = mode self.wsgi_status = None self.wsgi_headeritems = None + def add( self, file, relpath, check_file=False): - if check_file and len(file)>0: + if check_file and len(file) > 0: if not os.path.isfile(file): raise ObjectNotFound else: self.members[file] = relpath else: self.members[file] = relpath + def stream( self, environ, start_response ): response_write = start_response( self.wsgi_status, self.wsgi_headeritems ) + class tarfileobj: def write( self, *args, **kwargs ): response_write( *args, **kwargs ) @@ -34,10 +39,12 @@ class StreamBall( object ): tf.close() return [] + class ZipBall(object): def __init__(self, tmpf, tmpd): self._tmpf = tmpf self._tmpd = tmpd + def stream(self, environ, start_response): response_write = start_response( self.wsgi_status, self.wsgi_headeritems ) tmpfh = open( self._tmpf )