First round of Python 3 compatibility fixes.

This commit is contained in:
Murtuza Zabuawala 2015-11-06 10:23:19 +00:00 committed by Dave Page
parent da6043e7a5
commit 209ee78b25
11 changed files with 41 additions and 43 deletions

View File

@ -32,20 +32,20 @@ if config.SERVER_MODE is True:
local_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), local_config = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'config_local.py') 'config_local.py')
if not os.path.isfile(local_config): if not os.path.isfile(local_config):
print "The configuration file %s does not exist.\n" % local_config print("The configuration file %s does not exist.\n" % local_config)
print "Before running this application, ensure that config_local.py has been created" print("Before running this application, ensure that config_local.py has been created")
print "and sets values for SECRET_KEY, SECURITY_PASSWORD_SALT and CSRF_SESSION_KEY" print("and sets values for SECRET_KEY, SECURITY_PASSWORD_SALT and CSRF_SESSION_KEY")
print "at bare minimum. See config.py for more information and a complete list of" print("at bare minimum. See config.py for more information and a complete list of")
print "settings. Exiting..." print("settings. Exiting...")
sys.exit(1) sys.exit(1)
# Check if the database exists. If it does not, tell the user and exit. # Check if the database exists. If it does not, tell the user and exit.
if not os.path.isfile(config.SQLITE_PATH): if not os.path.isfile(config.SQLITE_PATH):
print "The configuration database %s does not exist.\n" \ print("The configuration database %s does not exist.\n" \
% config.SQLITE_PATH % config.SQLITE_PATH)
print "Please run 'python %s' to create it.\nExiting..." % os.path.join( print("Please run 'python %s' to create it.\nExiting..." % os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'setup.py' os.path.dirname(os.path.realpath(__file__)), 'setup.py'
) ))
sys.exit(1) sys.exit(1)
########################################################################## ##########################################################################

View File

@ -16,7 +16,7 @@ from flask.ext.security import Security, SQLAlchemyUserDatastore
from flask_security.utils import login_user from flask_security.utils import login_user
from flask_mail import Mail from flask_mail import Mail
from htmlmin.minify import html_minify from htmlmin.minify import html_minify
from settings.settings_model import db, Role, User, Version from pgadmin.settings.settings_model import db, Role, User, Version
from importlib import import_module from importlib import import_module
from werkzeug.local import LocalProxy from werkzeug.local import LocalProxy
from pgadmin.utils import PgAdminModule, driver from pgadmin.utils import PgAdminModule, driver
@ -40,9 +40,9 @@ class PgAdmin(Flask):
continue continue
self.logger.info('Examining potential module: %s' % module_name) self.logger.info('Examining potential module: %s' % module_name)
module = import_module(module_name) module = import_module(module_name)
for key, value in module.__dict__.items(): for key in list(module.__dict__.keys()):
if isinstance(value, PgAdminModule): if isinstance(module.__dict__[key], PgAdminModule):
yield value yield module.__dict__[key]
@property @property
def submodules(self): def submodules(self):

View File

