diff options
-rw-r--r-- | MANIFEST.in | 10 | ||||
-rw-r--r-- | mediagoblin/db/models.py | 1 | ||||
-rw-r--r-- | mediagoblin/media_types/video/transcoders.py | 37 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/media_collect.html | 11 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/utils/wtforms.html | 2 | ||||
-rw-r--r-- | mediagoblin/tests/test_misc.py | 15 | ||||
-rw-r--r-- | mediagoblin/tools/files.py | 2 | ||||
-rw-r--r-- | mediagoblin/user_pages/views.py | 25 |
8 files changed, 75 insertions, 28 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index b3ae7b75..0a39ce84 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,11 @@ recursive-include mediagoblin/i18n *.mo -recursive-include mediagoblin/templates *.html *.txt *.xml -recursive-include mediagoblin/static *.js *.css *.png *.svg *.ico -recursive-include mediagoblin/tests *.ini +recursive-include mediagoblin *.js *.css *.png *.svg *.ico +recursive-include mediagoblin *.ini +recursive-include mediagoblin *.html *.txt recursive-include docs *.rst *.html +include mediagoblin.ini mediagoblin/config_spec.ini paste.ini include mediagoblin/config_spec.ini graft extlib +graft licenses +include COPYING AUTHORS +include lazyserver.sh lazystarter.sh lazycelery.sh diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 10e0c33f..2f58503f 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -145,6 +145,7 @@ class MediaEntry(Base, MediaEntryMixin): ) attachment_files_helper = relationship("MediaAttachmentFile", + cascade="all, delete-orphan", order_by="MediaAttachmentFile.created" ) attachment_files = association_proxy("attachment_files_helper", "dict_view", diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py index 152de288..3a6a1c4d 100644 --- a/mediagoblin/media_types/video/transcoders.py +++ b/mediagoblin/media_types/video/transcoders.py @@ -477,8 +477,8 @@ from playbin') _log.debug('thumbnail message: {0}'.format(message)) if message.type == gst.MESSAGE_ERROR: - _log.error('thumbnail error: {0}'.format(message)) - gobject.idle_add(self.on_thumbnail_error) + _log.error('thumbnail error: {0}'.format(message.parse_error())) + gobject.idle_add(self.on_thumbnail_error, message) if message.type == gst.MESSAGE_STATE_CHANGED: prev_state, cur_state, pending_state = \ @@ -570,10 +570,37 @@ pending: {2}'.format( return False - def on_thumbnail_error(self): - _log.error('Thumbnailing failed.') + def on_thumbnail_error(self, message): + scaling_failed = False + + if 'Error calculating the output scaled size - integer overflow' \ + in message.parse_error()[1]: + # GStreamer videoscale sometimes fails to calculate the dimensions + # given only one of the destination dimensions and the source + # dimensions. This is a workaround in case videoscale returns an + # error that indicates this has happened. + scaling_failed = True + _log.error('Thumbnailing failed because of videoscale integer' + ' overflow. Will retry with fallback.') + else: + _log.error('Thumbnailing failed: {0}'.format(message.parse_error())) + + # Kill the current mainloop self.disconnect() + if scaling_failed: + # Manually scale the destination dimensions + _log.info('Retrying with manually set sizes...') + + info = VideoTranscoder().discover(self.source_path) + + h = info['videoheight'] + w = info['videowidth'] + ratio = 180 / int(w) + h = int(h * ratio) + + self.__init__(self.source_path, self.dest_path, 180, h) + def disconnect(self): self.state = self.STATE_HALTING @@ -1007,4 +1034,4 @@ if __name__ == '__main__': print('I\'m a callback!') transcoder.transcode(*args, progress_callback=cb) elif options.action == 'discover': - print transcoder.discover(*args).__dict__ + print transcoder.discover(*args) diff --git a/mediagoblin/templates/mediagoblin/user_pages/media_collect.html b/mediagoblin/templates/mediagoblin/user_pages/media_collect.html index 8cdb64fe..8b19e8c0 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media_collect.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media_collect.html @@ -57,8 +57,7 @@ </div> <div id="new_collection" class="subform"> - - <h3>{% trans %}Add a new collection{% endtrans %}</h3> + <h3>{% trans %}Add a new collection{% endtrans %}</h3> <p class="form_field_label"> <label for="{{ (form.collection_title.name) }}">{{ _(form.collection_title.label.text) }}</label> @@ -66,13 +65,7 @@ <div class="form_field_input"> {{ form.collection_title }} </div> - <p class="form_field_label"> - <label for="{{ (form.collection_description.name) }}">{{ _(form.collection_description.label.text) }}</label> - </p> - <div class="form_field_input"> - {{ form.collection_description }} - </div> - + {{- wtforms_util.render_field_div(form.collection_description) }} </div> <p class="form_field_label"> <label for="{{ (form.note.name) }}">{{ _(form.note.label.text) }}</label> diff --git a/mediagoblin/templates/mediagoblin/utils/wtforms.html b/mediagoblin/templates/mediagoblin/utils/wtforms.html index 58ecb8e0..df2354ed 100644 --- a/mediagoblin/templates/mediagoblin/utils/wtforms.html +++ b/mediagoblin/templates/mediagoblin/utils/wtforms.html @@ -28,7 +28,7 @@ <p class="form_field_error">{{ _(error) }}</p> {% endfor %} {%- endif %} - {% if field.description -%} + {%- if field.description %} <p class="form_field_description">{{ _(field.description)|safe }}</p> {%- endif %} </div> diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index b48b8762..776affc6 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -78,3 +78,18 @@ def test_user_deletes_other_comments(): assert_equal(med_cnt2, med_cnt1 - 2) # All comments gone assert_equal(cmt_cnt2, cmt_cnt1 - 4) + + +def test_media_deletes_broken_attachment(): + user_a = fixture_add_user(u"chris_a") + + media = fixture_media_entry(uploader=user_a.id, save=False) + media.attachment_files.append(dict( + name=u"some name", + filepath=[u"does", u"not", u"exist"], + )) + Session.add(media) + Session.flush() + + MediaEntry.query.get(media.id).delete() + User.query.get(user_a.id).delete() diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py index fd38f05e..848c86f2 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -37,7 +37,7 @@ def delete_media_files(media): mg_globals.public_store.delete_file( attachment['filepath']) except OSError: - no_such_files.append("/".join(attachment)) + no_such_files.append("/".join(attachment['filepath'])) if no_such_files: raise OSError(", ".join(no_such_files)) diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index dea47fbf..0225b6d7 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -205,7 +205,7 @@ def media_collect(request, media): if existing_collection: messages.add_message(request, messages.ERROR, _('You already have a collection called "%s"!' - % collection.title)) + % existing_collection.title)) return redirect(request, "mediagoblin.user_pages.media_home", user=request.user.username, media=media.id) @@ -309,6 +309,9 @@ def user_collection(request, page, url_user=None): get_creator=url_user, slug=request.matchdict['collection']).first() + if not collection: + return render_404(request) + cursor = collection.get_collection_items() pagination = Pagination(page, cursor) @@ -515,6 +518,8 @@ def collection_atom_feed(request): collection = Collection.query.filter_by( creator=user.id, slug=request.matchdict['collection']).first() + if not collection: + return render_404(request) cursor = CollectionItem.query.filter_by( collection=collection.id) \ @@ -539,14 +544,16 @@ def collection_atom_feed(request): 'href': push_url}) feed = AtomFeed( - "MediaGoblin: Feed for %s's collection %s" % (request.matchdict['user'], collection.title), - feed_url=request.url, - id='tag:{host},{year}:collection.user-{user}.title-{title}'.format( - host=request.host, - year=datetime.datetime.today().strftime('%Y'), - user=request.matchdict['user'], - title=collection.title), - links=atomlinks) + "MediaGoblin: Feed for %s's collection %s" % + (request.matchdict['user'], collection.title), + feed_url=request.url, + id=u'tag:{host},{year}:gnu-mediagoblin.{user}.collection.{slug}'\ + .format( + host=request.host, + year=collection.created.strftime('%Y'), + user=request.matchdict['user'], + slug=collection.slug), + links=atomlinks) for item in cursor: entry = item.get_media_entry |