mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-24 07:16:52 -06:00
First round of Python 3 compatibility fixes.
This commit is contained in:
parent
da6043e7a5
commit
209ee78b25
@ -32,20 +32,20 @@ if config.SERVER_MODE is True:
|
||||
local_config = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||
'config_local.py')
|
||||
if not os.path.isfile(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 "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 "settings. Exiting..."
|
||||
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("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("settings. Exiting...")
|
||||
sys.exit(1)
|
||||
|
||||
# Check if the database exists. If it does not, tell the user and exit.
|
||||
if not os.path.isfile(config.SQLITE_PATH):
|
||||
print "The configuration database %s does not exist.\n" \
|
||||
% config.SQLITE_PATH
|
||||
print "Please run 'python %s' to create it.\nExiting..." % os.path.join(
|
||||
print("The configuration database %s does not exist.\n" \
|
||||
% config.SQLITE_PATH)
|
||||
print("Please run 'python %s' to create it.\nExiting..." % os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)), 'setup.py'
|
||||
)
|
||||
))
|
||||
sys.exit(1)
|
||||
|
||||
##########################################################################
|
||||
|
@ -16,7 +16,7 @@ from flask.ext.security import Security, SQLAlchemyUserDatastore
|
||||
from flask_security.utils import login_user
|
||||
from flask_mail import Mail
|
||||
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 werkzeug.local import LocalProxy
|
||||
from pgadmin.utils import PgAdminModule, driver
|
||||
@ -40,9 +40,9 @@ class PgAdmin(Flask):
|
||||
continue
|
||||
self.logger.info('Examining potential module: %s' % module_name)
|
||||
module = import_module(module_name)
|
||||
for key, value in module.__dict__.items():
|
||||
if isinstance(value, PgAdminModule):
|
||||
yield value
|
||||
for key in list(module.__dict__.keys()):
|
||||
if isinstance(module.__dict__[key], PgAdminModule):
|
||||
yield module.__dict__[key]
|
||||
|
||||
@property
|
||||
def submodules(self):
|
||||
|
@ -16,10 +16,10 @@ from flask.ext.security import login_required
|
||||
from flask.ext.login import current_user
|
||||
from flask.ext.babel import gettext
|
||||
from flaskext.gravatar import Gravatar
|
||||
import six
|
||||
|
||||
MODULE_NAME = 'browser'
|
||||
|
||||
|
||||
class BrowserModule(PgAdminModule):
|
||||
|
||||
def get_own_stylesheets(self):
|
||||
@ -136,20 +136,18 @@ class BrowserModule(PgAdminModule):
|
||||
|
||||
for module in self.submodules:
|
||||
scripts.extend(module.get_own_javascripts())
|
||||
|
||||
return scripts
|
||||
|
||||
|
||||
blueprint = BrowserModule(MODULE_NAME, __name__)
|
||||
|
||||
|
||||
@six.add_metaclass(ABCMeta)
|
||||
class BrowserPluginModule(PgAdminModule):
|
||||
"""
|
||||
Base class for browser submodules.
|
||||
"""
|
||||
|
||||
browser_url_prefix = blueprint.url_prefix + '/'
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self, import_name, **kwargs):
|
||||
kwargs.setdefault("url_prefix", self.node_path)
|
||||
@ -178,7 +176,6 @@ class BrowserPluginModule(PgAdminModule):
|
||||
|
||||
for module in self.submodules:
|
||||
scripts.extend(module.get_own_javascripts())
|
||||
|
||||
return scripts
|
||||
|
||||
def generate_browser_node(
|
||||
@ -213,7 +210,6 @@ class BrowserPluginModule(PgAdminModule):
|
||||
|
||||
for submodule in self.submodules:
|
||||
snippets.extend(submodule.csssnippets)
|
||||
|
||||
return snippets
|
||||
|
||||
@abstractmethod
|
||||
|
@ -21,7 +21,7 @@ from pgadmin.browser import BrowserPluginModule
|
||||
from pgadmin.utils.menu import MenuItem
|
||||
from pgadmin.settings.settings_model import db, ServerGroup
|
||||
from pgadmin.browser.utils import NodeView
|
||||
|
||||
import six
|
||||
|
||||
class ServerGroupModule(BrowserPluginModule):
|
||||
|
||||
@ -55,13 +55,12 @@ class ServerGroupMenuItem(MenuItem):
|
||||
kwargs.setdefault("type", ServerGroupModule.NODE_TYPE)
|
||||
super(ServerGroupMenuItem, self).__init__(**kwargs)
|
||||
|
||||
|
||||
@six.add_metaclass(ABCMeta)
|
||||
class ServerGroupPluginModule(BrowserPluginModule):
|
||||
"""
|
||||
Base class for server group plugins.
|
||||
"""
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
@abstractmethod
|
||||
def get_nodes(self, *arg, **kwargs):
|
||||
@ -119,7 +118,7 @@ class ServerGroupView(NodeView):
|
||||
user_id=current_user.id,
|
||||
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:
|
||||
return make_json_response(
|
||||
@ -165,8 +164,7 @@ class ServerGroupView(NodeView):
|
||||
)
|
||||
|
||||
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'] != '':
|
||||
try:
|
||||
sg = ServerGroup(
|
||||
@ -177,7 +175,7 @@ class ServerGroupView(NodeView):
|
||||
|
||||
data[u'id'] = sg.id
|
||||
data[u'name'] = sg.name
|
||||
|
||||
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
"%d" % (sg.id),
|
||||
|
@ -22,7 +22,7 @@ import pgadmin.browser.server_groups as sg
|
||||
from pgadmin.utils.crypto import encrypt, decrypt
|
||||
from pgadmin.browser import BrowserPluginModule
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
|
||||
import six
|
||||
|
||||
class ServerModule(sg.ServerGroupPluginModule):
|
||||
NODE_TYPE = "server"
|
||||
@ -90,13 +90,12 @@ class ServerMenuItem(MenuItem):
|
||||
|
||||
blueprint = ServerModule(__name__)
|
||||
|
||||
|
||||
@six.add_metaclass(ABCMeta)
|
||||
class ServerTypeModule(BrowserPluginModule):
|
||||
"""
|
||||
Base class for different server types.
|
||||
"""
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
@abstractproperty
|
||||
def type(self):
|
||||
@ -381,7 +380,7 @@ class ServerNode(NodeView):
|
||||
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:
|
||||
if arg not in data:
|
||||
@ -577,7 +576,10 @@ class ServerNode(NodeView):
|
||||
# TODO::
|
||||
# Ask the password again (if existing password couldn't be
|
||||
# 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:
|
||||
current_app.logger.error(
|
||||
|
@ -14,16 +14,16 @@ from collections import OrderedDict
|
||||
import flask
|
||||
from flask.views import View, MethodViewType, with_metaclass
|
||||
from flask.ext.babel import gettext
|
||||
import six
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser import PgAdminModule
|
||||
from pgadmin.utils.ajax import make_json_response
|
||||
|
||||
|
||||
@six.add_metaclass(ABCMeta)
|
||||
class NodeAttr(object):
|
||||
"""
|
||||
"""
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
@abstractmethod
|
||||
def validate(self, mode, value):
|
||||
|
@ -13,7 +13,7 @@ from flask import current_app
|
||||
from flask.ext.login import current_user
|
||||
from flask.ext.sqlalchemy import SQLAlchemy
|
||||
|
||||
from settings_model import db, Setting
|
||||
from .settings_model import db, Setting
|
||||
import traceback
|
||||
from flask import Blueprint, Response, abort, request, render_template
|
||||
from flask.ext.security import login_required
|
||||
|
@ -12,7 +12,7 @@ from Crypto.Cipher import AES
|
||||
from Crypto import Random
|
||||
import base64
|
||||
|
||||
padding_string = '}'
|
||||
padding_string = b'}'
|
||||
|
||||
|
||||
def encrypt(plaintext, key):
|
||||
|
@ -9,8 +9,9 @@
|
||||
from abc import ABCMeta, abstractmethod, abstractproperty
|
||||
from flask import session
|
||||
from .registry import DriverRegistry
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(DriverRegistry)
|
||||
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
|
||||
configuration.
|
||||
"""
|
||||
__metaclass__ = DriverRegistry
|
||||
|
||||
@abstractproperty
|
||||
def Version(cls):
|
||||
@ -58,7 +58,7 @@ class BaseDriver(object):
|
||||
def gc(self):
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(ABCMeta)
|
||||
class BaseConnection(object):
|
||||
"""
|
||||
class BaseConnection(object)
|
||||
@ -113,7 +113,6 @@ class BaseConnection(object):
|
||||
connection object for better memory management, and connection pool
|
||||
management.
|
||||
"""
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
@abstractmethod
|
||||
def connect(self, **kwargs):
|
||||
|
@ -111,9 +111,12 @@ class Connection(BaseConnection):
|
||||
)
|
||||
|
||||
except psycopg2.Error as e:
|
||||
msg = e.pgerror if e.pgerror else e.message \
|
||||
if e.message else e.diag.message_detail \
|
||||
if e.diag.message_detail else str(e)
|
||||
if e.pgerror:
|
||||
msg = e.pgerror
|
||||
elif e.diag.message_detail:
|
||||
msg = e.diag.message_detail
|
||||
else:
|
||||
msg = str(e)
|
||||
|
||||
return False, msg
|
||||
|
||||
|
@ -47,7 +47,7 @@ Enter the email address and password to use for the initial pgAdmin user \
|
||||
account:\n""")
|
||||
email = ''
|
||||
while email == '':
|
||||
email = raw_input("Email address: ")
|
||||
email = input("Email address: ")
|
||||
|
||||
def pprompt():
|
||||
return getpass.getpass(), getpass.getpass('Retype password:')
|
||||
|
Loading…
Reference in New Issue
Block a user