Ticket #647: patch.diff

File patch.diff, 3.0 KB (added by Boris Bobrov, 10 years ago)

patch 1

  • mediagoblin/storage/cloudfiles.py

    diff --git a/mediagoblin/storage/cloudfiles.py b/mediagoblin/storage/cloudfiles.py
    index 532e5ba..61665ea 100644
    a b class CloudFilesStorageObjectWrapper():  
    193193        return self.storage_object.read(*args, **kwargs)
    194194
    195195    def write(self, data, *args, **kwargs):
    196         """
    197         write data to the cloudfiles storage object
    198 
    199         The original motivation for this wrapper is to ensure
    200         that buffered writing to a cloudfiles storage object does not overwrite
    201         any preexisting data.
    202 
    203         Currently this method does not support any write modes except "append".
    204         However if we should need it it would be easy implement.
    205         """
    206         _log.warn(
    207             '{0}.write() has bad performance! Use .send instead for now'\
    208             .format(self.__class__.__name__))
    209 
    210         if self.storage_object.size and type(data) == str:
    211             _log.debug('{0} is > 0 in size, appending data'.format(
    212                 self.storage_object.name))
    213             data = self.read() + data
    214 
    215         _log.debug('Writing {0}'.format(
    216             self.storage_object.name))
    217196        self.storage_object.write(data, *args, **kwargs)
    218197
    219198    def send(self, *args, **kw):
  • mediagoblin/storage/filestorage.py

    diff --git a/mediagoblin/storage/filestorage.py b/mediagoblin/storage/filestorage.py
    index f989539..89f4327 100644
    a b  
    1414# You should have received a copy of the GNU Affero General Public License
    1515# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616
     17import io
    1718import os
    1819import shutil
    1920
    from mediagoblin.storage import (  
    2425    clean_listy_filepath,
    2526    NoWebServing)
    2627
     28class FileObjectAwareFile(io.FileIO):
     29    def write(self, data):
     30        if hasattr(data, 'read'):
     31            # We can call data.read(). It means that the data is a file-like
     32            # object, which should be saved RAM-friendly way
     33            shutil.copyfileobj(data, self)
     34        else:
     35            super(FileObjectAwareFile, self).write(data)
     36
    2737
    2838class BasicFileStorage(StorageInterface):
    2939    """
    class BasicFileStorage(StorageInterface):  
    6070                os.makedirs(directory)
    6171
    6272        # Grab and return the file in the mode specified
    63         return open(self._resolve_filepath(filepath), mode)
     73        return FileObjectAwareFile(self._resolve_filepath(filepath), mode)
    6474
    6575    def delete_file(self, filepath):
    6676        """Delete file at filepath
  • mediagoblin/submit/lib.py

    diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py
    index 541447e..a0e1cf9 100644
    a b def submit_media(mg_app, user, submitted_file, filename,  
    157157    queue_file = prepare_queue_task(mg_app, entry, filename)
    158158
    159159    with queue_file:
    160         queue_file.write(submitted_file.read())
     160        queue_file.write(submitted_file)
    161161
    162162    # Get file size and round to 2 decimal places
    163163    file_size = mg_app.queue_store.get_file_size(