Continue to port GMG codebase.
authorBerker Peksag <berker.peksag@gmail.com>
Wed, 19 Mar 2014 14:44:34 +0000 (16:44 +0200)
committerBerker Peksag <berker.peksag@gmail.com>
Thu, 8 May 2014 17:33:14 +0000 (20:33 +0300)
mediagoblin/_compat.py
mediagoblin/db/migration_tools.py
mediagoblin/db/open.py
mediagoblin/media_types/image/processing.py
mediagoblin/media_types/pdf/processing.py
mediagoblin/storage/__init__.py
mediagoblin/storage/filestorage.py
mediagoblin/tools/crypto.py
mediagoblin/tools/mail.py

index bbd91c3fb8e4a61ea29bc5b2401d42057d996c51..38c71524d372c0e8a7e8ebe5d30807e823a89f7e 100644 (file)
@@ -1,3 +1,10 @@
 import sys
 
-PY3 = sys.version_info[0] >= 3
+from six import PY3, iteritems
+
+if PY3:
+    from email.mime.text import MIMEText
+    from urllib import parse as urlparse
+else:
+    from email.MIMEText import MIMEText
+    import urlparse
index e39070c34160c1ba1b448a355433807448710589..e725f5656d56fe474d65f77a64d88df8f733e088 100644 (file)
@@ -14,6 +14,8 @@
 # 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/>.
 
+from __future__ import unicode_literals
+
 from mediagoblin.tools.common import simple_printer
 from sqlalchemy import Table
 from sqlalchemy.sql import select
@@ -39,7 +41,7 @@ class MigrationManager(object):
          - migration_registry: where we should find all migrations to
            run
         """
-        self.name = unicode(name)
+        self.name = name
         self.models = models
         self.foundations = foundations
         self.session = session
index 4ff0945ffcc1b9c8cc378b7b90e955f68cd57d4d..9cf9e5789925ddb554f4519a50440d4a1a1a7535 100644 (file)
@@ -20,6 +20,7 @@ import logging
 
 from mediagoblin.db.base import Base, Session
 from mediagoblin import mg_globals
+from mediagoblin._compat import iteritems
 
 _log = logging.getLogger(__name__)
 
@@ -28,7 +29,7 @@ class DatabaseMaster(object):
     def __init__(self, engine):
         self.engine = engine
 
-        for k, v in Base._decl_class_registry.iteritems():
+        for k, v in iteritems(Base._decl_class_registry):
             setattr(self, k, v)
 
     def commit(self):
index 1db82ee79667024a88c8c09d88a26aa86efe99f0..a9b966ffb3851f828575e8ef4f6c203816cefacb 100644 (file)
@@ -14,6 +14,8 @@
 # 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/>.
 
+from __future__ import print_function
+
 try:
     from PIL import Image
 except ImportError:
@@ -381,5 +383,4 @@ if __name__ == '__main__':
     clean = clean_exif(result)
     useful = get_useful(clean)
 
-    print pp.pprint(
-        clean)
+    print(pp.pprint(clean))
index a000007a36d89fb323e4eb6855e0ff96dcfbb202..0a173cf7f76fd200647c55a508aa8af3713afe0a 100644 (file)
@@ -138,7 +138,7 @@ def is_unoconv_working():
     try:
         proc = Popen([unoconv, '--show'], stderr=PIPE)
         output = proc.stderr.read()
-    except OSError, e:
+    except OSError:
         _log.warn(_('unoconv failing to run, check log file'))
         return False
     if 'ERROR' in output:
index 51b46c07151f8bb65f9346cce2f92c47275d26f1..3aa1f4a4f6e2af380f097a74d9631d7305efb350 100644 (file)
@@ -14,6 +14,8 @@
 # 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/>.
 
+from __future__ import absolute_import
+
 import shutil
 import uuid
 
@@ -268,4 +270,4 @@ def storage_system_from_config(config_section):
     storage_class = common.import_component(storage_class)
     return storage_class(**config_params)
 
-import filestorage
+from . import filestorage
index 29b8383b4deaea0aecac52e4b220346603921226..404d24c3f3f24611cd2af98c91e5dc3220ee4750 100644 (file)
@@ -21,7 +21,8 @@ from mediagoblin.storage import (
 
 import os
 import shutil
-import urlparse
+
+from mediagoblin._compat import urlparse
 
 
 class BasicFileStorage(StorageInterface):
index 917e674cf9dade8dc99d4a716155844ac793140a..14a1a72de978c08c070b70242be1861829e637df 100644 (file)
@@ -52,7 +52,7 @@ def load_key(filename):
 
 def create_key(key_dir, key_filepath):
     global __itsda_secret
-    old_umask = os.umask(077)
+    old_umask = os.umask(0o77)
     key_file = None
     try:
         if not os.path.isdir(key_dir):
@@ -80,7 +80,7 @@ def setup_crypto():
     key_filepath = os.path.join(key_dir, 'itsdangeroussecret.bin')
     try:
         load_key(key_filepath)
-    except IOError, error:
+    except IOError as error:
         if error.errno != errno.ENOENT:
             raise
         create_key(key_dir, key_filepath)
index 0fabc5a9c3aa1f77a7c58b61fc228a0320209431..ad2e5a1936a924a8c09360d70e786c8b6fec6c78 100644 (file)
 # 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/>.
 
+from __future__ import print_function, unicode_literals
+
 import smtplib
-from email.MIMEText import MIMEText
 from mediagoblin import mg_globals, messages
+from mediagoblin._compat import MIMEText
 from mediagoblin.tools import common
 
 ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -119,12 +121,12 @@ def send_email(from_addr, to_addrs, subject, message_body):
         EMAIL_TEST_INBOX.append(message)
 
     elif mg_globals.app_config['email_debug_mode']:
-        print u"===== Email ====="
-        print u"From address: %s" % message['From']
-        print u"To addresses: %s" % message['To']
-        print u"Subject: %s" % message['Subject']
-        print u"-- Body: --"
-        print message.get_payload(decode=True)
+        print("===== Email =====")
+        print("From address: %s" % message['From'])
+        print("To addresses: %s" % message['To'])
+        print("Subject: %s" % message['Subject'])
+        print("-- Body: --")
+        print(message.get_payload(decode=True))
 
     return mhost.sendmail(from_addr, to_addrs, message.as_string())
 
@@ -151,5 +153,5 @@ def email_debug_message(request):
     if mg_globals.app_config['email_debug_mode']:
         # DEBUG message, no need to translate
         messages.add_message(request, messages.DEBUG,
-            u"This instance is running in email debug mode. "
-            u"The email will be on the console of the server process.")
+            "This instance is running in email debug mode. "
+            "The email will be on the console of the server process.")