From 82828aacf6fb85b9fa895d68a352ffe1c5d0cd5e Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 6 Sep 2022 17:45:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96gogs=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/plugin/orm.py | 3 ++ class/plugin/ormDb.py | 6 +++ plugins/gogs/class/mysqlDb.py | 91 ----------------------------------- plugins/gogs/index.py | 24 ++++----- plugins/gogs/js/gogs.js | 8 +-- 5 files changed, 25 insertions(+), 107 deletions(-) delete mode 100755 plugins/gogs/class/mysqlDb.py diff --git a/class/plugin/orm.py b/class/plugin/orm.py index 49bc65c18..f2b949c54 100755 --- a/class/plugin/orm.py +++ b/class/plugin/orm.py @@ -68,6 +68,9 @@ class ORM: def setPort(self, port): self.__DB_PORT = port + def setUser(self, user): + self.__DB_USER = user + def setPwd(self, pwd): self.__DB_PASS = pwd diff --git a/class/plugin/ormDb.py b/class/plugin/ormDb.py index f747c651d..14624ccc0 100755 --- a/class/plugin/ormDb.py +++ b/class/plugin/ormDb.py @@ -77,6 +77,12 @@ class ORM: def getPwd(self): return self.__DB_PASS + def setDbName(self, name): + self.__DB_NAME = name + + def setUser(self, user): + self.__DB_USER = user + def execute(self, sql): # 执行SQL语句返回受影响行 if not self.__Conn(): diff --git a/plugins/gogs/class/mysqlDb.py b/plugins/gogs/class/mysqlDb.py deleted file mode 100755 index 4ce57da67..000000000 --- a/plugins/gogs/class/mysqlDb.py +++ /dev/null @@ -1,91 +0,0 @@ -# coding: utf-8 - -import re -import os -import sys - -# sys.path.append("/usr/local/lib/python3.6/site-packages") - - -class mysqlDb: - __DB_PASS = None - __DB_USER = 'root' - __DB_PORT = 3306 - __DB_HOST = 'localhost' - __DB_NAME = 'test' - __DB_CONN = None - __DB_CUR = None - __DB_ERR = None - __DB_CNF = '/etc/my.cnf' - - def __Conn(self): - '''连接MYSQL数据库''' - try: - socket = '/www/server/mysql/mysql.sock' - try: - import MySQLdb - except Exception as ex: - self.__DB_ERR = ex - return False - try: - self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, - port=self.__DB_PORT, db=self.__DB_NAME, charset="utf8", connect_timeout=10, unix_socket=socket) - except MySQLdb.Error as e: - self.__DB_HOST = '127.0.0.1' - self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, - port=self.__DB_PORT, db=self.__DB_NAME, charset="utf8", connect_timeout=10, unix_socket=socket) - self.__DB_CUR = self.__DB_CONN.cursor() - return True - - except MySQLdb.Error as e: - self.__DB_ERR = e - return False - - def setHost(self, host): - self.__DB_HOST = host - - def setPwd(self, pwd): - self.__DB_PASS = pwd - - def setUser(self, user): - self.__DB_USER = user - - def setPort(self, port): - self.__DB_PORT = port - - def setDb(self, name): - self.__DB_NAME = name - - def getPwd(self): - return self.__DB_PASS - - def execute(self, sql): - # 执行SQL语句返回受影响行 - if not self.__Conn(): - return self.__DB_ERR - try: - result = self.__DB_CUR.execute(sql) - self.__DB_CONN.commit() - self.__Close() - return result - except Exception as ex: - return ex - - def query(self, sql): - # 执行SQL语句返回数据集 - if not self.__Conn(): - return self.__DB_ERR - try: - self.__DB_CUR.execute(sql) - result = self.__DB_CUR.fetchall() - # 将元组转换成列表 - # data = map(list, result) - self.__Close() - return result - except Exception as ex: - return "error: " + str(ex) - - # 关闭连接 - def __Close(self): - self.__DB_CUR.close() - self.__DB_CONN.close() diff --git a/plugins/gogs/index.py b/plugins/gogs/index.py index 7450d3993..898514477 100755 --- a/plugins/gogs/index.py +++ b/plugins/gogs/index.py @@ -31,9 +31,6 @@ def getPluginName(): def getPluginDir(): return mw.getPluginDir() + '/' + getPluginName() -sys.path.append(getPluginDir() + "/class") -import mysqlDb - def getServerDir(): return mw.getServerDir() + '/' + getPluginName() @@ -235,16 +232,19 @@ def getDbConfValue(): def pMysqlDb(conf): - host = conf['HOST'].split(':') - conn = mysqlDb.mysqlDb() + # pymysql + db = mw.getMyORM() + # MySQLdb | + # db = mw.getMyORMDb() - conn.setHost(host[0]) - conn.setUser(conf['USER']) - conn.setPwd(conf['PASSWD']) - conn.setPort(int(host[1])) - conn.setDb(conf['NAME']) - return conn + db.setPort(int(host[1])) + db.setUser(conf['USER']) + db.setPwd(conf['PASSWD']) + db.setDbName(conf['NAME']) + # db.setSocket(getSocketFile()) + db.setCharset("utf8") + return db def pSqliteDb(conf): @@ -476,7 +476,7 @@ def userList(): start = (page - 1) * page_size list_count = pQuery('select count(id) as num from user') - count = list_count[0][0] + count = list_count[0]["num"] list_data = pQuery( 'select id,name,email from user order by id desc limit ' + str(start) + ',' + str(page_size)) data['list'] = mw.getPage({'count': count, 'p': page, diff --git a/plugins/gogs/js/gogs.js b/plugins/gogs/js/gogs.js index e6318cc8c..abf8d8f32 100755 --- a/plugins/gogs/js/gogs.js +++ b/plugins/gogs/js/gogs.js @@ -163,11 +163,11 @@ function gogsUserList(page, search) { ulist = rdata['data']['data']; for (i in ulist){ - email = ulist[i][2] == '' ? '无' : ulist[i][2]; - content += ''+ulist[i][0]+''+ - ''+ulist[i][1]+''+ + email = ulist[i]["email"] == '' ? '无' : ulist[i]["email"]; + content += ''+ulist[i]["id"]+''+ + ''+ulist[i]["name"]+''+ ''+email+''+ - '项目管理'+ + '项目管理'+ ''; }