Merge remote-tracking branch 'refs/remotes/breton/bug/647'
This commit is contained in:
commit
50f12414df
@ -17,11 +17,6 @@ import logging
|
|||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
|
|
||||||
import gi
|
|
||||||
gi.require_version('Gst', '1.0')
|
|
||||||
from gi.repository import GObject, Gst, GstPbutils, GLib
|
|
||||||
Gst.init(None)
|
|
||||||
|
|
||||||
_log = logging.getLogger(__name__)
|
_log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -36,6 +31,13 @@ def discover(src):
|
|||||||
'''
|
'''
|
||||||
Discover properties about a media file
|
Discover properties about a media file
|
||||||
'''
|
'''
|
||||||
|
# GStreamer might be not installed, so it should not be initialized on
|
||||||
|
# import, or an exception will be raised.
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gst', '1.0')
|
||||||
|
from gi.repository import GObject, Gst, GstPbutils, GLib
|
||||||
|
Gst.init(None)
|
||||||
|
|
||||||
_log.info('Discovering {0}...'.format(src))
|
_log.info('Discovering {0}...'.format(src))
|
||||||
uri = 'file://{0}'.format(src)
|
uri = 'file://{0}'.format(src)
|
||||||
discoverer = GstPbutils.Discoverer.new(60 * Gst.SECOND)
|
discoverer = GstPbutils.Discoverer.new(60 * Gst.SECOND)
|
||||||
|
@ -193,27 +193,6 @@ class CloudFilesStorageObjectWrapper():
|
|||||||
return self.storage_object.read(*args, **kwargs)
|
return self.storage_object.read(*args, **kwargs)
|
||||||
|
|
||||||
def write(self, data, *args, **kwargs):
|
def write(self, data, *args, **kwargs):
|
||||||
"""
|
|
||||||
write data to the cloudfiles storage object
|
|
||||||
|
|
||||||
The original motivation for this wrapper is to ensure
|
|
||||||
that buffered writing to a cloudfiles storage object does not overwrite
|
|
||||||
any preexisting data.
|
|
||||||
|
|
||||||
Currently this method does not support any write modes except "append".
|
|
||||||
However if we should need it it would be easy implement.
|
|
||||||
"""
|
|
||||||
_log.warn(
|
|
||||||
'{0}.write() has bad performance! Use .send instead for now'\
|
|
||||||
.format(self.__class__.__name__))
|
|
||||||
|
|
||||||
if self.storage_object.size and type(data) == str:
|
|
||||||
_log.debug('{0} is > 0 in size, appending data'.format(
|
|
||||||
self.storage_object.name))
|
|
||||||
data = self.read() + data
|
|
||||||
|
|
||||||
_log.debug('Writing {0}'.format(
|
|
||||||
self.storage_object.name))
|
|
||||||
self.storage_object.write(data, *args, **kwargs)
|
self.storage_object.write(data, *args, **kwargs)
|
||||||
|
|
||||||
def send(self, *args, **kw):
|
def send(self, *args, **kw):
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
@ -24,6 +25,15 @@ from mediagoblin.storage import (
|
|||||||
clean_listy_filepath,
|
clean_listy_filepath,
|
||||||
NoWebServing)
|
NoWebServing)
|
||||||
|
|
||||||
|
class FileObjectAwareFile(io.FileIO):
|
||||||
|
def write(self, data):
|
||||||
|
if hasattr(data, 'read'):
|
||||||
|
# We can call data.read(). It means that the data is a file-like
|
||||||
|
# object, which should be saved RAM-friendly way
|
||||||
|
shutil.copyfileobj(data, self)
|
||||||
|
else:
|
||||||
|
super(FileObjectAwareFile, self).write(data)
|
||||||
|
|
||||||
|
|
||||||
class BasicFileStorage(StorageInterface):
|
class BasicFileStorage(StorageInterface):
|
||||||
"""
|
"""
|
||||||
@ -60,7 +70,7 @@ class BasicFileStorage(StorageInterface):
|
|||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
|
|
||||||
# Grab and return the file in the mode specified
|
# Grab and return the file in the mode specified
|
||||||
return open(self._resolve_filepath(filepath), mode)
|
return FileObjectAwareFile(self._resolve_filepath(filepath), mode)
|
||||||
|
|
||||||
def delete_file(self, filepath):
|
def delete_file(self, filepath):
|
||||||
"""Delete file at filepath
|
"""Delete file at filepath
|
||||||
|
@ -157,7 +157,7 @@ def submit_media(mg_app, user, submitted_file, filename,
|
|||||||
queue_file = prepare_queue_task(mg_app, entry, filename)
|
queue_file = prepare_queue_task(mg_app, entry, filename)
|
||||||
|
|
||||||
with queue_file:
|
with queue_file:
|
||||||
queue_file.write(submitted_file.read())
|
queue_file.write(submitted_file)
|
||||||
|
|
||||||
# Get file size and round to 2 decimal places
|
# Get file size and round to 2 decimal places
|
||||||
file_size = mg_app.queue_store.get_file_size(
|
file_size = mg_app.queue_store.get_file_size(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user