upload refactor: push url handling
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 17 Dec 2012 18:42:31 +0000 (19:42 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 26 Dec 2012 22:42:26 +0000 (23:42 +0100)
Start to refactor our upload handling in main submit and
the api. Start factoring out the handling of PuSH url
handling.

mediagoblin/submit/lib.py [new file with mode: 0644]
mediagoblin/submit/views.py

diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py
new file mode 100644 (file)
index 0000000..57069e8
--- /dev/null
@@ -0,0 +1,50 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# 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/>.
+
+import urllib
+import urllib2
+import logging
+
+from mediagoblin import mg_globals
+
+_log = logging.getLogger(__name__)
+
+
+def handle_push_urls(request):
+    if mg_globals.app_config["push_urls"]:
+        feed_url = request.urlgen(
+                           'mediagoblin.user_pages.atom_feed',
+                           qualified=True,
+                           user=request.user.username)
+        hubparameters = {
+            'hub.mode': 'publish',
+            'hub.url': feed_url}
+        hubdata = urllib.urlencode(hubparameters)
+        hubheaders = {
+            "Content-type": "application/x-www-form-urlencoded",
+            "Connection": "close"}
+        for huburl in mg_globals.app_config["push_urls"]:
+            hubrequest = urllib2.Request(huburl, hubdata, hubheaders)
+            try:
+                hubresponse = urllib2.urlopen(hubrequest)
+            except urllib2.HTTPError as exc:
+                # This is not a big issue, the item will be fetched
+                # by the PuSH server next time we hit it
+                _log.warning(
+                    "push url %r gave error %r", huburl, exc.code)
+            except urllib2.URLError as exc:
+                _log.warning(
+                    "push url %r is unreachable %r", huburl, exc.reason)
index b52fca3382b44843d04524adb802f8b93554435f..6d4c8be38b2072a665a0744d3e2f961643ea4e2a 100644 (file)
@@ -20,8 +20,6 @@ import uuid
 from os.path import splitext
 
 from celery import registry
-import urllib
-import urllib2
 import logging
 
 _log = logging.getLogger(__name__)
@@ -39,6 +37,7 @@ from mediagoblin.processing.task import ProcessMedia
 from mediagoblin.messages import add_message, SUCCESS
 from mediagoblin.media_types import sniff_media, \
     InvalidFileType, FileTypeNotSupported
+from mediagoblin.submit.lib import handle_push_urls
 
 
 @require_active_login
@@ -134,30 +133,7 @@ def submit_start(request):
                     # re-raise the exception
                     raise
 
-                if mg_globals.app_config["push_urls"]:
-                    feed_url = request.urlgen(
-                                       'mediagoblin.user_pages.atom_feed',
-                                       qualified=True,
-                                       user=request.user.username)
-                    hubparameters = {
-                        'hub.mode': 'publish',
-                        'hub.url': feed_url}
-                    hubdata = urllib.urlencode(hubparameters)
-                    hubheaders = {
-                        "Content-type": "application/x-www-form-urlencoded",
-                        "Connection": "close"}
-                    for huburl in mg_globals.app_config["push_urls"]:
-                        hubrequest = urllib2.Request(huburl, hubdata, hubheaders)
-                        try:
-                            hubresponse = urllib2.urlopen(hubrequest)
-                        except urllib2.HTTPError as exc:
-                            # This is not a big issue, the item will be fetched
-                            # by the PuSH server next time we hit it
-                            _log.warning(
-                                "push url %r gave error %r", huburl, exc.code)
-                        except urllib2.URLError as exc:
-                            _log.warning(
-                                "push url %r is unreachable %r", huburl, exc.reason)
+                handle_push_urls(request)
 
                 add_message(request, SUCCESS, _('Woohoo! Submitted!'))