Opened 10 years ago

Closed 10 years ago

#5053 closed defect (fixed)

gmg addmedia broken in 0.8

Reported by: ayleph Owned by:
Priority: major Milestone: 0.8.0
Component: programming Keywords: addmedia, cli
Cc: Parent Tickets:

Description

bin/gmg addmedia no longer works.

(mediagoblin-0.8.0) ~/mediagoblin-0.8.0 $ bin/gmg addmedia ayleph video.mp4 
/usr/lib/python2.7/site-packages/gi/module.py:178: Warning: g_array_append_vals: assertion 'array' failed
  g_type = info.get_g_type()
/usr/lib/python2.7/site-packages/gi/module.py:178: Warning: g_hash_table_lookup: assertion 'hash_table != NULL' failed
  g_type = info.get_g_type()
/usr/lib/python2.7/site-packages/gi/module.py:178: Warning: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed
  g_type = info.get_g_type()
/path/to/mediagoblin/lib/python2.7/site-packages/SQLAlchemy-0.8.7-py2.7-linux-x86_64.egg/sqlalchemy/engine/default.py:471: SAWarning: Unicode type received non-unicode bind param value.
Traceback (most recent call last):
  File "bin/gmg", line 9, in <module>
    load_entry_point('mediagoblin==0.8.1.dev0', 'console_scripts', 'gmg')()
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/__init__.py", line 142, in main_cli
    args.func(args)
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/addmedia.py", line 104, in addmedia
    upload_limit=upload_limit, max_file_size=max_file_size)
  File "/path/to/mediagoblin/mediagoblin/submit/lib.py", line 139, in submit_media
    media_type, media_manager = sniff_media(submitted_file, filename)
  File "/path/to/mediagoblin/mediagoblin/media_types/__init__.py", line 147, in sniff_media
    media_file.save(tmp_media_file.name)
AttributeError: 'file' object has no attribute 'save'

Change History (3)

comment:1 by Boris Bobrov, 10 years ago

Owner: set to Boris Bobrov
Status: newin_progress

comment:2 by Boris Bobrov, 10 years ago

Owner: Boris Bobrov removed
Status: in_progressreview

The patch should fix it.

diff --git a/mediagoblin/media_types/__init__.py b/mediagoblin/media_types/__init__.py
index ab39fa3..3eeead8 100644
--- a/mediagoblin/media_types/__init__.py
+++ b/mediagoblin/media_types/__init__.py
@@ -16,6 +16,7 @@
 
 import os
 import logging
+import shutil
 import tempfile
 
 from mediagoblin.tools.pluginapi import hook_handle
@@ -143,7 +144,7 @@ def sniff_media(media_file, filename):
     # copy the contents to a .name-enabled temporary file for further checks
     # TODO: there are cases when copying is not required
     tmp_media_file = tempfile.NamedTemporaryFile()
-    media_file.save(tmp_media_file.name)
+    shutil.copyfileobj(media_file, tmp_media_file)
     media_file.seek(0)
     try:
         return type_match_handler(tmp_media_file, filename)

ayleph, could you please test it?

comment:3 by Christopher Allan Webber, 10 years ago

Resolution: fixed
Status: reviewclosed

Looks good to me, I merged the patch!

In the future a patch using git-format-patch is easiest to merge.

Note: See TracTickets for help on using tickets.