1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-08 18:59:03 +00:00

Modify scripts to support python3.

This commit is contained in:
ly1217
2019-08-15 21:11:18 -07:00
parent 5d555a8d24
commit e0b4a11667
20 changed files with 124 additions and 1443 deletions

View File

@@ -2,14 +2,14 @@
import sys
import os
import ConfigParser
import configparser
import glob
HAS_MYSQLDB = True
HAS_PYMYSQL = True
try:
import MySQLdb
import pymysql
except ImportError:
HAS_MYSQLDB = False
HAS_PYMYSQL = False
HAS_SQLITE3 = True
try:
@@ -41,15 +41,15 @@ class Utils(object):
@staticmethod
def info(msg):
print Utils.highlight('[INFO] ') + msg
print(Utils.highlight('[INFO] ') + msg)
@staticmethod
def warning(msg):
print Utils.highlight('[WARNING] ') + msg
print(Utils.highlight('[WARNING] ') + msg)
@staticmethod
def error(msg):
print Utils.highlight('[ERROR] ') + msg
print(Utils.highlight('[ERROR] ') + msg)
sys.exit(1)
@staticmethod
@@ -57,7 +57,7 @@ class Utils(object):
if not os.path.exists(config_path):
Utils.error('Config path %s doesn\'t exist, stop db upgrade' %
config_path)
cp = ConfigParser.ConfigParser(defaults)
cp = configparser.ConfigParser(defaults)
cp.read(config_path)
return cp
@@ -87,8 +87,8 @@ class DBUpdater(object):
if ccnet_db_info and seafile_db_info and seahub_db_info:
Utils.info('You are using MySQL')
if not HAS_MYSQLDB:
Utils.error('Python MySQLdb module is not found')
if not HAS_PYMYSQL:
Utils.error('Python pymysql module is not found')
updater = MySQLDBUpdater(version, ccnet_db_info, seafile_db_info, seahub_db_info)
elif (ccnet_db_info is None) and (seafile_db_info is None) and (seahub_db_info is None):
@@ -162,7 +162,7 @@ class DBUpdater(object):
password = config.get(db_section, 'PASSWD')
db = config.get(db_section, 'DB')
unix_socket = config.get(db_section, 'UNIX_SOCKET')
except ConfigParser.NoOptionError, e:
except configparser.NoOptionError as e:
Utils.error('Database config in ccnet.conf is invalid: %s' % e)
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
@@ -198,7 +198,7 @@ class DBUpdater(object):
password = config.get(db_section, 'password')
db = config.get(db_section, 'db_name')
unix_socket = config.get(db_section, 'unix_socket')
except ConfigParser.NoOptionError, e:
except configparser.NoOptionError as e:
Utils.error('Database config in seafile.conf is invalid: %s' % e)
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
@@ -211,7 +211,7 @@ class DBUpdater(object):
sys.path.insert(0, env_mgr.central_config_dir)
try:
import seahub_settings # pylint: disable=F0401
except ImportError, e:
except ImportError as e:
Utils.error('Failed to import seahub_settings.py: %s' % e)
if not hasattr(seahub_settings, 'DATABASES'):
@@ -336,9 +336,9 @@ class MySQLDBUpdater(DBUpdater):
kw['host'] = info.host
kw['port'] = info.port
try:
conn = MySQLdb.connect(**kw)
except Exception, e:
if isinstance(e, MySQLdb.OperationalError):
conn = pymysql.connect(**kw)
except Exception as e:
if isinstance(e, pymysql.err.OperationalError):
msg = str(e.args[1])
else:
msg = str(e)
@@ -351,7 +351,7 @@ class MySQLDBUpdater(DBUpdater):
try:
cursor.execute(sql)
conn.commit()
except Exception, e:
except Exception as e:
msg = str(e)
Utils.warning('Failed to execute sql: %s' % msg)
@@ -372,7 +372,7 @@ class MySQLDBUpdater(DBUpdater):
def main():
skipdb = os.environ.get('SEAFILE_SKIP_DB_UPGRADE', '').lower()
if skipdb in ('1', 'true', 'on'):
print 'Database upgrade skipped because SEAFILE_SKIP_DB_UPGRADE=%s' % skipdb
print('Database upgrade skipped because SEAFILE_SKIP_DB_UPGRADE=%s' % skipdb)
sys.exit()
version = sys.argv[1]
db_updater = DBUpdater.get_instance(version)