@ -16,10 +16,10 @@ from flask.ext.security import login_required
from flask.ext.login import current_user from flask.ext.login import current_user
from flask.ext.babel import gettext from flask.ext.babel import gettext
from flaskext.gravatar import Gravatar from flaskext.gravatar import Gravatar
import six
MODULE_NAME = 'browser' MODULE_NAME = 'browser'
class BrowserModule(PgAdminModule): class BrowserModule(PgAdminModule):
def get_own_stylesheets(self): def get_own_stylesheets(self):
@ -136,20 +136,18 @@ class BrowserModule(PgAdminModule):
for module in self.submodules: for module in self.submodules:
scripts.extend(module.get_own_javascripts()) scripts.extend(module.get_own_javascripts())
return scripts return scripts
blueprint = BrowserModule(MODULE_NAME, __name__) blueprint = BrowserModule(MODULE_NAME, __name__)
@six.add_metaclass(ABCMeta)
class BrowserPluginModule(PgAdminModule): class BrowserPluginModule(PgAdminModule):
""" """
Base class for browser submodules. Base class for browser submodules.
""" """
browser_url_prefix = blueprint.url_prefix + '/' browser_url_prefix = blueprint.url_prefix + '/'
__metaclass__ = ABCMeta
def __init__(self, import_name, **kwargs): def __init__(self, import_name, **kwargs):
kwargs.setdefault("url_prefix", self.node_path) kwargs.setdefault("url_prefix", self.node_path)
@ -178,7 +176,6 @@ class BrowserPluginModule(PgAdminModule):
for module in self.submodules: for module in self.submodules:
scripts.extend(module.get_own_javascripts()) scripts.extend(module.get_own_javascripts())
return scripts return scripts
def generate_browser_node( def generate_browser_node(
@ -213,7 +210,6 @@ class BrowserPluginModule(PgAdminModule):
for submodule in self.submodules: for submodule in self.submodules:
snippets.extend(submodule.csssnippets) snippets.extend(submodule.csssnippets)
return snippets return snippets
@abstractmethod @abstractmethod

View File

@ -21,7 +21,7 @@ from pgadmin.browser import BrowserPluginModule
from pgadmin.utils.menu import MenuItem from pgadmin.utils.menu import MenuItem
from pgadmin.settings.settings_model import db, ServerGroup from pgadmin.settings.settings_model import db, ServerGroup
from pgadmin.browser.utils import NodeView from pgadmin.browser.utils import NodeView
import six
class ServerGroupModule(BrowserPluginModule): class ServerGroupModule(BrowserPluginModule):
@ -55,13 +55,12 @@ class ServerGroupMenuItem(MenuItem):
kwargs.setdefault("type", ServerGroupModule.NODE_TYPE) kwargs.setdefault("type", ServerGroupModule.NODE_TYPE)
super(ServerGroupMenuItem, self).__init__(**kwargs) super(ServerGroupMenuItem, self).__init__(**kwargs)
@six.add_metaclass(ABCMeta)
class ServerGroupPluginModule(BrowserPluginModule): class ServerGroupPluginModule(BrowserPluginModule):
""" """
Base class for server group plugins. Base class for server group plugins.
""" """
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def get_nodes(self, *arg, **kwargs): def get_nodes(self, *arg, **kwargs):
@ -119,7 +118,7 @@ class ServerGroupView(NodeView):
user_id=current_user.id, user_id=current_user.id,
id=gid).first() id=gid).first()
data = request.form if request.form else json.loads(request.data) data = request.form if request.form else json.loads(request.data.decode())
if servergroup is None: if servergroup is None:
return make_json_response( return make_json_response(
@ -165,8 +164,7 @@ class ServerGroupView(NodeView):
) )
def create(self): def create(self):
data = request.form if request.form else json.loads(request.data) data = request.form if request.form else json.loads(request.data.decode())
if data[u'name'] != '': if data[u'name'] != '':
try: try:
sg = ServerGroup( sg = ServerGroup(
@ -177,7 +175,7 @@ class ServerGroupView(NodeView):
data[u'id'] = sg.id data[u'id'] = sg.id
data[u'name'] = sg.name data[u'name'] = sg.name
return jsonify( return jsonify(
node=self.blueprint.generate_browser_node( node=self.blueprint.generate_browser_node(
"%d" % (sg.id), "%d" % (sg.id),

View File

@ -22,7 +22,7 @@ import pgadmin.browser.server_groups as sg
from pgadmin.utils.crypto import encrypt, decrypt from pgadmin.utils.crypto import encrypt, decrypt
from pgadmin.browser import BrowserPluginModule from pgadmin.browser import BrowserPluginModule
from config import PG_DEFAULT_DRIVER from config import PG_DEFAULT_DRIVER
import six
class ServerModule(sg.ServerGroupPluginModule): class ServerModule(sg.ServerGroupPluginModule):
NODE_TYPE = "server" NODE_TYPE = "server"
@ -90,13 +90,12 @@ class ServerMenuItem(MenuItem):
blueprint = ServerModule(__name__) blueprint = ServerModule(__name__)
@six.add_metaclass(ABCMeta)
class ServerTypeModule(BrowserPluginModule): class ServerTypeModule(BrowserPluginModule):
""" """
Base class for different server types. Base class for different server types.
""" """
__metaclass__ = ABCMeta
@abstractproperty @abstractproperty
def type(self): def type(self):
@ -381,7 +380,7 @@ class ServerNode(NodeView):
u'role' u'role'
] ]
data = request.form if request.form else json.loads(request.data) data = request.form if request.form else json.loads(request.data.decode())
for arg in required_args: for arg in required_args:
if arg not in data: if arg not in data:
@ -577,7 +576,10 @@ class ServerNode(NodeView):
# TODO:: # TODO::
# Ask the password again (if existing password couldn't be # Ask the password again (if existing password couldn't be
# descrypted) # descrypted)
return internal_server_error(errormsg=e.message) if e.message:
return internal_server_error(errormsg=e.message)
else:
return internal_server_error(errormsg=str(e))
if not status: if not status:
current_app.logger.error( current_app.logger.error(

View File

@ -14,16 +14,16 @@ from collections import OrderedDict
import flask import flask
from flask.views import View, MethodViewType, with_metaclass from flask.views import View, MethodViewType, with_metaclass
from flask.ext.babel import gettext from flask.ext.babel import gettext
import six
from config import PG_DEFAULT_DRIVER from config import PG_DEFAULT_DRIVER
from pgadmin.browser import PgAdminModule from pgadmin.browser import PgAdminModule
from pgadmin.utils.ajax import make_json_response from pgadmin.utils.ajax import make_json_response
@six.add_metaclass(ABCMeta)
class NodeAttr(object): class NodeAttr(object):
""" """
""" """
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def validate(self, mode, value): def validate(self, mode, value):

View File

@ -13,7 +13,7 @@ from flask import current_app
from flask.ext.login import current_user from flask.ext.login import current_user
from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.sqlalchemy import SQLAlchemy
from settings_model import db, Setting from .settings_model import db, Setting
import traceback import traceback
from flask import Blueprint, Response, abort, request, render_template from flask import Blueprint, Response, abort, request, render_template
from flask.ext.security import login_required from flask.ext.security import login_required

View File

@ -12,7 +12,7 @@ from Crypto.Cipher import AES
from Crypto import Random from Crypto import Random
import base64 import base64
padding_string = '}' padding_string = b'}'
def encrypt(plaintext, key): def encrypt(plaintext, key):

View File

@ -9,8 +9,9 @@
from abc import ABCMeta, abstractmethod, abstractproperty from abc import ABCMeta, abstractmethod, abstractproperty
from flask import session from flask import session
from .registry import DriverRegistry from .registry import DriverRegistry
import six
@six.add_metaclass(DriverRegistry)
class BaseDriver(object): class BaseDriver(object):
""" """
class BaseDriver(object): class BaseDriver(object):
@ -40,7 +41,6 @@ class BaseDriver(object):
session, which has not been pinged from more than the idle timeout session, which has not been pinged from more than the idle timeout
configuration. configuration.
""" """
__metaclass__ = DriverRegistry
@abstractproperty @abstractproperty
def Version(cls): def Version(cls):
@ -58,7 +58,7 @@ class BaseDriver(object):
def gc(self): def gc(self):
pass pass
@six.add_metaclass(ABCMeta)
class BaseConnection(object): class BaseConnection(object):
""" """
class BaseConnection(object) class BaseConnection(object)
@ -113,7 +113,6 @@ class BaseConnection(object):
connection object for better memory management, and connection pool connection object for better memory management, and connection pool
management. management.
""" """
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def connect(self, **kwargs): def connect(self, **kwargs):

View File

@ -111,9 +111,12 @@ class Connection(BaseConnection):
) )
except psycopg2.Error as e: except psycopg2.Error as e:
msg = e.pgerror if e.pgerror else e.message \ if e.pgerror:
if e.message else e.diag.message_detail \ msg = e.pgerror
if e.diag.message_detail else str(e) elif e.diag.message_detail:
msg = e.diag.message_detail
else:
msg = str(e)
return False, msg return False, msg

View File

@ -47,7 +47,7 @@ Enter the email address and password to use for the initial pgAdmin user \
account:\n""") account:\n""")
email = '' email = ''
while email == '': while email == '':
email = raw_input("Email address: ") email = input("Email address: ")
def pprompt(): def pprompt():
return getpass.getpass(), getpass.getpass('Retype password:') return getpass.getpass(), getpass.getpass('Retype password:')