From 2a0095495417429e4bc815807828c919689ad6f7 Mon Sep 17 00:00:00 2001 From: kunkun Date: Tue, 12 May 2020 01:40:43 +0800 Subject: [PATCH 01/52] kun --- setup.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4601c2d --- /dev/null +++ b/setup.py @@ -0,0 +1,59 @@ + +# python setup.py sdist upload +# twine upload --repository-url https://test.pypi.org/legacy/ dist/* #上传到测试 +# pip install --index-url https://test.pypi.org/simple/ kcweb #安装测试服务上的kcweb +############################################# +from setuptools import setup, find_packages,Extension +import os +def file_get_content(k): + "获取文件内容" + if os.path.isfile(k): + f=open(k,'r',encoding="utf-8") + con=f.read() + f.close() + else: + con='' + return con +confkcw={} +confkcw['name']='kcweb' #项目的名称 +confkcw['version']='2.40.7' #项目版本 +confkcw['description']='基于python后端开发框架' #项目的简单描述 +confkcw['long_description']="完整文档:http://intapp.kwebapp.cn/index/index/doc/docde/1" #项目详细描述 +confkcw['license']='MIT License' #开源协议 mit开源 +confkcw['url']='http://intapp.kwebapp.cn/index/index/doc/docde/1' +confkcw['author']='禄可集团-坤坤' #名字 +confkcw['author_email']='fk1402936534@qq.com' #邮件地址 +confkcw['maintainer']='坤坤' #维护人员的名字 +confkcw['maintainer_email']='fk1402936534@qq.com' #维护人员的邮件地址 +def get_file(folder='./',lists=[]): + lis=os.listdir(folder) + for files in lis: + if not os.path.isfile(folder+"/"+files): + if files=='__pycache__' or files=='.git': + pass + else: + lists.append(folder+"/"+files) + get_file(folder+"/"+files,lists) + else: + pass + return lists +b=get_file("kcweb",['kcweb']) +setup( + name = confkcw["name"], + version = confkcw["version"], + keywords = "kcweb"+confkcw['version'], + description = confkcw["description"], + long_description = confkcw["long_description"], + license = confkcw["license"], + author = confkcw["author"], + author_email = confkcw["author_email"], + maintainer = confkcw["maintainer"], + maintainer_email = confkcw["maintainer_email"], + url=confkcw['url'], + packages = b, + # install_requires = ['pymongo==3.10.0','six==1.12.0','requests==2.22.0','watchdog==0.9.0','Mako==1.1.0','paramiko==2.6.0','webssh==1.4.5'], #第三方包 + install_requires = ['pymongo>=3.10.0','Mako>=1.1.2','requests>=2.23.0','six>=1.12.0','watchdog>=0.9.0'], #第三方包 + package_data = { + '': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'], + } +) \ No newline at end of file -- Gitee From 056b25fb2e3a6e1294619f97040f07bb9ef00aa8 Mon Sep 17 00:00:00 2001 From: kunkun Date: Tue, 12 May 2020 03:48:47 +0800 Subject: [PATCH 02/52] kun --- config/__init__.py | 2 +- setup.py | 6 +++--- utill/queues.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index 554752a..99cdd5c 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -88,7 +88,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='2.40.7' #项目版本 +kcweb['version']='2.40.8' #项目版本 kcweb['description']='基于python后端开发框架' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index 4601c2d..b90f088 100644 --- a/setup.py +++ b/setup.py @@ -16,11 +16,11 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='2.40.7' #项目版本 +confkcw['version']='2.40.8' #项目版本 confkcw['description']='基于python后端开发框架' #项目的简单描述 -confkcw['long_description']="完整文档:http://intapp.kwebapp.cn/index/index/doc/docde/1" #项目详细描述 +confkcw['long_description']="完整文档:http://intapp.kwebapp.cn/doc/docde?id=1" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -confkcw['url']='http://intapp.kwebapp.cn/index/index/doc/docde/1' +confkcw['url']='http://intapp.kwebapp.cn/doc/docde?id=1' confkcw['author']='禄可集团-坤坤' #名字 confkcw['author_email']='fk1402936534@qq.com' #邮件地址 confkcw['maintainer']='坤坤' #维护人员的名字 diff --git a/utill/queues.py b/utill/queues.py index 5dd9d70..c25980c 100644 --- a/utill/queues.py +++ b/utill/queues.py @@ -29,7 +29,7 @@ class Queues(): if not os.path.isfile(queuesdbpath): t=model_task() t.create_table() - kcwsqlite.sqlite().connect(queuesdbpath).table("Queues").where(True).delete() + kcwsqlite.sqlite().connect(queuesdbpath).table("Queues").where("id","gt",0).delete() while True: if not Queues.__globalqueue.empty(): value=Queues.__globalqueue.get() -- Gitee From 7dd1718865fcf3cbaa6bd546e8d22b3b7aa1a9f0 Mon Sep 17 00:00:00 2001 From: kunkun Date: Tue, 12 May 2020 18:00:03 +0800 Subject: [PATCH 03/52] kun --- utill/queues.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/utill/queues.py b/utill/queues.py index c25980c..68566ff 100644 --- a/utill/queues.py +++ b/utill/queues.py @@ -21,10 +21,11 @@ class model_task(model.model): class Queues(): __globalqueue=None def start(): - Queues.__globalqueue=Queue() - t=threading.Thread(target=Queues.__messagequeue) - t.daemon=True - t.start() + if not Queues.__globalqueue: + Queues.__globalqueue=Queue() + t=threading.Thread(target=Queues.__messagequeue) + t.daemon=True + t.start() def __messagequeue(): if not os.path.isfile(queuesdbpath): t=model_task() @@ -73,6 +74,8 @@ class Queues(): taskid=m.hexdigest() task={"taskid":taskid,"title":title,"describes":describes,"code":2,"msg":msg,"error":"","addtime":ttt} key={"target":target,"args":args,"task":task} + if not Queues.__globalqueue: + Queues.__globalqueue=Queue() Queues.__globalqueue.put(key) kcwsqlite.sqlite().connect(queuesdbpath).table("Queues").insert(task) return taskid @@ -95,7 +98,9 @@ class Queues(): taskid 任务id """ - if not os.path.isfile(queuesdbpath): - t=model_task() - t.create_table() + if not Queues.__globalqueue: + Queues.__globalqueue=Queue() + t=threading.Thread(target=Queues.__messagequeue) + t.daemon=True + t.start() return kcwsqlite.sqlite().connect(queuesdbpath).table("Queues").field("taskid,title,describes,code,msg,error,addtime").where("taskid",taskid).find() \ No newline at end of file -- Gitee From 2b40a47f75d338d444441384f843856db66b796e Mon Sep 17 00:00:00 2001 From: kunkun Date: Fri, 15 May 2020 22:09:52 +0800 Subject: [PATCH 04/52] kun --- utill/db/mongodb.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/utill/db/mongodb.py b/utill/db/mongodb.py index 960eaa4..bc7bf7a 100644 --- a/utill/db/mongodb.py +++ b/utill/db/mongodb.py @@ -294,15 +294,30 @@ class mongo: 参数 length:int 查询数量 """ + offset=int(offset) + length=int(length) if length==None: length=offset offset=0 - elif offset > 0: - offset=offset*length-length + # elif offset > 0: + # offset=offset*length-length self.__limit=[offset,length] return self - # def order(self,k): - # pass + def page(self,offset, length = None): + """设置分页查询 + + 参数 offset:int 页码 + + 参数 length:int 页面数量 + """ + offset=int(offset) + length=int(length) + if length==None: + length=offset + offset=0 + elif offset > 0: + offset=offset*length-length + self.__limit=[ def __operator(self,strs): """运算符转换 参数 strs 待转的字符串 -- Gitee From f38596801334aef4dcaa8cc9b5a269aa5a774fef Mon Sep 17 00:00:00 2001 From: kunkun Date: Fri, 15 May 2020 22:10:37 +0800 Subject: [PATCH 05/52] kun --- utill/db/mongodb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utill/db/mongodb.py b/utill/db/mongodb.py index bc7bf7a..5e5fb11 100644 --- a/utill/db/mongodb.py +++ b/utill/db/mongodb.py @@ -317,7 +317,8 @@ class mongo: offset=0 elif offset > 0: offset=offset*length-length - self.__limit=[ + self.__limit=[offset,length] + return self def __operator(self,strs): """运算符转换 参数 strs 待转的字符串 -- Gitee From aa8614199dcc068b0355ac42c50ffb890691490d Mon Sep 17 00:00:00 2001 From: kunkun Date: Sun, 24 May 2020 07:43:37 +0800 Subject: [PATCH 06/52] kun --- Events.py | 1 + app.py | 32 +-- application/api/controller/__init__.py | 2 +- .../api/controller/{v1 => plug}/__init__.py | 0 application/api/controller/plug/index.py | 8 + .../api/controller/{v2 => plug1}/__init__.py | 0 .../api/controller/{v1 => plug1}/index.py | 2 +- application/api/controller/plug2/__init__.py | 4 + .../api/controller/{v2 => plug2}/index.py | 4 +- .../api/tpl/{v1 => plug1}/index/index.html | 2 +- .../api/tpl/{v2 => plug2}/index/index.html | 2 +- application/config/other.py | 2 +- common/autoload.py | 205 +++++++++++++++++- config/__init__.py | 4 +- create.py | 95 -------- setup.py | 1 - utill/db/mongodb.py | 29 ++- 17 files changed, 257 insertions(+), 136 deletions(-) rename application/api/controller/{v1 => plug}/__init__.py (100%) create mode 100644 application/api/controller/plug/index.py rename application/api/controller/{v2 => plug1}/__init__.py (100%) rename application/api/controller/{v1 => plug1}/index.py (65%) create mode 100644 application/api/controller/plug2/__init__.py rename application/api/controller/{v2 => plug2}/index.py (41%) rename application/api/tpl/{v1 => plug1}/index/index.html (95%) rename application/api/tpl/{v2 => plug2}/index/index.html (95%) delete mode 100644 create.py diff --git a/Events.py b/Events.py index 574d83f..9993b28 100644 --- a/Events.py +++ b/Events.py @@ -10,6 +10,7 @@ class MyFileSystemEventHander(FileSystemEventHandler): def on_any_event(self, event): if event.src_path.endswith('.py'): print('* 更新文件:%s' % event.src_path) + time.sleep(0.2) self.restart() class Events: command = ['echo', 'ok'] diff --git a/app.py b/app.py index 53cb075..6d6f56f 100644 --- a/app.py +++ b/app.py @@ -222,11 +222,11 @@ class web: routedefault=route['default'] methods=route['methods'] if routedefault: - edition='index' + plug='index' files=route['files'] funct=route['funct'] else: - edition='' + plug='' files='' funct='' param=[] @@ -236,8 +236,8 @@ class web: ##默认路由start ################################################################################# if modular: - if route['edition']: #匹配模块并且匹配了版本 - edition=route['edition'] + if route['plug']: #匹配模块并且匹配了插件 + plug=route['plug'] routedefault,PATH_INFO=web.__getconfigroute( self, PATH_INFO, @@ -255,7 +255,7 @@ class web: else: param.append(urllib.parse.unquote(path)) i+=1 - else: #配置模块没有配置版本 + else: #配置模块没有配置插件 routedefault,PATH_INFO=web.__getconfigroute( self, PATH_INFO, @@ -265,7 +265,7 @@ class web: for path in PATH_INFO: if path: if i==0: - edition=path + plug=path elif i==1: files=path urls=urls+"/"+str(path) @@ -275,8 +275,8 @@ class web: else: param.append(urllib.parse.unquote(path)) i+=1 - elif route['edition']: #配置版本的但没有匹配模块 - edition=route['edition'] + elif route['plug']: #配置版本的但没有匹配插件 + plug=route['plug'] routedefault,PATH_INFO=web.__getconfigroute( self, PATH_INFO, @@ -304,7 +304,7 @@ class web: if i==0: modular=path elif i==1: - edition=path + plug=path elif i==2: files=path urls=urls+"/"+str(path) @@ -315,7 +315,7 @@ class web: param.append(urllib.parse.unquote(path)) i+=1 #默认路由end ############################################################ - return methods,modular,edition,files,funct,tuple(param) + return methods,modular,plug,files,funct,tuple(param) def __tran(self,data,status,resheader): "转换控制器返回的内容" if isinstance(data,tuple): @@ -362,7 +362,7 @@ class web: PATH_INFO=header['PATH_INFO'].split('/') if PATH_INFO[0]==' ' or PATH_INFO[0]=='': del PATH_INFO[0] - methods,modular,edition,files,funct,param=web.defaultroute(self,header,PATH_INFO) + methods,modular,plug,files,funct,param=web.defaultroute(self,header,PATH_INFO) if header['REQUEST_METHOD'] in methods: try: obj=getattr(web.__appname,modular) @@ -385,9 +385,9 @@ class web: ) else: try: - obj=getattr(obj,edition) + obj=getattr(obj,plug) except (AttributeError,UnboundLocalError) as e: - con="无法找到目录:"+str(modular)+"/controller/"+str(edition)+"/" + con="无法找到目录:"+str(modular)+"/controller/"+str(plug)+"/" try: data=getattr(obj,"error")(e,con) body,status,resheader=web.__tran( @@ -416,7 +416,7 @@ class web: try: obj=getattr(obj,files) except (AttributeError,UnboundLocalError) as e: - con="无法找到文件:"+str(modular)+"/controller/"+str(edition)+"/"+str(files)+".py" + con="无法找到文件:"+str(modular)+"/controller/"+str(plug)+"/"+str(files)+".py" try: data=getattr(obj,"error")(e,con) body,status,resheader=web.__tran( @@ -697,7 +697,7 @@ class web: print(HTTP_HOST+' -- ['+str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))+'] "'+REQUEST_METHOD+" "+RAW_URI +" "+SERVER_PROTOCOL + '" '+status+"-") t=time.time() - header+="Server:kcweb\n" + header+="Server:kcweb"+str(config.kcweb['version'])+"\n" header+="Date:%s\n" % datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT') for t in resheader: header+="%s:%s\n" % (t[0],t[1]) @@ -808,7 +808,7 @@ class web: print(HTTP_HOST+' -- ['+str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))+'] "'+REQUEST_METHOD+" "+RAW_URI +" "+SERVER_PROTOCOL + '" '+status+"-") t=time.time() - header+="Server:kcweb\n" + header+="Server:kcweb"+str(config.kcweb['version'])+"\n" header+="Date:%s\n" % datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT') for t in resheader: header+="%s:%s\n" % (t[0],t[1]) diff --git a/application/api/controller/__init__.py b/application/api/controller/__init__.py index 5ab9848..6de7530 100644 --- a/application/api/controller/__init__.py +++ b/application/api/controller/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from . import v1,v2 +from . import plug,plug1,plug2 # def error(err,data): # "该函数在当前目录下无法匹配时被调用" # return data,"200",{"Content-Type":"text/json; charset=utf-8"} \ No newline at end of file diff --git a/application/api/controller/v1/__init__.py b/application/api/controller/plug/__init__.py similarity index 100% rename from application/api/controller/v1/__init__.py rename to application/api/controller/plug/__init__.py diff --git a/application/api/controller/plug/index.py b/application/api/controller/plug/index.py new file mode 100644 index 0000000..b7eedd7 --- /dev/null +++ b/application/api/controller/plug/index.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from ${appname}.${modular}.common import * +def inter(id='',title=""): + data={ + 'title':title, + 'id':id + } + return successjson(data) \ No newline at end of file diff --git a/application/api/controller/v2/__init__.py b/application/api/controller/plug1/__init__.py similarity index 100% rename from application/api/controller/v2/__init__.py rename to application/api/controller/plug1/__init__.py diff --git a/application/api/controller/v1/index.py b/application/api/controller/plug1/index.py similarity index 65% rename from application/api/controller/v1/index.py rename to application/api/controller/plug1/index.py index 80b47d4..bc863e5 100644 --- a/application/api/controller/v1/index.py +++ b/application/api/controller/plug1/index.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from ${appname}.${modular}.common import * def index(): - return tpl("/v1/index/index.html",title="欢迎使用kcweb框架",data=['这是${appname}应用${modular}模块下v1版本的一个模板渲染测试效果']) + return tpl("/plug1/index/index.html",title="欢迎使用kcweb框架",data=['这是${appname}应用${modular}模块下plug插件的一个模板渲染测试效果']) def inter(id='',title=""): data={ 'title':title, diff --git a/application/api/controller/plug2/__init__.py b/application/api/controller/plug2/__init__.py new file mode 100644 index 0000000..ab68b08 --- /dev/null +++ b/application/api/controller/plug2/__init__.py @@ -0,0 +1,4 @@ +from . import index +# def error(err,data): +# "该函数在找不到模块时执行函数时和框架报错时被调用" +# return str(err) \ No newline at end of file diff --git a/application/api/controller/v2/index.py b/application/api/controller/plug2/index.py similarity index 41% rename from application/api/controller/v2/index.py rename to application/api/controller/plug2/index.py index 25d4d39..679977c 100644 --- a/application/api/controller/v2/index.py +++ b/application/api/controller/plug2/index.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- from ${appname}.${modular}.common import * def index(): - return tpl("/v2/index/index.html",title="欢迎使用kcweb框架",data=['这是${appname}应用${modular}模块下v2版本的一个模板渲染测试效果']) + return tpl("/plug2/index/index.html",title="欢迎使用kcweb框架",data=['这是${appname}应用${modular}模块下plug2版本的一个模板渲染测试效果']) def inter(): data={ 'title':'欢迎使用kcweb框架', - 'desc':'这是${appname}应用${modular}模块下v2版本的json输出效果' + 'desc':'这是${appname}应用${modular}模块下plug2版本的json输出效果' } return successjson(data) \ No newline at end of file diff --git a/application/api/tpl/v1/index/index.html b/application/api/tpl/plug1/index/index.html similarity index 95% rename from application/api/tpl/v1/index/index.html rename to application/api/tpl/plug1/index/index.html index f4818f5..5110512 100644 --- a/application/api/tpl/v1/index/index.html +++ b/application/api/tpl/plug1/index/index.html @@ -10,7 +10,7 @@
-

这是v1模板文件

+

这是plug1模板文件

% if title:

${title}

% endif diff --git a/application/api/tpl/v2/index/index.html b/application/api/tpl/plug2/index/index.html similarity index 95% rename from application/api/tpl/v2/index/index.html rename to application/api/tpl/plug2/index/index.html index f331dab..c8b3513 100644 --- a/application/api/tpl/v2/index/index.html +++ b/application/api/tpl/plug2/index/index.html @@ -10,7 +10,7 @@
-

这是v2模板文件

+

这是plug2模板文件

% if title:

${title}

% endif diff --git a/application/config/other.py b/application/config/other.py index 1e4e433..e2b9dc5 100644 --- a/application/config/other.py +++ b/application/config/other.py @@ -3,7 +3,7 @@ from kcweb.config import * #路由配置 route['default']=True #是否开启默认路由 默认路由开启后面不影响以下配置的路由,模块名/版本名/控制器文件名/方法名 作为路由地址 如:http://www.kcw.com/api/v1/index/index/ route['modular']='${modular}' -route['edition']='v1' +route['plug']='plug1' route['files']='index' #默认路由文件(控制器) route['funct']='index' #默认路由函数 (操作方法) route['methods']=['POST','GET'] #默认请求方式 diff --git a/common/autoload.py b/common/autoload.py index 4b917d1..dbcc8ce 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import time,hashlib,json,re,os,platform +import time,hashlib,json,re,os,platform,sys,shutil,zipfile import datetime as core_datetime from kcweb import config from kcweb.utill.dateutil.relativedelta import relativedelta as core_relativedelta @@ -16,7 +16,6 @@ import smtplib from email.mime.text import MIMEText from email.utils import formataddr from . import globals - redis=kcwredis() def send_mail(user,text="邮件内容",theme="邮件主题",recNick="收件人昵称"): """发送邮件 @@ -257,14 +256,8 @@ def dateoperator(date,years=0,formats='%Y%m%d%H%M%S',months=0, days=0, hours=0, strs=strs.strftime(formats) return strs def get_folder(): - '获取当前框架所在目录' - path=os.path.split(os.path.realpath(__file__))[0] #当前文件目录 - framepath=path.split('\\') ##框架主目录 - s='' - for k in framepath: - s=s+'/'+k - framepath=s[1:] - return re.sub('/kcw/common','',framepath) #包所在目录 + '获取当前框架目录' + return os.path.split(os.path.realpath(__file__))[0][:-7] #当前框架目录 # aa=[] def get_file(folder='./',is_folder=True,suffix="*",lists=[],append=False): """获取文件夹下所有文件夹和文件 @@ -320,4 +313,194 @@ def list_to_tree(data, pk = 'id', pid = 'pid', child = 'lowerlist', root=0,child if kkkk: v[child]=kkkk arr.append(v) - return arr \ No newline at end of file + return arr +class zip: + def packzip(dirname,zipfilename): + filelist = [] + if os.path.isfile(dirname): + filelist.append(dirname) + for root, dirs, files in os.walk(dirname): + for name in files: + filelist.append(os.path.join(root, name)) + zf = zipfile.ZipFile(zipfilename, "w", zipfile.zlib.DEFLATED) + for tar in filelist: + arcname = tar[len(dirname):] + #print arcname + zf.write(tar,arcname) + zf.close() + def unzip_file(zipfilename, unziptodir): + zf = zipfile.ZipFile(zipfilename) + zf.extractall(unziptodir) + zf.close() +class create: + appname=None + modular=None + path=get_folder() #当前框架目录 + def __init__(self,appname="app",modular="api"): + self.appname=str(appname) + self.modular=str(modular) + def uninstallplug(self,plug): + """卸载插件 + + plug 插件名 + """ + f=open(self.appname+"/"+self.modular+"/controller/__init__.py","r",encoding='utf-8') + text=f.read() + f.close() + f=open(self.appname+"/"+self.modular+"/controller/__init__.py","w",encoding='utf-8') + text=re.sub("from . import "+plug,"",text) + f.write(text) + f.close() + shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug) + return True + def packplug(self,plug): + """打包插件 + + plug 插件名 + """ + """打包模块""" + if os.path.exists(self.appname+"/"+self.modular+"/controller/"+plug): + zip.packzip(self.appname+"/"+self.modular+"/controller/"+plug,self.appname+"/"+self.modular+"/controller/"+plug+".zip") + return True + else: + return False + def installplug(self,plug): + """创建一个插件,如果您的模块目录下没有插件包,则创建默认插件文件 + + plug 插件名 + """ + plug=str(plug) + if os.path.exists(self.appname+"/"+self.modular+"/controller/"+plug): + raise Exception("该插件已存在") + else: + if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 + zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + else:#安装默认插件 + if not os.path.exists(self.appname+"/"+self.modular+"/controller/"+plug): + os.makedirs(self.appname+"/"+self.modular+"/controller/"+plug) + content=Templates(self.path+"/application/api/controller/plug/__init__.py",appname=self.appname,modular=self.modular) + f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/__init__.py","a",encoding='utf-8') + f.write(content) + f.close() + content=Templates(self.path+"/application/api/controller/plug/index.py",appname=self.appname,modular=self.modular) + f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/index.py","a",encoding='utf-8') + f.write(content) + f.close() + content="\nfrom . import "+plug + f=open(self.appname+"/"+self.modular+"/controller/__init__.py","a",encoding='utf-8') + f.write(content) + f.close() + return True + def uninstallmodular(self): + "卸载模块" + f=open(self.appname+"/__init__.py","r") + text=f.read() + f.close() + f=open(self.appname+"/__init__.py","w") + text=re.sub("from . import "+self.modular,"",text) + f.write(text) + f.close() + shutil.rmtree(self.appname+"/"+self.modular) + return True + def packmodular(self): + """打包模块""" + if os.path.exists(self.appname+"/"+self.modular): + zip.packzip(self.appname+"/"+self.modular,self.appname+"/"+self.modular+".zip") + return True + else: + return False + def installmodular(self): + "创建模块,如果应用不存,则创建默认应用,如果在您的应用目录下没有模块包,则创建默认模块文件" + if not os.path.exists(self.appname): + os.makedirs(self.appname) + else: + if not os.path.isfile(self.appname+"/__init__.py") or not os.path.exists(self.appname+"/common"): + raise Exception(self.appname+"不是kcweb应用") + if not os.path.exists(self.appname+"/common"): + os.makedirs(self.appname+"/common") + f=open(self.appname+"/common/__init__.py","w+",encoding='utf-8') + content=Templates(self.path+"/application/common/__init__.py",appname=self.appname,modular=self.modular) + f.write(content) + f.close() + f=open(self.appname+"/common/autoload.py","w+",encoding='utf-8') + content=Templates(self.path+"/application/common/autoload.py",appname=self.appname,modular=self.modular) + f.write(content) + f.close() + if not os.path.exists(self.appname+"/config"): + os.makedirs(self.appname+"/config") + f=open(self.appname+"/config/__init__.py","w+",encoding='utf-8') + content=Templates(self.path+"/application/config/__init__.py",appname=self.appname,modular=self.modular) + f.write(content) + f.close() + f=open(self.appname+"/config/other.py","w+",encoding='utf-8') + content=Templates(self.path+"/application/config/other.py",appname=self.appname,modular=self.modular) + f.write(content) + f.close() + if os.path.exists(self.appname+"/"+self.modular): + raise Exception(self.appname+"/"+self.modular+"已存在") + else: + if os.path.isfile(self.appname+"/"+self.modular+".zip"):#安装打包好的模块 + zip.unzip_file(self.appname+"/"+self.modular+".zip",self.appname+"/"+self.modular+"/") + os.remove(self.appname+"/"+self.modular+".zip") + else: + os.makedirs(self.appname+"/"+self.modular)#创建模块 + self.__zxmodular("") + + if os.path.isfile(self.appname+"/__init__.py"): + content="\nfrom . import "+self.modular + else: + #在应用目录下创建初始化文件 + lists=os.listdir(self.appname) + modulars=[] + filters=['__init__','__pycache__','common','config','runtime','log'] + for files in lists: + if not os.path.isfile(self.appname+"/"+files): + if files not in filters: + modulars.append(files) + content=Templates(self.path+"/application/__init__.py",appname=self.appname,tuple_modular=modulars) + f=open(self.appname+"/__init__.py","a",encoding='utf-8') + f.write(content) + f.close() + if not os.path.exists(self.path): + if "Windows" in platform.platform(): + pythonname="python" + else: + pythonname="python3" + sys.argv[0]=re.sub('.py','',sys.argv[0]) + content=('# #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ + 'from kcweb import web\n'+ + 'import '+self.appname+' as application\n'+ + 'from '+self.appname+'.common import *\n'+ + 'Queues.start() #开启队列监听\n'+ + 'app=web(__name__,application)\n'+ + 'if __name__ == "__main__":\n'+ + ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ + ' app.run(host="0.0.0.0",port="39001",name="'+pythonname+'")') + f=open("./"+sys.argv[0]+".py","w+",encoding='utf-8') + f.write(content) + f.close() + return True + def __zxmodular(self,sourcep): + "处理模块文件" + path1=self.path+"/application/api"+sourcep + path2=self.appname+"/"+self.modular+sourcep + lists=os.listdir(path1) + for files in lists: + if os.path.isfile(path1+"/"+files): + if ".py" in files: + content=Templates(path1+"/"+files,appname=self.appname,modular=self.modular) + f=open(path2+"/"+files,"w+",encoding='utf-8') + f.write(content) + f.close() + else: + f=open(path1+"/"+files,"r",encoding='utf-8') + content=f.read() + f.close() + f=open(path2+"/"+files,"w+",encoding='utf-8') + f.write(content) + f.close() + elif files != '__pycache__': + if not os.path.exists(path2+"/"+files): + os.makedirs(path2+"/"+files) + self.__zxmodular(sourcep+"/"+files) \ No newline at end of file diff --git a/config/__init__.py b/config/__init__.py index 99cdd5c..630439e 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -73,7 +73,7 @@ mongo['retryWrites']=False #是否支持重新写入 route={} route['default']=True route['modular']='' -route['edition']='' +route['plug']='' route['files']='index' #默认路由文件 route['funct']='index' #默认路由函数 route['methods']=['POST','GET'] #默认请求方式 @@ -88,7 +88,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='2.40.8' #项目版本 +kcweb['version']='2.40.9' #项目版本 kcweb['description']='基于python后端开发框架' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/create.py b/create.py deleted file mode 100644 index 036c060..0000000 --- a/create.py +++ /dev/null @@ -1,95 +0,0 @@ -# -*- coding: utf-8 -*- -import os,re,traceback,shutil,platform,sys -from mako.template import Template as kcwTemplate -def Template(path,**context): - body='' - with open(str(path), 'r',encoding='utf-8') as f: - content=f.read() - t=kcwTemplate(content) - body=t.render(**context) - return body -class create: - appname=None - modular=None - path=os.path.split(os.path.realpath(__file__))[0] #当前文件目录 - def __init__(self,appname="application",modular="api"): - self.appname=appname - self.modular=modular - if not os.path.exists(self.appname): - os.makedirs(self.appname) - if not os.path.exists(self.appname+"/common"): - os.makedirs(self.appname+"/common") - f=open(self.appname+"/common/__init__.py","w+",encoding='utf-8') - content=Template(self.path+"/application/common/__init__.py",appname=appname,modular=modular) - f.write(content) - f.close() - f=open(self.appname+"/common/autoload.py","w+",encoding='utf-8') - content=Template(self.path+"/application/common/autoload.py",appname=appname,modular=modular) - f.write(content) - f.close() - if not os.path.exists(self.appname+"/config"): - os.makedirs(self.appname+"/config") - f=open(self.appname+"/config/__init__.py","w+",encoding='utf-8') - content=Template(self.path+"/application/config/__init__.py",appname=appname,modular=modular) - f.write(content) - f.close() - f=open(self.appname+"/config/other.py","w+",encoding='utf-8') - content=Template(self.path+"/application/config/other.py",appname=appname,modular=modular) - f.write(content) - f.close() - if not os.path.exists(self.appname+"/"+self.modular): #创建模块 - os.makedirs(self.appname+"/"+self.modular) - self.zxmodular("") - #在应用目录下创建初始化文件 - lists=os.listdir(self.appname) - modulars=[] - filters=['__init__','__pycache__','common','config','runtime','log'] - for files in lists: - if not os.path.isfile(self.appname+"/"+files): - if files not in filters: - modulars.append(files) - f=open(self.appname+"/__init__.py","w+",encoding='utf-8') - content=Template(self.path+"/application/__init__.py",appname=appname,tuple_modular=modulars) - f.write(content) - f.close() - if "Windows" in platform.platform(): - pythonname="python" - else: - pythonname="python3" - sys.argv[0]=re.sub('.py','',sys.argv[0]) - content=('# #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ - 'from kcweb import web\n'+ - 'import '+self.appname+' as application\n'+ - 'from '+self.appname+'.common import *\n'+ - 'Queues.start() #开启队列监听\n'+ - 'app=web(__name__,application)\n'+ - 'if __name__ == "__main__":\n'+ - ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ - ' app.run(host="0.0.0.0",port="39001",name="'+pythonname+'")') - f=open("./"+sys.argv[0]+".py","w+",encoding='utf-8') - f.write(content) - f.close() - def zxmodular(self,sourcep): - "处理模块文件" - path1=self.path+"/application/api"+sourcep - path2=self.appname+"/"+self.modular+sourcep - lists=os.listdir(path1) - for files in lists: - if os.path.isfile(path1+"/"+files): - if ".py" in files: - content=Template(path1+"/"+files,appname=self.appname,modular=self.modular) - f=open(path2+"/"+files,"w+",encoding='utf-8') - f.write(content) - f.close() - else: - f=open(path1+"/"+files,"r",encoding='utf-8') - content=f.read() - f.close() - f=open(path2+"/"+files,"w+",encoding='utf-8') - f.write(content) - f.close() - elif files != '__pycache__': - if not os.path.exists(path2+"/"+files): - os.makedirs(path2+"/"+files) - self.zxmodular(sourcep+"/"+files) - diff --git a/setup.py b/setup.py index b90f088..b09c8bc 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,6 @@ setup( maintainer_email = confkcw["maintainer_email"], url=confkcw['url'], packages = b, - # install_requires = ['pymongo==3.10.0','six==1.12.0','requests==2.22.0','watchdog==0.9.0','Mako==1.1.0','paramiko==2.6.0','webssh==1.4.5'], #第三方包 install_requires = ['pymongo>=3.10.0','Mako>=1.1.2','requests>=2.23.0','six>=1.12.0','watchdog>=0.9.0'], #第三方包 package_data = { '': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'], diff --git a/utill/db/mongodb.py b/utill/db/mongodb.py index 5e5fb11..aa17924 100644 --- a/utill/db/mongodb.py +++ b/utill/db/mongodb.py @@ -51,6 +51,7 @@ class mongo: 返回 文档列表 """ + self.__setconn() if id: self.where('_id',id) @@ -70,6 +71,7 @@ class mongo: except: pass else: k['_id']=str(k['_id']) lists.append(k) + self.__None() return lists def find(self,id=None): """查询一条文档 @@ -86,6 +88,7 @@ class mongo: try: arr['_id'] except: pass else: arr['_id']=str(arr['_id']) + self.__None() return arr def countlist(self): """查询文档数量和所有文档 @@ -109,6 +112,7 @@ class mongo: except: pass else: k['_id']=str(k['_id']) lists.append(k) + self.__None() return arr.count(),lists def count(self): """查询文档数量 @@ -117,6 +121,7 @@ class mongo: """ self.__setconn() count=self.__tabobj.find(self.__where,{}).count() + self.__None() return count def update(self,data,multi=True): """文档更新 @@ -130,11 +135,8 @@ class mongo: # print(self.__where) # print({"$set":data}) ar=self.__tabobj.update(self.__where,{"$set":data},multi=multi) + self.__None() return ar - if ar: - return ar['nModified'] - else: - return 0 def delete(self,id=None): """文档删除 删除条件是where函数 """ @@ -145,17 +147,20 @@ class mongo: # print(self.__where) # exit() bo=self.__tabobj.remove(self.__where) + self.__None() if bo: return bo['n'] else: return 0 else: + self.__None() return 0 def deleteAll(self,id=None): """删所有文档除 """ self.__setconn() bo=self.__tabobj.remove({}) + self.__None() if bo: return bo['n'] else: @@ -188,6 +193,22 @@ class mongo: """ self.__table=table return self + def __None(self): + "清除所有赋值条件" + # self.__lock=None + # self.__distinct=None + # self.__join=None + # self.__joinstr='' + # self.__alias=None + # self.__having=None + # self.__group=None + # self.__group1=None + # self.__order=None + # self.__order1=None + mongo.__limit=[] + mongo.__field={} + mongo.__where={} + mongo.__table=None __where={} def where(self,where = None,*wheres): """设置过滤条件 -- Gitee From 5385b07f6a46ba3be03016833b234b5b0d177376 Mon Sep 17 00:00:00 2001 From: kunkun Date: Sun, 24 May 2020 07:45:01 +0800 Subject: [PATCH 07/52] kun --- application/api/controller/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/application/api/controller/__init__.py b/application/api/controller/__init__.py index 6de7530..cd4aab3 100644 --- a/application/api/controller/__init__.py +++ b/application/api/controller/__init__.py @@ -1,5 +1,2 @@ # -*- coding: utf-8 -*- -from . import plug,plug1,plug2 -# def error(err,data): -# "该函数在当前目录下无法匹配时被调用" -# return data,"200",{"Content-Type":"text/json; charset=utf-8"} \ No newline at end of file +from . import plug,plug1,plug2 \ No newline at end of file -- Gitee From c93ece8304038e435fbac052cc417697cc8edb0f Mon Sep 17 00:00:00 2001 From: kunkun Date: Mon, 25 May 2020 12:28:22 +0800 Subject: [PATCH 08/52] kun --- config/__init__.py | 1 + utill/db/mysql copy.py | 1013 ++++++++++++++++++++++++++++++++++++++++ utill/db/mysql.py | 96 ++-- 3 files changed, 1059 insertions(+), 51 deletions(-) create mode 100644 utill/db/mysql copy.py diff --git a/config/__init__.py b/config/__init__.py index 630439e..6d7a23b 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -40,6 +40,7 @@ session['db']=2 #Redis数据库 注:Redis用1或2或3等表示 # 默认数据库配置 database={} database['type']='mysql' # 数据库类型 目前支持mysql和sqlite +database['debug']=False #是否开启数据库调试描述 database['host']=['127.0.0.1']#服务器地址 [地址1,地址2,地址3...] 多个地址分布式(主从服务器)下有效 database['port']=[3306] #端口 [端口1,端口2,端口3...] database['user']=['root'] #用户名 [用户名1,用户名2,用户名3...] diff --git a/utill/db/mysql copy.py b/utill/db/mysql copy.py new file mode 100644 index 0000000..30250bc --- /dev/null +++ b/utill/db/mysql copy.py @@ -0,0 +1,1013 @@ +# -*- coding: utf-8 -*- +from .pymysql import connect,escape_string +# import config.conf as config +import kcweb.config as config +import time,traceback,decimal,random +dbconfig=config.database +class mysql: + """数据库实例""" + __config=dbconfig + __conn={} #数据库链接对象 + __cursor=None #游标对象 + __errorcount=dbconfig['break'] #允许最大链接错误次数 + __errorcounts=0 #默认链接错误次数 + __dbObjcount=dbconfig['dbObjcount'] #数据库链接实例数量 + __sql='' + __sqls='' + __masteridentifier='' # 主服务器标识 + __slaveidentifier='' # 从服务器标识 + def __del__(self): + if not self.__config['pattern'] and self.__conn: + try: + self.__conn.close() + except Exception as e: + print("关闭失败",e) + __dbcount=1 + def __setdbcount(self): + "设置数据库配置总数量" + if isinstance(self.__config['host'],str): + self.__config['host']=[self.__config['host']] + if isinstance(self.__config['port'],str): + self.__config['port']=[self.__config['port']] + if isinstance(self.__config['user'],str): + self.__config['user']=[self.__config['user']] + if isinstance(self.__config['password'],str): + self.__config['password']=[self.__config['password']] + if isinstance(self.__config['db'],str): + self.__config['db']=[self.__config['db']] + host=len(self.__config['host']) + port=len(self.__config['port']) + user=len(self.__config['user']) + password=len(self.__config['password']) + db=len(self.__config['db']) + lists=[host,port,user,password,db] + lists.sort() + self.__dbcount=lists[0] + def __closeconn(self,identifier): + "长链接模式下,关闭链接池的链接" + if self.__config['pattern']: + if identifier in mysql.__conn: + for k in mysql.__conn[identifier]: + # print(identifier) + try: + k['obj'].close() + print(k,"关闭成功") + except: + print(k,"关闭错误") + mysql.__conn[identifier]=[] + __dbobjident=None #集中式(单一服务器)并且长连接模式下随机服务器链接标识 和 分布式(主从服务器)模式下随机服务器链接标识 + def __connects(self,typess="DQL"): + """设置数据库链接 + + 参数 typess :数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL + """ + + try: + if self.__config['deploy']==0: # 集中式(单一服务器) + if self.__config['pattern']: # 长连接情况下 + self.__masteridentifier=self.__config['host'][0]+str(self.__config['port'][0])+self.__config['db'][0] # 服务器标识 + if self.__masteridentifier not in mysql.__conn or len(mysql.__conn[self.__masteridentifier])<1: + i=0 + masterlistsdb=[] + while iself.__config['dbObjcount'] * self.__dbcount: #长连接情况下如果错误次数超过数据实例数量 关闭使用连接进行重连接 + self.__patternerrorcount=0 + if self.__config['deploy'] == 1: #分布式(主从服务器) 情况下 + print("数据库连接失效,关闭主从连接池后重新连接") + self.__closeconn(self.__masteridentifier) + self.__closeconn(self.__slaveidentifier) + time.sleep(10) + # mysql.__conn=[] #父类数据库实例 + self.__connects(typess) + self.__execute(typess) + else: + print("数据库连接失效,关闭主连接池后重新连接") + self.__closeconn(self.__masteridentifier) + time.sleep(10) + # mysql.__conn=[] #父类数据库实例 + self.__connects(typess) + self.__execute(typess) + else: + self.__patternerrorcount=self.__patternerrorcount+1 + self.__execute(typess) + else: + self.__conn[bs][self.__dbobjident]['error']=self.__conn[bs][self.__dbobjident]['error']+1 #当前数据库连接实例异常错误数量 + if self.__conn[bs][self.__dbobjident]['error'] > 0: + try: + # mysql.__conn[bs][self.__dbobjident]['obj'].close() #关闭当前实例 + self.__closeconn(bs) + except Exception as e: + print("关闭异常",e) + raise Exception(e) + else: # 短连接情况下 + print("服务器正在被关闭,关闭当前连接后重试") + try: + mysql.__conn.close() #关闭当前实例 + except Exception as e: + print("关闭异常",e) + # mysql.__conn=[] #父类数据库实例 + self.__connects(typess) + self.__execute(typess) + else: + raise Exception(e) + else: + self.__patternerrorcount=0 + return res + + def query(self,sql): + """执行sql语句 注:只支持单一服务器模式 + + 参数 sql 字符串 + + 返回 列表 或 数字 + """ + self.__sql=sql + res=self.__execute('DQL') + description=self.__cursor.description #获取字段 + result = self.__cursor.fetchall() #获取查询结果 + # print(result) + self.__cursor.close() + if description is None: + return res + else: + lists=[] + data_dict=[] + for field in description:#获取字段 + data_dict.append(field[0]) + for k in result: + i=0 + dicts={} + for j in k: + dicts[data_dict[i]]=j + i=i+1 + lists.append(dicts) + return lists + def execute(self,sql): + """执行sql语句 注:只支持单一服务器模式 + + 参数 sql 字符串 + + 返回 列表 或 数字 + """ + self.__sql=sql + res=self.__execute('DML') + description=self.__cursor.description #获取字段 + result = self.__cursor.fetchall() #获取查询结果 + # print(result) + self.__cursor.close() + if description is None: + return res + else: + lists=[] + data_dict=[] + for field in description:#获取字段 + data_dict.append(field[0]) + for k in result: + i=0 + dicts={} + for j in k: + dicts[data_dict[i]]=j + i=i+1 + lists.append(dicts) + return lists + + + def select(self,id=None): + """select查询 + + 返回 list(列表) + """ + if id : + self.__where="id=%d" % id + self.__setsql() + if self.__buildSql: + self.__sqls="("+self.__sql+")" + self.__None() + return self.__sqls + + self.__execute() + description=self.__cursor.description #获取字段 + result = self.__cursor.fetchall() #获取查询结果 + # print(result) + self.__cursor.close() + lists=[] + keys =[] + for field in description:#获取字段 + keys.append(field[0]) + key_number = len(keys) + for row in result: + item = dict() + for q in range(key_number): + k=row[q] + if type(row[q])==decimal.Decimal: + k=float(row[q]) + item[keys[q]] = k + lists.append(item) + return lists + def find(self,id=None): + """查询一条记录 + + 返回 字典 + """ + if id : + self.__where="id=%s" % id + self.limit(1) + self.__setsql() + if self.__buildSql: + self.__sqls="("+self.__sql+")" + self.__None() + return self.__sqls + self.__execute() + description=self.__cursor.description #获取字段 + result = self.__cursor.fetchall() #获取查询结果 + # print(result) + self.__cursor.close() + + item = dict() + keys =[] + for field in description:#获取字段 + keys.append(field[0]) + key_number = len(keys) + for row in result: + for q in range(key_number): + k=row[q] + if type(row[q])==decimal.Decimal: + k=float(row[q]) + item[keys[q]] = k + return item + + def count(self,field="*"): + """查询数量 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('count') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor.fetchall() #获取查询结果 + self.__cursor.close() + cou=int(result[0][0]) + return cou + def max(self,field): + """查询某字段的最大值 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('max') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor.fetchall() #获取查询结果 + self.__cursor.close() + cou=int(result[0][0]) + return cou + def min(self,field): + """查询某字段的最小值 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('min') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor.fetchall() #获取查询结果 + self.__cursor.close() + cou=int(result[0][0]) + return cou + def avg(self,field): + """查询某字段的平均值 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('avg') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor.fetchall() #获取查询结果 + self.__cursor.close() + cou=int(result[0][0]) + return cou + def sum(self,field): + """查询某字段之和 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('sum') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor.fetchall() #获取查询结果 + self.__cursor.close() + cou=int(result[0][0]) + return cou + + + def update(self,data,affair=False): + """数据表更新 + + 参数 data 要更新的内容 格式:{"name":"测试","age":20} + + 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 + """ + self.__setsql('update',data) + res=self.__execute('DML') + if affair==False and self.__startTrans==False: + if not self.__config['pattern']: + self.__conn.commit() + else: + self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() + self.__cursor.close() + return res + def delete(self,affair=False): + """数据表删除 + + 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 + """ + self.__setsql('delete') + if self.__where: + res=self.__execute('DML') + else: + return 0 + if affair==False and self.__startTrans==False: + if not self.__config['pattern']: + self.__conn.commit() + else: + self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() + self.__cursor.close() + return res + def insert(self,dicts,affair=False): + """插入数据库 单条插入或多条插入 + + 参数 dicts 要插入的内容 单条格式:{"name":"测试","age":20} 。 多条格式:[{"name":"测试","age":20},{"name":"测试","age":20}] + + 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 + + 返回插入的数量 + """ + self.__setsql('insert',dicts) + res=self.__execute('DML') + if affair==False and self.__startTrans==False: + if not self.__config['pattern']: + self.__conn.commit() + else: + self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() + self.__cursor.close() + return res + + __startTrans=False + def startTrans(self): + "开启事务,仅对 update方法、delete方法、install方法有效" + self.__startTrans=True + def commit(self): + """事务提交 + + 增删改后的任务进行提交 + """ + if not self.__config['pattern']: + self.__conn.commit() + else: + self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() + + def rollback(self): + """事务回滚 + + 增删改后的任务进行撤销 + """ + if not self.__config['pattern']: + self.__conn.rollback() + else: + self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].rollback() + def getsql(self): + """得到生成的sql语句""" + return self.__sql + __buildSql=None + def buildSql(self): + """构造子查询""" + self.__buildSql=True + return self + def __None(self): + "清除所有赋值条件" + self.__lock=None + self.__distinct=None + self.__join=None + self.__joinstr='' + self.__alias=None + self.__having=None + self.__group=None + self.__group1=None + self.__order=None + self.__order1=None + self.__limit=None + self.__field="*" + self.__where=None + self.__wheres=() + self.__table=None + self.__buildSql=None + self.__table=None + + __where=None + __wheres=() + def where(self,where = None,*wheres): + """设置过滤条件 + + 传入方式: + "id",2 表示id='2' + + "id","in",2,3,4,5,6,...表示 id in (2,3,4,5,6,...) + + "id","in",[2,3,4,5,6,...]表示 id in (2,3,4,5,6,...) + + + [("id","gt",6000),"and",("name","like","%超")] 表示 ( id > "6000" and name LIKE "%超" ) + + "id","eq",1 表示 id = '1' + + eq 等于 + neq 不等于 + gt 大于 + egt 大于等于 + lt 小于 + elt 小于等于 + like LIKE + """ + self.__where=where + self.__wheres=wheres + return self + __field='*' + def field(self,field = "*"): + """设置过滤显示条件 + + 参数 field:str 字符串 + """ + self.__field=field + return self + __limit=[] + def limit(self,offset, length = None): + """设置查询数量 + + 参数 offset:int 起始位置 + + 参数 length:int 查询数量 + """ + self.__limit=[offset,length] + return self + def page(self,pagenow=1, length = 20): + """设置分页查询 + + 参数 pagenow:int 页码 + + 参数 length:int 查询数量 + """ + offset=(pagenow-1)*length + self.__limit=[offset,length] + return self + __order=None + __order1=None + def order(self,strs=None,*strs1): + """设置排序查询 + + 传入方式: + + "id desc" + + "id",'name','appkey','asc' + + "id",'name','appkey' 不包含asc或desc的情况下 默认是desc + + ['id','taskid',{"task_id":"desc"}] + """ + self.__order=strs + self.__order1=strs1 + return self + __group=None + __group1=None + def group(self,strs=None,*strs1): + """设置分组查询 + + 传入方式: + + "id,name" + + "id","name" + """ + self.__group=strs + self.__group1=strs1 + return self + __having=None + def having(self,strs=None): + """用于配合group方法完成从分组的结果中筛选(通常是聚合条件)数据 + + 参数 strs:string 如:"count(time)>3" + """ + self.__having=strs + return self + __alias=None + def alias(self,strs=None): + """用于设置当前数据表的别名,便于使用其他的连贯操作例如join方法等。 + + 参数 strs:string 默认当前表作为别名 + """ + if strs: + self.__alias=strs + else: + self.__alias=self.__table + return self + __join=None + __joinstr='' + def join(self,strs,on=None,types='INNER'): + """用于根据两个或多个表中的列之间的关系,从这些表中查询数据 + + 参数 strs string 如:"test t1" test表设置别名t1 + + 参数 on string 如:"t1.id=t2.pid" 设置连接条件 + + 参数 types 支持INNER、LEFT、RIGHT、FULL 默认INNER + + """ + joinstr='' + if strs and on: + joinstr=joinstr+types+" JOIN "+strs+" ON "+on+" " + if joinstr: + self.__joinstr=self.__joinstr+joinstr + return self + __distinct=None + def distinct(self,bools=None): + "用于返回唯一不同的值,配合field方法使用生效,来消除所有重复的记录,并只获取唯一一次记录。" + self.__distinct=bools + return self + __lock=None + def lock(self,strs=None): + """用于数据库的锁机制,在查询或者执行操作的时候使用 + + 排他锁 (FOR UPDATE) + + 共享锁 (lock in share mode) + + 参数 strs 如:True表示自动在生成的SQL语句最后加上FOR UPDATE, + + + """ + self.__lock=strs + return self + + # __cache=[] + # def cache(self,endtime,tag=None): + # """设置查询缓存 + + # 参数 endtime:int 缓存数据 0永久 + + # 参数 tag:int 缓存标签 + # """ + # self.__cache=[endtime,tag] + # return self + def __setsql(self,types=None,data = {}): + """生成sql语句""" + if types==None: + self.__sql="SELECT" + if self.__distinct and self.__field: + self.__sql=self.__sql+" DISTINCT" + if self.__alias: + self.__sql=self.__sql+" %s FROM %s %s" % (self.__field,self.__table,self.__alias) + else: + self.__sql=self.__sql+" %s FROM %s" % (self.__field,self.__table) + elif types=='count': + self.__sql="SELECT COUNT(%s) FROM %s" % (self.__field,self.__table) + elif types=='max': + self.__sql="SELECT MAX(%s) FROM %s" % (self.__field,self.__table) + elif types=='min': + self.__sql="SELECT MIN(%s) FROM %s" % (self.__field,self.__table) + elif types=='avg': + self.__sql="SELECT AVG(%s) FROM %s" % (self.__field,self.__table) + elif types=='sum': + self.__sql="SELECT SUM(%s) FROM %s" % (self.__field,self.__table) + elif types=='update': + strs='' + for k in data: + if isinstance(data[k],str): + strs=strs+" %s = '%s' ," % (k,escape_string(data[k])) + else: + strs=strs+" %s = %s ," % (k,data[k]) + strs=strs[:-1] + self.__sql="UPDATE %s SET %s" % (self.__table,strs) + elif types=='delete': + self.__sql="DELETE FROM %s" % self.__table + elif types=='insert': + if isinstance(data,dict): + strs='' + val='' + for k in data: + strs=strs+"%s," % k + if isinstance(data[k],str): + val=val+"'%s'," % escape_string(data[k]) + else: + val=val+"%s," % data[k] + strs=strs[:-1] + val=val[:-1] + self.__sql="INSERT INTO %s (%s) VALUES (%s)" % (self.__table,strs,val) + elif isinstance(data,list): + strs='' + val='(' + for k in data[0]: + strs=strs+" , "+k + for k in data: + for j in k: + if isinstance(k[j],str): + val=val+"'"+str(k[j])+"'," + else: + val=val+str(k[j])+"," + val=val[:-1] + val=val+"),(" + val=val[:-2] + self.__sql="INSERT INTO "+self.__table+" ("+strs[3:]+") VALUES "+val + if self.__joinstr: + self.__sql=self.__sql+" "+self.__joinstr + if self.__where: + if isinstance(self.__where,str): + if self.__wheres: + if len(self.__wheres) == 2: + if isinstance(self.__wheres[1],list): + self.__sql=self.__sql + " WHERE %s %s (" % (self.__where,self.__operator(self.__wheres[0])) + for k in self.__wheres[1]: + self.__sql=self.__sql+str(k)+"," + self.__sql=self.__sql[:-1]+")" + else: + self.__sql=self.__sql + " WHERE %s %s '%s'" % (self.__where,self.__operator(self.__wheres[0]),self.__wheres[1]) + elif len(self.__wheres) > 2: + if self.__wheres[0]=='in': + strs=str(self.__wheres[1]) + i=0 + for k in self.__wheres: + if i > 1: + strs=strs+","+str(k) + i=i+1 + self.__sql=self.__sql + " WHERE %s in (%s)" % (self.__where,strs) + else: + self.__sql=self.__sql + " WHERE %s = '%s'" % (self.__where,self.__wheres[0]) + else: + self.__sql=self.__sql + " WHERE %s" % self.__where + elif isinstance(self.__where,list): + self.__sql=self.__sql + " WHERE %s" % self.__listTrans() + else: + print("参数where类型错误") + if self.__order: + s='' + if isinstance(self.__order,list): + for strs in self.__order: + if isinstance(strs,str): + s=s+strs+"," + else: + pass + for key in strs: + s=s+key+" "+strs[key] + s=s+"," + s=s[:-1] + if isinstance(self.__order,str): + if self.__order1: + if len(self.__order1) > 1: + if self.__order1[len(self.__order1)-1] == 'desc' or self.__order1[len(self.__order1)-1] == 'asc': + i=0 + while iself.__config['dbObjcount'] * self.__dbcount: #长连接情况下如果错误次数超过数据实例数量 关闭使用连接进行重连接 self.__patternerrorcount=0 if self.__config['deploy'] == 1: #分布式(主从服务器) 情况下 - print("数据库连接失效,关闭主从连接池后重新连接") + if self.__config['debug']: + print("数据库连接失效,关闭主从连接池后重新连接") self.__closeconn(self.__masteridentifier) self.__closeconn(self.__slaveidentifier) time.sleep(10) - # mysql.__conn=[] #父类数据库实例 self.__connects(typess) self.__execute(typess) else: - print("数据库连接失效,关闭主连接池后重新连接") + if self.__config['debug']: + print("数据库连接失效,关闭主连接池后重新连接") self.__closeconn(self.__masteridentifier) time.sleep(10) - # mysql.__conn=[] #父类数据库实例 self.__connects(typess) self.__execute(typess) else: @@ -333,29 +342,22 @@ class mysql: self.__execute(typess) else: self.__conn[bs][self.__dbobjident]['error']=self.__conn[bs][self.__dbobjident]['error']+1 #当前数据库连接实例异常错误数量 - if self.__conn[bs][self.__dbobjident]['error'] > 2: + if self.__conn[bs][self.__dbobjident]['error'] > 0: try: - mysql.__conn[bs][self.__dbobjident]['obj'].close() #关闭当前实例 + # mysql.__conn[bs][self.__dbobjident]['obj'].close() #关闭当前实例 + self.__closeconn(bs) except Exception as e: - print("关闭异常",e) - # self.__conn[bs].pos(self.__dbobjident) #从列表中删除 - # if errorcodes == 2013: - #创建一个新的数据库实例 - if types=='master': - s=random.randint(0,self.__config['master_num']-1) - else: - s=random.randint(self.__dbcount-self.__config['master_num']-1,self.__dbcount-1) - obj=connect(host=self.__config['host'][s], port=self.__config['port'][s], user=self.__config['user'][s], password=self.__config['password'][s], db=self.__config['db'][s], charset=self.__config['charset']) - mysql.__conn[bs][self.__dbobjident]['obj']=obj - mysql.__conn[bs][self.__dbobjident]['error']=0 - print("已重新创建一个新的数据库实例",mysql.__conn) - self.__execute(typess) + if self.__config['debug']: + print("关闭异常",e) + raise Exception(e) else: # 短连接情况下 - print("服务器正在被关闭,关闭当前连接后重试") + if self.__config['debug']: + print("服务器正在被关闭,关闭当前连接后重试") try: mysql.__conn.close() #关闭当前实例 except Exception as e: - print("关闭异常",e) + if self.__config['debug']: + print("关闭异常",e) # mysql.__conn=[] #父类数据库实例 self.__connects(typess) self.__execute(typess) @@ -376,7 +378,6 @@ class mysql: res=self.__execute('DQL') description=self.__cursor.description #获取字段 result = self.__cursor.fetchall() #获取查询结果 - # print(result) self.__cursor.close() if description is None: return res @@ -404,7 +405,6 @@ class mysql: res=self.__execute('DML') description=self.__cursor.description #获取字段 result = self.__cursor.fetchall() #获取查询结果 - # print(result) self.__cursor.close() if description is None: return res @@ -439,7 +439,6 @@ class mysql: self.__execute() description=self.__cursor.description #获取字段 result = self.__cursor.fetchall() #获取查询结果 - # print(result) self.__cursor.close() lists=[] keys =[] @@ -471,7 +470,6 @@ class mysql: self.__execute() description=self.__cursor.description #获取字段 result = self.__cursor.fetchall() #获取查询结果 - # print(result) self.__cursor.close() item = dict() @@ -943,7 +941,6 @@ class mysql: s=self.__order+" "+s else: s=self.__order - # print(s) self.__sql=self.__sql+" ORDER BY "+s if self.__group: s=self.__group @@ -963,15 +960,12 @@ class mysql: self.__sql=self.__sql+" "+self.__lock else: self.__sql=self.__sql+' FOR UPDATE' - # print(self.__sql) - # exit() def __listTrans(self): """列表转换sql表达式 返回 字符串 """ strs='' #[('id', 'eq', '1'), 'or', ('id', 'eq', '2')] - # print(self.__where) for k in self.__where: if isinstance(k,tuple): t=0 -- Gitee From a551b19985d1081d0ce37e5e6376e863a5d4efa0 Mon Sep 17 00:00:00 2001 From: kunkun Date: Tue, 26 May 2020 02:18:23 +0800 Subject: [PATCH 09/52] kun --- app.py | 171 +++++++++++++++++++++++++++------------------ config/__init__.py | 1 + 2 files changed, 104 insertions(+), 68 deletions(-) diff --git a/app.py b/app.py index 6d6f56f..7ce47e3 100644 --- a/app.py +++ b/app.py @@ -8,6 +8,7 @@ from datetime import datetime from threading import local from .utill import filetype from kcweb.utill.cache import cache as kcwcache +from wsgiref.simple_server import make_server class web: __name=None __appname=None @@ -17,15 +18,6 @@ class web: self.__appname=appname if self.__name != '__main__': def apps(env, start_response): - # REQUEST_METHOD=env['REQUEST_METHOD'] #GET - # QUERY_STRING=env['QUERY_STRING'] #a=1&b=1 - # RAW_URI=env['RAW_URI'] #/aa/bb/cc?a=1&b=1 - # SERVER_PROTOCOL=env['SERVER_PROTOCOL'] #HTTP/1.1 - # HTTP_HOST=env['HTTP_HOST'] #212.129.149.238:39010 - # HTTP_COOKIE=env['HTTP_COOKIE'] #cookie - # REMOTE_ADDR=env['REMOTE_ADDR'] #27.156.27.201 - # PATH_INFO=env['PATH_INFO'] #/aa/bb/cc - # HTTP_USER_AGENT=env['HTTP_USER_AGENT'] #Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0 try: env['BODY_DATA']=str(env['wsgi.input'].next(), encoding = "utf-8") except: @@ -49,7 +41,6 @@ class web: ("Content-Type",kind.mime), ("Cache-Control","public, max-age=43200"), ("Accept-Ranges","bytes"), - # ("Content-Length",len(body)) ] else: status,resheader,body=self.__routes(self,env) @@ -57,51 +48,6 @@ class web: pass else: body=bytes(body, encoding='utf-8') - # print(env['bodydata']) - # print("\n\nwsgi.input",env['wsgi.input']) - # print("\n\ndir(env['wsgi.input'])",dir(env['wsgi.input'])) - # print("\n\nenv['wsgi.input'].__dict__",env['wsgi.input'].__dict__) - # try: - # print("\n\nwsgi.input.buf()",env['wsgi.input'].buf()) - # except Exception as e: - # print("\n\nwsgi.input.buf() error:",e) - # try: - # print("\n\nwsgi.input.next()",env['wsgi.input'].next()) - # except Exception as e: - # print("\n\nwsgi.input.next() error:",e) - # try: - # print("\n\nwsgi.input.read()",env['wsgi.input'].read()) - # except Exception as e: - # print("\n\nwsgi.input.read() error:",e) - # try: - # print("\n\nwsgi.input.reader()",env['wsgi.input'].reader()) - # except Exception as e: - # print("\n\nwsgi.input.reader() error:",e) - # try: - # print("\n\nwsgi.input.readline()",env['wsgi.input'].readline()) - # except Exception as e: - # print("\n\nwsgi.input.readline() error:",e) - # try: - # print("\n\nwsgi.input.readlines()",env['wsgi.input'].readlines()) - # except Exception as e: - # print("\n\nwsgi.input.readlines() error:",e) - # try: - # print("wsgi.input.aa",env['wsgi.input'].get("SCRIPT_NAME", "")) - # except Exception as e: - # print("wsgi.input.get('aa') error:",e) - # try: - # print("wsgi.input.aa",env['wsgi.input']['aa']) - # except Exception as e: - # print("wsgi.input['aa'] error:",e) - # print(dir(env['wsgi.input']).getsize) - # from io import StringIO - # stdout = StringIO() - # print("Hello world!", file=stdout) - # print(file=stdout) - # h = sorted(env.items()) - # for k,v in h: - # print(k,'=',repr(v), file=stdout) - # print(stdout.getvalue().encode("utf-8")) start_response(status,resheader) return [body] return apps @@ -158,11 +104,30 @@ class web: def __impl(self,host,port,filename): "运行测试服务器" try: - self.__http_server( - host=host, - port=port, - filename=filename - ) + if config.app['http_server']=='wsgiref': + self.__http_wsgi( + host=host, + port=port, + filename=filename + ) + elif config.app['http_server']=='kcweb': + self.__http_sever( + host=host, + port=port, + filename=filename + ) + elif config.app['http_server']=='kcweb_server': + self.__http_server( + host=host, + port=port, + filename=filename + ) + else: + self.__http_wsgi( + host=host, + port=port, + filename=filename + ) except KeyboardInterrupt: pass def __get_modular(self,header): @@ -594,9 +559,73 @@ class web: t=Template(content) body=t.render(**context) return body - - + def __application(self,env, start_response): + # print(env) + try: + request_body_size = int(env.get('CONTENT_LENGTH', 0)) + except (ValueError): + request_body_size = 0 + BODY_DATA=env['wsgi.input'].read(request_body_size) + if 'multipart/form-data; boundary' in env['CONTENT_TYPE']: + env['BODY_DATA']="" + else: + env['BODY_DATA']=BODY_DATA.decode() + env['RAW_URI']=env['PATH_INFO'] + if env.get('QUERY_STRING'): + env['RAW_URI']=str(env['PATH_INFO'])+"?"+str(env.get('QUERY_STRING')) + reqheader={ + 'REQUEST_METHOD':env['REQUEST_METHOD'], + 'RAW_URI':env['RAW_URI'], + 'PATH_INFO':env['PATH_INFO'], + 'QUERY_STRING':env['QUERY_STRING'], + 'SERVER_PROTOCOL':env['SERVER_PROTOCOL'], + 'HTTP_HOST':env['HTTP_HOST'], + 'HTTP_COOKIE':env['HTTP_COOKIE'], + 'REMOTE_ADDR':env['REMOTE_ADDR'], + 'HTTP_USER_AGENT':env['HTTP_USER_AGENT'], + 'BODY_DATA':env['BODY_DATA'] + } + p=(config.app['staticpath']+reqheader['RAW_URI'].replace(' ','')) + status='200 ok' + if os.path.isfile(p): + kind = filetype.guess(p) + if kind is None: + f=open(p,"rb") + body=f.read() + f.close() + resheader=[ + ("Cache-Control","public, max-age=43200"), + ] + else: + f=open(p,"rb") + body=f.read() + f.close() + resheader=[ + ("Content-Type",kind.mime), + ("Cache-Control","public, max-age=43200"), + ("Accept-Ranges","bytes"), + ] + else: + status,resheader,body=web.__routes(self,reqheader) + if type(body) is bytes: + pass + else: + body=bytes(body, encoding='utf-8') + start_response(status,resheader) + return [body] + def __http_wsgi(self,host,port,filename): + "http——wsgi测试服务" + print("* \033[1;31;40m! 警告:\033[0m这是一个wsgiref开发服务器。不要在生产环境中部署使用它") + print('* 生产环境中建议使用gunicorn,gunicorn运行命令如:gunicorn -b '+host+':'+str(port)+' '+str(filename)+':app') + if self.__config.app['app_debug']: + print('* 调试器:开启') + else: + print('* 调试器:已关闭') + print("* 运行在http://"+host+":"+str(port)+"/ (按CTRL+C退出)") + httpd = make_server(host, int(port), self.__application) + httpd.serve_forever() def __http_server(self,host,port,filename): + "http测试服务" tcp_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM) try: tcp_socket.bind((host,int(port))) @@ -604,7 +633,7 @@ class web: print("通常每个套接字地址(协议/网络地址/端口)只允许使用一次(按CTRL+C退出)") else: tcp_socket.listen(1024) - print('! 警告:这是开发服务器。不要在生产环境中部署使用它') + print('! \033[1;31;40m警告:\033[0m这是一个kcweb_server开发服务器。不要在生产环境中部署使用它') print('* 生产环境中建议使用gunicorn,gunicorn运行命令如:gunicorn -b '+host+':'+str(port)+' '+str(filename)+':app') if self.__config.app['app_debug']: print('* 调试器:开启') @@ -708,8 +737,10 @@ class web: except Exception as e: pass new_socket.close() - def __http_sever(self,host,port): + def __http_sever(self,host,port,filename): #http测试服务器 + print('\033[1;31;40m! 警告:\033[0m这是一个kcweb开发服务器。不要在生产环境中部署使用它') + print('* 生产环境中建议使用gunicorn,gunicorn运行命令如:gunicorn -b '+host+':'+str(port)+' '+str(filename)+':app') if self.__config.app['app_debug']: print('* 调试器:开启') else: @@ -721,8 +752,6 @@ class web: pack_length=1024 tcp_socket.setblocking(False) tcp_socket_list=list() - - while True: try: new_tcp_socket,client_info=tcp_socket.accept() @@ -767,6 +796,7 @@ class web: else: HTTP_USER_AGENT='' BODY_DATA=datas[len(datas)-1] + # print(data) #reqsest reqheader={ 'REQUEST_METHOD':REQUEST_METHOD, @@ -781,11 +811,13 @@ class web: 'BODY_DATA':BODY_DATA } p=(config.app['staticpath']+RAW_URI.replace(' ','')) - + # print("目录",p) status='200 ok' if os.path.isfile(p): + # print('静态文件',p) kind = filetype.guess(p) if kind is None: + f=open(p,"rb") body=f.read() f.close() @@ -802,7 +834,10 @@ class web: header+="Content-Length:%d\n" % len(body) else: status,resheader,body=self.__routes(reqheader) - body=body.encode() + if type(body) is bytes: + pass + else: + body=body.encode() header="HTTP/1.1 %s \n" % status header+="Content-Length:%d\n" % len(body) diff --git a/config/__init__.py b/config/__init__.py index 6d7a23b..427043a 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -6,6 +6,7 @@ app['tpl_folder']='./tpl' #设置模板文件目录名 注意:不能配置目 app['before_request']='' #设置请求前执行的函数 app['after_request']='' #设置请求后执行的函数 app['staticpath']='static' +app['http_server']='wsgiref' #使用的开发服务器 支持 wsgiref、kcweb、kcweb_server # redis配置 redis={} redis['host']='127.0.0.1' #服务器地址 -- Gitee From 8f0e50a9ed014ef06f4d74bb2353367739746e97 Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 27 May 2020 22:44:05 +0800 Subject: [PATCH 10/52] kun --- app.py | 25 +- common/autoload.py | 1 - setup.py | 2 +- utill/db/mysql copy.py | 1013 ---------------------------------------- utill/http.py | 10 +- utill/queues.py | 33 +- 6 files changed, 50 insertions(+), 1034 deletions(-) delete mode 100644 utill/db/mysql copy.py diff --git a/app.py b/app.py index 7ce47e3..bf09386 100644 --- a/app.py +++ b/app.py @@ -567,12 +567,34 @@ class web: request_body_size = 0 BODY_DATA=env['wsgi.input'].read(request_body_size) if 'multipart/form-data; boundary' in env['CONTENT_TYPE']: - env['BODY_DATA']="" + BODY_DATA=BODY_DATA.decode("ISO-8859-1") + env['BODY_DATA']=BODY_DATA + # lists=BODY_DATA.split("\r\n") + # BODY_DATA=re.sub(lists[0],'',BODY_DATA) + # BODY_DATA=re.sub(lists[1],'',BODY_DATA) + # BODY_DATA=re.sub(lists[2],'',BODY_DATA) + # BODY_DATA=re.sub(lists[len(lists)-2],'',BODY_DATA) else: env['BODY_DATA']=BODY_DATA.decode() env['RAW_URI']=env['PATH_INFO'] if env.get('QUERY_STRING'): env['RAW_URI']=str(env['PATH_INFO'])+"?"+str(env.get('QUERY_STRING')) + try: + env['REMOTE_ADDR'] + except: + env['REMOTE_ADDR']='' + try: + env['HTTP_COOKIE'] + except: + env['HTTP_COOKIE']='' + try: + env['REMOTE_ADDR'] + except: + env['REMOTE_ADDR']='' + try: + env['HTTP_USER_AGENT'] + except: + env['HTTP_USER_AGENT']='' reqheader={ 'REQUEST_METHOD':env['REQUEST_METHOD'], 'RAW_URI':env['RAW_URI'], @@ -607,6 +629,7 @@ class web: ] else: status,resheader,body=web.__routes(self,reqheader) + resheader.append(('Server', "kcweb"+config.kcweb['version'])) if type(body) is bytes: pass else: diff --git a/common/autoload.py b/common/autoload.py index dbcc8ce..787215d 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -472,7 +472,6 @@ class create: 'from kcweb import web\n'+ 'import '+self.appname+' as application\n'+ 'from '+self.appname+'.common import *\n'+ - 'Queues.start() #开启队列监听\n'+ 'app=web(__name__,application)\n'+ 'if __name__ == "__main__":\n'+ ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ diff --git a/setup.py b/setup.py index b09c8bc..dec34f5 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='2.40.8' #项目版本 +confkcw['version']='2.40.9' #项目版本 confkcw['description']='基于python后端开发框架' #项目的简单描述 confkcw['long_description']="完整文档:http://intapp.kwebapp.cn/doc/docde?id=1" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 diff --git a/utill/db/mysql copy.py b/utill/db/mysql copy.py deleted file mode 100644 index 30250bc..0000000 --- a/utill/db/mysql copy.py +++ /dev/null @@ -1,1013 +0,0 @@ -# -*- coding: utf-8 -*- -from .pymysql import connect,escape_string -# import config.conf as config -import kcweb.config as config -import time,traceback,decimal,random -dbconfig=config.database -class mysql: - """数据库实例""" - __config=dbconfig - __conn={} #数据库链接对象 - __cursor=None #游标对象 - __errorcount=dbconfig['break'] #允许最大链接错误次数 - __errorcounts=0 #默认链接错误次数 - __dbObjcount=dbconfig['dbObjcount'] #数据库链接实例数量 - __sql='' - __sqls='' - __masteridentifier='' # 主服务器标识 - __slaveidentifier='' # 从服务器标识 - def __del__(self): - if not self.__config['pattern'] and self.__conn: - try: - self.__conn.close() - except Exception as e: - print("关闭失败",e) - __dbcount=1 - def __setdbcount(self): - "设置数据库配置总数量" - if isinstance(self.__config['host'],str): - self.__config['host']=[self.__config['host']] - if isinstance(self.__config['port'],str): - self.__config['port']=[self.__config['port']] - if isinstance(self.__config['user'],str): - self.__config['user']=[self.__config['user']] - if isinstance(self.__config['password'],str): - self.__config['password']=[self.__config['password']] - if isinstance(self.__config['db'],str): - self.__config['db']=[self.__config['db']] - host=len(self.__config['host']) - port=len(self.__config['port']) - user=len(self.__config['user']) - password=len(self.__config['password']) - db=len(self.__config['db']) - lists=[host,port,user,password,db] - lists.sort() - self.__dbcount=lists[0] - def __closeconn(self,identifier): - "长链接模式下,关闭链接池的链接" - if self.__config['pattern']: - if identifier in mysql.__conn: - for k in mysql.__conn[identifier]: - # print(identifier) - try: - k['obj'].close() - print(k,"关闭成功") - except: - print(k,"关闭错误") - mysql.__conn[identifier]=[] - __dbobjident=None #集中式(单一服务器)并且长连接模式下随机服务器链接标识 和 分布式(主从服务器)模式下随机服务器链接标识 - def __connects(self,typess="DQL"): - """设置数据库链接 - - 参数 typess :数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL - """ - - try: - if self.__config['deploy']==0: # 集中式(单一服务器) - if self.__config['pattern']: # 长连接情况下 - self.__masteridentifier=self.__config['host'][0]+str(self.__config['port'][0])+self.__config['db'][0] # 服务器标识 - if self.__masteridentifier not in mysql.__conn or len(mysql.__conn[self.__masteridentifier])<1: - i=0 - masterlistsdb=[] - while iself.__config['dbObjcount'] * self.__dbcount: #长连接情况下如果错误次数超过数据实例数量 关闭使用连接进行重连接 - self.__patternerrorcount=0 - if self.__config['deploy'] == 1: #分布式(主从服务器) 情况下 - print("数据库连接失效,关闭主从连接池后重新连接") - self.__closeconn(self.__masteridentifier) - self.__closeconn(self.__slaveidentifier) - time.sleep(10) - # mysql.__conn=[] #父类数据库实例 - self.__connects(typess) - self.__execute(typess) - else: - print("数据库连接失效,关闭主连接池后重新连接") - self.__closeconn(self.__masteridentifier) - time.sleep(10) - # mysql.__conn=[] #父类数据库实例 - self.__connects(typess) - self.__execute(typess) - else: - self.__patternerrorcount=self.__patternerrorcount+1 - self.__execute(typess) - else: - self.__conn[bs][self.__dbobjident]['error']=self.__conn[bs][self.__dbobjident]['error']+1 #当前数据库连接实例异常错误数量 - if self.__conn[bs][self.__dbobjident]['error'] > 0: - try: - # mysql.__conn[bs][self.__dbobjident]['obj'].close() #关闭当前实例 - self.__closeconn(bs) - except Exception as e: - print("关闭异常",e) - raise Exception(e) - else: # 短连接情况下 - print("服务器正在被关闭,关闭当前连接后重试") - try: - mysql.__conn.close() #关闭当前实例 - except Exception as e: - print("关闭异常",e) - # mysql.__conn=[] #父类数据库实例 - self.__connects(typess) - self.__execute(typess) - else: - raise Exception(e) - else: - self.__patternerrorcount=0 - return res - - def query(self,sql): - """执行sql语句 注:只支持单一服务器模式 - - 参数 sql 字符串 - - 返回 列表 或 数字 - """ - self.__sql=sql - res=self.__execute('DQL') - description=self.__cursor.description #获取字段 - result = self.__cursor.fetchall() #获取查询结果 - # print(result) - self.__cursor.close() - if description is None: - return res - else: - lists=[] - data_dict=[] - for field in description:#获取字段 - data_dict.append(field[0]) - for k in result: - i=0 - dicts={} - for j in k: - dicts[data_dict[i]]=j - i=i+1 - lists.append(dicts) - return lists - def execute(self,sql): - """执行sql语句 注:只支持单一服务器模式 - - 参数 sql 字符串 - - 返回 列表 或 数字 - """ - self.__sql=sql - res=self.__execute('DML') - description=self.__cursor.description #获取字段 - result = self.__cursor.fetchall() #获取查询结果 - # print(result) - self.__cursor.close() - if description is None: - return res - else: - lists=[] - data_dict=[] - for field in description:#获取字段 - data_dict.append(field[0]) - for k in result: - i=0 - dicts={} - for j in k: - dicts[data_dict[i]]=j - i=i+1 - lists.append(dicts) - return lists - - - def select(self,id=None): - """select查询 - - 返回 list(列表) - """ - if id : - self.__where="id=%d" % id - self.__setsql() - if self.__buildSql: - self.__sqls="("+self.__sql+")" - self.__None() - return self.__sqls - - self.__execute() - description=self.__cursor.description #获取字段 - result = self.__cursor.fetchall() #获取查询结果 - # print(result) - self.__cursor.close() - lists=[] - keys =[] - for field in description:#获取字段 - keys.append(field[0]) - key_number = len(keys) - for row in result: - item = dict() - for q in range(key_number): - k=row[q] - if type(row[q])==decimal.Decimal: - k=float(row[q]) - item[keys[q]] = k - lists.append(item) - return lists - def find(self,id=None): - """查询一条记录 - - 返回 字典 - """ - if id : - self.__where="id=%s" % id - self.limit(1) - self.__setsql() - if self.__buildSql: - self.__sqls="("+self.__sql+")" - self.__None() - return self.__sqls - self.__execute() - description=self.__cursor.description #获取字段 - result = self.__cursor.fetchall() #获取查询结果 - # print(result) - self.__cursor.close() - - item = dict() - keys =[] - for field in description:#获取字段 - keys.append(field[0]) - key_number = len(keys) - for row in result: - for q in range(key_number): - k=row[q] - if type(row[q])==decimal.Decimal: - k=float(row[q]) - item[keys[q]] = k - return item - - def count(self,field="*"): - """查询数量 - - 返回 int 数字 - """ - self.__field=field - self.__setsql('count') - if self.__buildSql: - self.__sqls="("+self.__sql+")" - return self.__sql - self.__execute() - result = self.__cursor.fetchall() #获取查询结果 - self.__cursor.close() - cou=int(result[0][0]) - return cou - def max(self,field): - """查询某字段的最大值 - - 返回 int 数字 - """ - self.__field=field - self.__setsql('max') - if self.__buildSql: - self.__sqls="("+self.__sql+")" - return self.__sql - self.__execute() - result = self.__cursor.fetchall() #获取查询结果 - self.__cursor.close() - cou=int(result[0][0]) - return cou - def min(self,field): - """查询某字段的最小值 - - 返回 int 数字 - """ - self.__field=field - self.__setsql('min') - if self.__buildSql: - self.__sqls="("+self.__sql+")" - return self.__sql - self.__execute() - result = self.__cursor.fetchall() #获取查询结果 - self.__cursor.close() - cou=int(result[0][0]) - return cou - def avg(self,field): - """查询某字段的平均值 - - 返回 int 数字 - """ - self.__field=field - self.__setsql('avg') - if self.__buildSql: - self.__sqls="("+self.__sql+")" - return self.__sql - self.__execute() - result = self.__cursor.fetchall() #获取查询结果 - self.__cursor.close() - cou=int(result[0][0]) - return cou - def sum(self,field): - """查询某字段之和 - - 返回 int 数字 - """ - self.__field=field - self.__setsql('sum') - if self.__buildSql: - self.__sqls="("+self.__sql+")" - return self.__sql - self.__execute() - result = self.__cursor.fetchall() #获取查询结果 - self.__cursor.close() - cou=int(result[0][0]) - return cou - - - def update(self,data,affair=False): - """数据表更新 - - 参数 data 要更新的内容 格式:{"name":"测试","age":20} - - 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 - """ - self.__setsql('update',data) - res=self.__execute('DML') - if affair==False and self.__startTrans==False: - if not self.__config['pattern']: - self.__conn.commit() - else: - self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() - self.__cursor.close() - return res - def delete(self,affair=False): - """数据表删除 - - 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 - """ - self.__setsql('delete') - if self.__where: - res=self.__execute('DML') - else: - return 0 - if affair==False and self.__startTrans==False: - if not self.__config['pattern']: - self.__conn.commit() - else: - self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() - self.__cursor.close() - return res - def insert(self,dicts,affair=False): - """插入数据库 单条插入或多条插入 - - 参数 dicts 要插入的内容 单条格式:{"name":"测试","age":20} 。 多条格式:[{"name":"测试","age":20},{"name":"测试","age":20}] - - 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 - - 返回插入的数量 - """ - self.__setsql('insert',dicts) - res=self.__execute('DML') - if affair==False and self.__startTrans==False: - if not self.__config['pattern']: - self.__conn.commit() - else: - self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() - self.__cursor.close() - return res - - __startTrans=False - def startTrans(self): - "开启事务,仅对 update方法、delete方法、install方法有效" - self.__startTrans=True - def commit(self): - """事务提交 - - 增删改后的任务进行提交 - """ - if not self.__config['pattern']: - self.__conn.commit() - else: - self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() - - def rollback(self): - """事务回滚 - - 增删改后的任务进行撤销 - """ - if not self.__config['pattern']: - self.__conn.rollback() - else: - self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].rollback() - def getsql(self): - """得到生成的sql语句""" - return self.__sql - __buildSql=None - def buildSql(self): - """构造子查询""" - self.__buildSql=True - return self - def __None(self): - "清除所有赋值条件" - self.__lock=None - self.__distinct=None - self.__join=None - self.__joinstr='' - self.__alias=None - self.__having=None - self.__group=None - self.__group1=None - self.__order=None - self.__order1=None - self.__limit=None - self.__field="*" - self.__where=None - self.__wheres=() - self.__table=None - self.__buildSql=None - self.__table=None - - __where=None - __wheres=() - def where(self,where = None,*wheres): - """设置过滤条件 - - 传入方式: - "id",2 表示id='2' - - "id","in",2,3,4,5,6,...表示 id in (2,3,4,5,6,...) - - "id","in",[2,3,4,5,6,...]表示 id in (2,3,4,5,6,...) - - - [("id","gt",6000),"and",("name","like","%超")] 表示 ( id > "6000" and name LIKE "%超" ) - - "id","eq",1 表示 id = '1' - - eq 等于 - neq 不等于 - gt 大于 - egt 大于等于 - lt 小于 - elt 小于等于 - like LIKE - """ - self.__where=where - self.__wheres=wheres - return self - __field='*' - def field(self,field = "*"): - """设置过滤显示条件 - - 参数 field:str 字符串 - """ - self.__field=field - return self - __limit=[] - def limit(self,offset, length = None): - """设置查询数量 - - 参数 offset:int 起始位置 - - 参数 length:int 查询数量 - """ - self.__limit=[offset,length] - return self - def page(self,pagenow=1, length = 20): - """设置分页查询 - - 参数 pagenow:int 页码 - - 参数 length:int 查询数量 - """ - offset=(pagenow-1)*length - self.__limit=[offset,length] - return self - __order=None - __order1=None - def order(self,strs=None,*strs1): - """设置排序查询 - - 传入方式: - - "id desc" - - "id",'name','appkey','asc' - - "id",'name','appkey' 不包含asc或desc的情况下 默认是desc - - ['id','taskid',{"task_id":"desc"}] - """ - self.__order=strs - self.__order1=strs1 - return self - __group=None - __group1=None - def group(self,strs=None,*strs1): - """设置分组查询 - - 传入方式: - - "id,name" - - "id","name" - """ - self.__group=strs - self.__group1=strs1 - return self - __having=None - def having(self,strs=None): - """用于配合group方法完成从分组的结果中筛选(通常是聚合条件)数据 - - 参数 strs:string 如:"count(time)>3" - """ - self.__having=strs - return self - __alias=None - def alias(self,strs=None): - """用于设置当前数据表的别名,便于使用其他的连贯操作例如join方法等。 - - 参数 strs:string 默认当前表作为别名 - """ - if strs: - self.__alias=strs - else: - self.__alias=self.__table - return self - __join=None - __joinstr='' - def join(self,strs,on=None,types='INNER'): - """用于根据两个或多个表中的列之间的关系,从这些表中查询数据 - - 参数 strs string 如:"test t1" test表设置别名t1 - - 参数 on string 如:"t1.id=t2.pid" 设置连接条件 - - 参数 types 支持INNER、LEFT、RIGHT、FULL 默认INNER - - """ - joinstr='' - if strs and on: - joinstr=joinstr+types+" JOIN "+strs+" ON "+on+" " - if joinstr: - self.__joinstr=self.__joinstr+joinstr - return self - __distinct=None - def distinct(self,bools=None): - "用于返回唯一不同的值,配合field方法使用生效,来消除所有重复的记录,并只获取唯一一次记录。" - self.__distinct=bools - return self - __lock=None - def lock(self,strs=None): - """用于数据库的锁机制,在查询或者执行操作的时候使用 - - 排他锁 (FOR UPDATE) - - 共享锁 (lock in share mode) - - 参数 strs 如:True表示自动在生成的SQL语句最后加上FOR UPDATE, - - - """ - self.__lock=strs - return self - - # __cache=[] - # def cache(self,endtime,tag=None): - # """设置查询缓存 - - # 参数 endtime:int 缓存数据 0永久 - - # 参数 tag:int 缓存标签 - # """ - # self.__cache=[endtime,tag] - # return self - def __setsql(self,types=None,data = {}): - """生成sql语句""" - if types==None: - self.__sql="SELECT" - if self.__distinct and self.__field: - self.__sql=self.__sql+" DISTINCT" - if self.__alias: - self.__sql=self.__sql+" %s FROM %s %s" % (self.__field,self.__table,self.__alias) - else: - self.__sql=self.__sql+" %s FROM %s" % (self.__field,self.__table) - elif types=='count': - self.__sql="SELECT COUNT(%s) FROM %s" % (self.__field,self.__table) - elif types=='max': - self.__sql="SELECT MAX(%s) FROM %s" % (self.__field,self.__table) - elif types=='min': - self.__sql="SELECT MIN(%s) FROM %s" % (self.__field,self.__table) - elif types=='avg': - self.__sql="SELECT AVG(%s) FROM %s" % (self.__field,self.__table) - elif types=='sum': - self.__sql="SELECT SUM(%s) FROM %s" % (self.__field,self.__table) - elif types=='update': - strs='' - for k in data: - if isinstance(data[k],str): - strs=strs+" %s = '%s' ," % (k,escape_string(data[k])) - else: - strs=strs+" %s = %s ," % (k,data[k]) - strs=strs[:-1] - self.__sql="UPDATE %s SET %s" % (self.__table,strs) - elif types=='delete': - self.__sql="DELETE FROM %s" % self.__table - elif types=='insert': - if isinstance(data,dict): - strs='' - val='' - for k in data: - strs=strs+"%s," % k - if isinstance(data[k],str): - val=val+"'%s'," % escape_string(data[k]) - else: - val=val+"%s," % data[k] - strs=strs[:-1] - val=val[:-1] - self.__sql="INSERT INTO %s (%s) VALUES (%s)" % (self.__table,strs,val) - elif isinstance(data,list): - strs='' - val='(' - for k in data[0]: - strs=strs+" , "+k - for k in data: - for j in k: - if isinstance(k[j],str): - val=val+"'"+str(k[j])+"'," - else: - val=val+str(k[j])+"," - val=val[:-1] - val=val+"),(" - val=val[:-2] - self.__sql="INSERT INTO "+self.__table+" ("+strs[3:]+") VALUES "+val - if self.__joinstr: - self.__sql=self.__sql+" "+self.__joinstr - if self.__where: - if isinstance(self.__where,str): - if self.__wheres: - if len(self.__wheres) == 2: - if isinstance(self.__wheres[1],list): - self.__sql=self.__sql + " WHERE %s %s (" % (self.__where,self.__operator(self.__wheres[0])) - for k in self.__wheres[1]: - self.__sql=self.__sql+str(k)+"," - self.__sql=self.__sql[:-1]+")" - else: - self.__sql=self.__sql + " WHERE %s %s '%s'" % (self.__where,self.__operator(self.__wheres[0]),self.__wheres[1]) - elif len(self.__wheres) > 2: - if self.__wheres[0]=='in': - strs=str(self.__wheres[1]) - i=0 - for k in self.__wheres: - if i > 1: - strs=strs+","+str(k) - i=i+1 - self.__sql=self.__sql + " WHERE %s in (%s)" % (self.__where,strs) - else: - self.__sql=self.__sql + " WHERE %s = '%s'" % (self.__where,self.__wheres[0]) - else: - self.__sql=self.__sql + " WHERE %s" % self.__where - elif isinstance(self.__where,list): - self.__sql=self.__sql + " WHERE %s" % self.__listTrans() - else: - print("参数where类型错误") - if self.__order: - s='' - if isinstance(self.__order,list): - for strs in self.__order: - if isinstance(strs,str): - s=s+strs+"," - else: - pass - for key in strs: - s=s+key+" "+strs[key] - s=s+"," - s=s[:-1] - if isinstance(self.__order,str): - if self.__order1: - if len(self.__order1) > 1: - if self.__order1[len(self.__order1)-1] == 'desc' or self.__order1[len(self.__order1)-1] == 'asc': - i=0 - while i Date: Thu, 28 May 2020 20:57:26 +0800 Subject: [PATCH 11/52] kun --- .gitignore => kcweb/.gitignore | 0 Events.py => kcweb/Events.py | 0 LICENSE => kcweb/LICENSE | 0 README.md => kcweb/README.md | 0 __init__.py => kcweb/__init__.py | 0 app.py => kcweb/app.py | 0 .../application}/__init__.py | 0 .../application}/api/__init__.py | 0 .../application}/api/common/__init__.py | 0 .../application}/api/common/autoload.py | 0 .../application}/api/controller/__init__.py | 0 .../api/controller/plug/__init__.py | 0 .../application}/api/controller/plug/index.py | 0 .../api/controller/plug1/__init__.py | 0 .../api/controller/plug1/index.py | 0 .../api/controller/plug2/__init__.py | 0 .../api/controller/plug2/index.py | 0 .../api/tpl/plug1/index/index.html | 0 .../api/tpl/plug2/index/index.html | 0 .../application}/common/__init__.py | 0 .../application}/common/autoload.py | 0 .../application}/config/__init__.py | 0 .../application}/config/other.py | 0 {common => kcweb/common}/__init__.py | 0 {common => kcweb/common}/autoload.py | 0 {common => kcweb/common}/globals.py | 0 {common => kcweb/common}/request.py | 0 {common => kcweb/common}/session.py | 0 {config => kcweb/config}/__init__.py | 6 +- kcweb/setup.py | 58 +++++++++++++++++++ {tpl => kcweb/tpl}/error.html | 0 {utill => kcweb/utill}/app.py | 0 {utill => kcweb/utill}/cache/cache.py | 0 {utill => kcweb/utill}/dateutil/__init__.py | 0 {utill => kcweb/utill}/dateutil/_common.py | 0 {utill => kcweb/utill}/dateutil/_version.py | 0 {utill => kcweb/utill}/dateutil/easter.py | 0 .../utill}/dateutil/parser/__init__.py | 0 .../utill}/dateutil/parser/_parser.py | 0 .../utill}/dateutil/parser/isoparser.py | 0 .../utill}/dateutil/relativedelta.py | 0 {utill => kcweb/utill}/dateutil/rrule.py | 0 .../utill}/dateutil/tz/__init__.py | 0 {utill => kcweb/utill}/dateutil/tz/_common.py | 0 .../utill}/dateutil/tz/_factories.py | 0 {utill => kcweb/utill}/dateutil/tz/tz.py | 0 {utill => kcweb/utill}/dateutil/tz/win.py | 0 {utill => kcweb/utill}/dateutil/tzwin.py | 0 {utill => kcweb/utill}/dateutil/utils.py | 0 .../utill}/dateutil/zoneinfo/__init__.py | 0 .../utill}/dateutil/zoneinfo/rebuild.py | 0 {utill => kcweb/utill}/db/model.py | 0 {utill => kcweb/utill}/db/mongodb.py | 0 {utill => kcweb/utill}/db/mysql.py | 0 {utill => kcweb/utill}/db/pymysql/__init__.py | 0 {utill => kcweb/utill}/db/pymysql/_auth.py | 0 {utill => kcweb/utill}/db/pymysql/_compat.py | 0 .../utill}/db/pymysql/_socketio.py | 0 {utill => kcweb/utill}/db/pymysql/charset.py | 0 .../utill}/db/pymysql/connections.py | 0 .../utill}/db/pymysql/constants/CLIENT.py | 0 .../utill}/db/pymysql/constants/COMMAND.py | 0 .../utill}/db/pymysql/constants/CR.py | 0 .../utill}/db/pymysql/constants/ER.py | 0 .../utill}/db/pymysql/constants/FIELD_TYPE.py | 0 .../utill}/db/pymysql/constants/FLAG.py | 0 .../db/pymysql/constants/SERVER_STATUS.py | 0 .../utill}/db/pymysql/constants/__init__.py | 0 .../utill}/db/pymysql/converters.py | 0 {utill => kcweb/utill}/db/pymysql/cursors.py | 0 {utill => kcweb/utill}/db/pymysql/err.py | 0 .../utill}/db/pymysql/optionfile.py | 0 {utill => kcweb/utill}/db/pymysql/protocol.py | 0 {utill => kcweb/utill}/db/pymysql/times.py | 0 {utill => kcweb/utill}/db/pymysql/util.py | 0 {utill => kcweb/utill}/db/sqlite.py | 0 {utill => kcweb/utill}/db/sqlitedata/kcwdb | 0 {utill => kcweb/utill}/filetype/__init__.py | 0 {utill => kcweb/utill}/filetype/filetype.py | 0 {utill => kcweb/utill}/filetype/helpers.py | 0 {utill => kcweb/utill}/filetype/match.py | 0 .../utill}/filetype/types/__init__.py | 0 .../utill}/filetype/types/archive.py | 0 .../utill}/filetype/types/audio.py | 0 {utill => kcweb/utill}/filetype/types/base.py | 0 {utill => kcweb/utill}/filetype/types/font.py | 0 .../utill}/filetype/types/image.py | 0 .../utill}/filetype/types/isobmff.py | 0 .../utill}/filetype/types/video.py | 0 {utill => kcweb/utill}/filetype/utils.py | 0 {utill => kcweb/utill}/http.py | 0 {utill => kcweb/utill}/queues.py | 0 {utill => kcweb/utill}/redis.py | 0 {utill => kcweb/utill}/rediss/__init__.py | 0 {utill => kcweb/utill}/rediss/_compat.py | 0 {utill => kcweb/utill}/rediss/client.py | 0 {utill => kcweb/utill}/rediss/connection.py | 0 {utill => kcweb/utill}/rediss/exceptions.py | 0 {utill => kcweb/utill}/rediss/lock.py | 0 {utill => kcweb/utill}/rediss/sentinel.py | 0 {utill => kcweb/utill}/rediss/utils.py | 0 server.py | 3 + setup.py | 8 +-- 103 files changed, 68 insertions(+), 7 deletions(-) rename .gitignore => kcweb/.gitignore (100%) rename Events.py => kcweb/Events.py (100%) rename LICENSE => kcweb/LICENSE (100%) rename README.md => kcweb/README.md (100%) rename __init__.py => kcweb/__init__.py (100%) rename app.py => kcweb/app.py (100%) rename {application => kcweb/application}/__init__.py (100%) rename {application => kcweb/application}/api/__init__.py (100%) rename {application => kcweb/application}/api/common/__init__.py (100%) rename {application => kcweb/application}/api/common/autoload.py (100%) rename {application => kcweb/application}/api/controller/__init__.py (100%) rename {application => kcweb/application}/api/controller/plug/__init__.py (100%) rename {application => kcweb/application}/api/controller/plug/index.py (100%) rename {application => kcweb/application}/api/controller/plug1/__init__.py (100%) rename {application => kcweb/application}/api/controller/plug1/index.py (100%) rename {application => kcweb/application}/api/controller/plug2/__init__.py (100%) rename {application => kcweb/application}/api/controller/plug2/index.py (100%) rename {application => kcweb/application}/api/tpl/plug1/index/index.html (100%) rename {application => kcweb/application}/api/tpl/plug2/index/index.html (100%) rename {application => kcweb/application}/common/__init__.py (100%) rename {application => kcweb/application}/common/autoload.py (100%) rename {application => kcweb/application}/config/__init__.py (100%) rename {application => kcweb/application}/config/other.py (100%) rename {common => kcweb/common}/__init__.py (100%) rename {common => kcweb/common}/autoload.py (100%) rename {common => kcweb/common}/globals.py (100%) rename {common => kcweb/common}/request.py (100%) rename {common => kcweb/common}/session.py (100%) rename {config => kcweb/config}/__init__.py (95%) create mode 100644 kcweb/setup.py rename {tpl => kcweb/tpl}/error.html (100%) rename {utill => kcweb/utill}/app.py (100%) rename {utill => kcweb/utill}/cache/cache.py (100%) rename {utill => kcweb/utill}/dateutil/__init__.py (100%) rename {utill => kcweb/utill}/dateutil/_common.py (100%) rename {utill => kcweb/utill}/dateutil/_version.py (100%) rename {utill => kcweb/utill}/dateutil/easter.py (100%) rename {utill => kcweb/utill}/dateutil/parser/__init__.py (100%) rename {utill => kcweb/utill}/dateutil/parser/_parser.py (100%) rename {utill => kcweb/utill}/dateutil/parser/isoparser.py (100%) rename {utill => kcweb/utill}/dateutil/relativedelta.py (100%) rename {utill => kcweb/utill}/dateutil/rrule.py (100%) rename {utill => kcweb/utill}/dateutil/tz/__init__.py (100%) rename {utill => kcweb/utill}/dateutil/tz/_common.py (100%) rename {utill => kcweb/utill}/dateutil/tz/_factories.py (100%) rename {utill => kcweb/utill}/dateutil/tz/tz.py (100%) rename {utill => kcweb/utill}/dateutil/tz/win.py (100%) rename {utill => kcweb/utill}/dateutil/tzwin.py (100%) rename {utill => kcweb/utill}/dateutil/utils.py (100%) rename {utill => kcweb/utill}/dateutil/zoneinfo/__init__.py (100%) rename {utill => kcweb/utill}/dateutil/zoneinfo/rebuild.py (100%) rename {utill => kcweb/utill}/db/model.py (100%) rename {utill => kcweb/utill}/db/mongodb.py (100%) rename {utill => kcweb/utill}/db/mysql.py (100%) rename {utill => kcweb/utill}/db/pymysql/__init__.py (100%) rename {utill => kcweb/utill}/db/pymysql/_auth.py (100%) rename {utill => kcweb/utill}/db/pymysql/_compat.py (100%) rename {utill => kcweb/utill}/db/pymysql/_socketio.py (100%) rename {utill => kcweb/utill}/db/pymysql/charset.py (100%) rename {utill => kcweb/utill}/db/pymysql/connections.py (100%) rename {utill => kcweb/utill}/db/pymysql/constants/CLIENT.py (100%) rename {utill => kcweb/utill}/db/pymysql/constants/COMMAND.py (100%) rename {utill => kcweb/utill}/db/pymysql/constants/CR.py (100%) rename {utill => kcweb/utill}/db/pymysql/constants/ER.py (100%) rename {utill => kcweb/utill}/db/pymysql/constants/FIELD_TYPE.py (100%) rename {utill => kcweb/utill}/db/pymysql/constants/FLAG.py (100%) rename {utill => kcweb/utill}/db/pymysql/constants/SERVER_STATUS.py (100%) rename {utill => kcweb/utill}/db/pymysql/constants/__init__.py (100%) rename {utill => kcweb/utill}/db/pymysql/converters.py (100%) rename {utill => kcweb/utill}/db/pymysql/cursors.py (100%) rename {utill => kcweb/utill}/db/pymysql/err.py (100%) rename {utill => kcweb/utill}/db/pymysql/optionfile.py (100%) rename {utill => kcweb/utill}/db/pymysql/protocol.py (100%) rename {utill => kcweb/utill}/db/pymysql/times.py (100%) rename {utill => kcweb/utill}/db/pymysql/util.py (100%) rename {utill => kcweb/utill}/db/sqlite.py (100%) rename {utill => kcweb/utill}/db/sqlitedata/kcwdb (100%) rename {utill => kcweb/utill}/filetype/__init__.py (100%) rename {utill => kcweb/utill}/filetype/filetype.py (100%) rename {utill => kcweb/utill}/filetype/helpers.py (100%) rename {utill => kcweb/utill}/filetype/match.py (100%) rename {utill => kcweb/utill}/filetype/types/__init__.py (100%) rename {utill => kcweb/utill}/filetype/types/archive.py (100%) rename {utill => kcweb/utill}/filetype/types/audio.py (100%) rename {utill => kcweb/utill}/filetype/types/base.py (100%) rename {utill => kcweb/utill}/filetype/types/font.py (100%) rename {utill => kcweb/utill}/filetype/types/image.py (100%) rename {utill => kcweb/utill}/filetype/types/isobmff.py (100%) rename {utill => kcweb/utill}/filetype/types/video.py (100%) rename {utill => kcweb/utill}/filetype/utils.py (100%) rename {utill => kcweb/utill}/http.py (100%) rename {utill => kcweb/utill}/queues.py (100%) rename {utill => kcweb/utill}/redis.py (100%) rename {utill => kcweb/utill}/rediss/__init__.py (100%) rename {utill => kcweb/utill}/rediss/_compat.py (100%) rename {utill => kcweb/utill}/rediss/client.py (100%) rename {utill => kcweb/utill}/rediss/connection.py (100%) rename {utill => kcweb/utill}/rediss/exceptions.py (100%) rename {utill => kcweb/utill}/rediss/lock.py (100%) rename {utill => kcweb/utill}/rediss/sentinel.py (100%) rename {utill => kcweb/utill}/rediss/utils.py (100%) create mode 100644 server.py diff --git a/.gitignore b/kcweb/.gitignore similarity index 100% rename from .gitignore rename to kcweb/.gitignore diff --git a/Events.py b/kcweb/Events.py similarity index 100% rename from Events.py rename to kcweb/Events.py diff --git a/LICENSE b/kcweb/LICENSE similarity index 100% rename from LICENSE rename to kcweb/LICENSE diff --git a/README.md b/kcweb/README.md similarity index 100% rename from README.md rename to kcweb/README.md diff --git a/__init__.py b/kcweb/__init__.py similarity index 100% rename from __init__.py rename to kcweb/__init__.py diff --git a/app.py b/kcweb/app.py similarity index 100% rename from app.py rename to kcweb/app.py diff --git a/application/__init__.py b/kcweb/application/__init__.py similarity index 100% rename from application/__init__.py rename to kcweb/application/__init__.py diff --git a/application/api/__init__.py b/kcweb/application/api/__init__.py similarity index 100% rename from application/api/__init__.py rename to kcweb/application/api/__init__.py diff --git a/application/api/common/__init__.py b/kcweb/application/api/common/__init__.py similarity index 100% rename from application/api/common/__init__.py rename to kcweb/application/api/common/__init__.py diff --git a/application/api/common/autoload.py b/kcweb/application/api/common/autoload.py similarity index 100% rename from application/api/common/autoload.py rename to kcweb/application/api/common/autoload.py diff --git a/application/api/controller/__init__.py b/kcweb/application/api/controller/__init__.py similarity index 100% rename from application/api/controller/__init__.py rename to kcweb/application/api/controller/__init__.py diff --git a/application/api/controller/plug/__init__.py b/kcweb/application/api/controller/plug/__init__.py similarity index 100% rename from application/api/controller/plug/__init__.py rename to kcweb/application/api/controller/plug/__init__.py diff --git a/application/api/controller/plug/index.py b/kcweb/application/api/controller/plug/index.py similarity index 100% rename from application/api/controller/plug/index.py rename to kcweb/application/api/controller/plug/index.py diff --git a/application/api/controller/plug1/__init__.py b/kcweb/application/api/controller/plug1/__init__.py similarity index 100% rename from application/api/controller/plug1/__init__.py rename to kcweb/application/api/controller/plug1/__init__.py diff --git a/application/api/controller/plug1/index.py b/kcweb/application/api/controller/plug1/index.py similarity index 100% rename from application/api/controller/plug1/index.py rename to kcweb/application/api/controller/plug1/index.py diff --git a/application/api/controller/plug2/__init__.py b/kcweb/application/api/controller/plug2/__init__.py similarity index 100% rename from application/api/controller/plug2/__init__.py rename to kcweb/application/api/controller/plug2/__init__.py diff --git a/application/api/controller/plug2/index.py b/kcweb/application/api/controller/plug2/index.py similarity index 100% rename from application/api/controller/plug2/index.py rename to kcweb/application/api/controller/plug2/index.py diff --git a/application/api/tpl/plug1/index/index.html b/kcweb/application/api/tpl/plug1/index/index.html similarity index 100% rename from application/api/tpl/plug1/index/index.html rename to kcweb/application/api/tpl/plug1/index/index.html diff --git a/application/api/tpl/plug2/index/index.html b/kcweb/application/api/tpl/plug2/index/index.html similarity index 100% rename from application/api/tpl/plug2/index/index.html rename to kcweb/application/api/tpl/plug2/index/index.html diff --git a/application/common/__init__.py b/kcweb/application/common/__init__.py similarity index 100% rename from application/common/__init__.py rename to kcweb/application/common/__init__.py diff --git a/application/common/autoload.py b/kcweb/application/common/autoload.py similarity index 100% rename from application/common/autoload.py rename to kcweb/application/common/autoload.py diff --git a/application/config/__init__.py b/kcweb/application/config/__init__.py similarity index 100% rename from application/config/__init__.py rename to kcweb/application/config/__init__.py diff --git a/application/config/other.py b/kcweb/application/config/other.py similarity index 100% rename from application/config/other.py rename to kcweb/application/config/other.py diff --git a/common/__init__.py b/kcweb/common/__init__.py similarity index 100% rename from common/__init__.py rename to kcweb/common/__init__.py diff --git a/common/autoload.py b/kcweb/common/autoload.py similarity index 100% rename from common/autoload.py rename to kcweb/common/autoload.py diff --git a/common/globals.py b/kcweb/common/globals.py similarity index 100% rename from common/globals.py rename to kcweb/common/globals.py diff --git a/common/request.py b/kcweb/common/request.py similarity index 100% rename from common/request.py rename to kcweb/common/request.py diff --git a/common/session.py b/kcweb/common/session.py similarity index 100% rename from common/session.py rename to kcweb/common/session.py diff --git a/config/__init__.py b/kcweb/config/__init__.py similarity index 95% rename from config/__init__.py rename to kcweb/config/__init__.py index 427043a..d8a17cf 100644 --- a/config/__init__.py +++ b/kcweb/config/__init__.py @@ -90,11 +90,11 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='2.40.9' #项目版本 -kcweb['description']='基于python后端开发框架' #项目的简单描述 +kcweb['version']='3.0.0' #项目版本 +kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 -kcweb['url']='http://intapp.kwebapp.cn/index/index/doc/docde/1' +kcweb['url']='' kcweb['author']='禄可集团-坤坤' #名字 kcweb['author_email']='fk1402936534@qq.com' #邮件地址 kcweb['maintainer']='坤坤' #维护人员的名字 diff --git a/kcweb/setup.py b/kcweb/setup.py new file mode 100644 index 0000000..99a4a9d --- /dev/null +++ b/kcweb/setup.py @@ -0,0 +1,58 @@ + +# python setup.py sdist upload +# twine upload --repository-url https://test.pypi.org/legacy/ dist/* #上传到测试 +# pip install --index-url https://test.pypi.org/simple/ kcweb #安装测试服务上的kcweb +############################################# +from setuptools import setup, find_packages,Extension +import os +def file_get_content(k): + "获取文件内容" + if os.path.isfile(k): + f=open(k,'r',encoding="utf-8") + con=f.read() + f.close() + else: + con='' + return con +confkcw={} +confkcw['name']='kcweb' #项目的名称 +confkcw['version']='3.0.0' #项目版本 +confkcw['description']='' #项目的简单描述 +confkcw['long_description']="" #项目详细描述 +confkcw['license']='MIT License' #开源协议 mit开源 +confkcw['url']='' +confkcw['author']='禄可集团-坤坤' #名字 +confkcw['author_email']='fk1402936534@qq.com' #邮件地址 +confkcw['maintainer']='坤坤' #维护人员的名字 +confkcw['maintainer_email']='fk1402936534@qq.com' #维护人员的邮件地址 +def get_file(folder='./',lists=[]): + lis=os.listdir(folder) + for files in lis: + if not os.path.isfile(folder+"/"+files): + if files=='__pycache__' or files=='.git': + pass + else: + lists.append(folder+"/"+files) + get_file(folder+"/"+files,lists) + else: + pass + return lists +b=get_file("kcweb",['kcweb']) +setup( + name = confkcw["name"], + version = confkcw["version"], + keywords = "kcweb"+confkcw['version'], + description = confkcw["description"], + long_description = confkcw["long_description"], + license = confkcw["license"], + author = confkcw["author"], + author_email = confkcw["author_email"], + maintainer = confkcw["maintainer"], + maintainer_email = confkcw["maintainer_email"], + url=confkcw['url'], + packages = b, + install_requires = ['pymongo>=3.10.0','Mako>=1.1.2','requests>=2.23.0','six>=1.12.0','watchdog>=0.9.0'], #第三方包 + package_data = { + '': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'], + } +) \ No newline at end of file diff --git a/tpl/error.html b/kcweb/tpl/error.html similarity index 100% rename from tpl/error.html rename to kcweb/tpl/error.html diff --git a/utill/app.py b/kcweb/utill/app.py similarity index 100% rename from utill/app.py rename to kcweb/utill/app.py diff --git a/utill/cache/cache.py b/kcweb/utill/cache/cache.py similarity index 100% rename from utill/cache/cache.py rename to kcweb/utill/cache/cache.py diff --git a/utill/dateutil/__init__.py b/kcweb/utill/dateutil/__init__.py similarity index 100% rename from utill/dateutil/__init__.py rename to kcweb/utill/dateutil/__init__.py diff --git a/utill/dateutil/_common.py b/kcweb/utill/dateutil/_common.py similarity index 100% rename from utill/dateutil/_common.py rename to kcweb/utill/dateutil/_common.py diff --git a/utill/dateutil/_version.py b/kcweb/utill/dateutil/_version.py similarity index 100% rename from utill/dateutil/_version.py rename to kcweb/utill/dateutil/_version.py diff --git a/utill/dateutil/easter.py b/kcweb/utill/dateutil/easter.py similarity index 100% rename from utill/dateutil/easter.py rename to kcweb/utill/dateutil/easter.py diff --git a/utill/dateutil/parser/__init__.py b/kcweb/utill/dateutil/parser/__init__.py similarity index 100% rename from utill/dateutil/parser/__init__.py rename to kcweb/utill/dateutil/parser/__init__.py diff --git a/utill/dateutil/parser/_parser.py b/kcweb/utill/dateutil/parser/_parser.py similarity index 100% rename from utill/dateutil/parser/_parser.py rename to kcweb/utill/dateutil/parser/_parser.py diff --git a/utill/dateutil/parser/isoparser.py b/kcweb/utill/dateutil/parser/isoparser.py similarity index 100% rename from utill/dateutil/parser/isoparser.py rename to kcweb/utill/dateutil/parser/isoparser.py diff --git a/utill/dateutil/relativedelta.py b/kcweb/utill/dateutil/relativedelta.py similarity index 100% rename from utill/dateutil/relativedelta.py rename to kcweb/utill/dateutil/relativedelta.py diff --git a/utill/dateutil/rrule.py b/kcweb/utill/dateutil/rrule.py similarity index 100% rename from utill/dateutil/rrule.py rename to kcweb/utill/dateutil/rrule.py diff --git a/utill/dateutil/tz/__init__.py b/kcweb/utill/dateutil/tz/__init__.py similarity index 100% rename from utill/dateutil/tz/__init__.py rename to kcweb/utill/dateutil/tz/__init__.py diff --git a/utill/dateutil/tz/_common.py b/kcweb/utill/dateutil/tz/_common.py similarity index 100% rename from utill/dateutil/tz/_common.py rename to kcweb/utill/dateutil/tz/_common.py diff --git a/utill/dateutil/tz/_factories.py b/kcweb/utill/dateutil/tz/_factories.py similarity index 100% rename from utill/dateutil/tz/_factories.py rename to kcweb/utill/dateutil/tz/_factories.py diff --git a/utill/dateutil/tz/tz.py b/kcweb/utill/dateutil/tz/tz.py similarity index 100% rename from utill/dateutil/tz/tz.py rename to kcweb/utill/dateutil/tz/tz.py diff --git a/utill/dateutil/tz/win.py b/kcweb/utill/dateutil/tz/win.py similarity index 100% rename from utill/dateutil/tz/win.py rename to kcweb/utill/dateutil/tz/win.py diff --git a/utill/dateutil/tzwin.py b/kcweb/utill/dateutil/tzwin.py similarity index 100% rename from utill/dateutil/tzwin.py rename to kcweb/utill/dateutil/tzwin.py diff --git a/utill/dateutil/utils.py b/kcweb/utill/dateutil/utils.py similarity index 100% rename from utill/dateutil/utils.py rename to kcweb/utill/dateutil/utils.py diff --git a/utill/dateutil/zoneinfo/__init__.py b/kcweb/utill/dateutil/zoneinfo/__init__.py similarity index 100% rename from utill/dateutil/zoneinfo/__init__.py rename to kcweb/utill/dateutil/zoneinfo/__init__.py diff --git a/utill/dateutil/zoneinfo/rebuild.py b/kcweb/utill/dateutil/zoneinfo/rebuild.py similarity index 100% rename from utill/dateutil/zoneinfo/rebuild.py rename to kcweb/utill/dateutil/zoneinfo/rebuild.py diff --git a/utill/db/model.py b/kcweb/utill/db/model.py similarity index 100% rename from utill/db/model.py rename to kcweb/utill/db/model.py diff --git a/utill/db/mongodb.py b/kcweb/utill/db/mongodb.py similarity index 100% rename from utill/db/mongodb.py rename to kcweb/utill/db/mongodb.py diff --git a/utill/db/mysql.py b/kcweb/utill/db/mysql.py similarity index 100% rename from utill/db/mysql.py rename to kcweb/utill/db/mysql.py diff --git a/utill/db/pymysql/__init__.py b/kcweb/utill/db/pymysql/__init__.py similarity index 100% rename from utill/db/pymysql/__init__.py rename to kcweb/utill/db/pymysql/__init__.py diff --git a/utill/db/pymysql/_auth.py b/kcweb/utill/db/pymysql/_auth.py similarity index 100% rename from utill/db/pymysql/_auth.py rename to kcweb/utill/db/pymysql/_auth.py diff --git a/utill/db/pymysql/_compat.py b/kcweb/utill/db/pymysql/_compat.py similarity index 100% rename from utill/db/pymysql/_compat.py rename to kcweb/utill/db/pymysql/_compat.py diff --git a/utill/db/pymysql/_socketio.py b/kcweb/utill/db/pymysql/_socketio.py similarity index 100% rename from utill/db/pymysql/_socketio.py rename to kcweb/utill/db/pymysql/_socketio.py diff --git a/utill/db/pymysql/charset.py b/kcweb/utill/db/pymysql/charset.py similarity index 100% rename from utill/db/pymysql/charset.py rename to kcweb/utill/db/pymysql/charset.py diff --git a/utill/db/pymysql/connections.py b/kcweb/utill/db/pymysql/connections.py similarity index 100% rename from utill/db/pymysql/connections.py rename to kcweb/utill/db/pymysql/connections.py diff --git a/utill/db/pymysql/constants/CLIENT.py b/kcweb/utill/db/pymysql/constants/CLIENT.py similarity index 100% rename from utill/db/pymysql/constants/CLIENT.py rename to kcweb/utill/db/pymysql/constants/CLIENT.py diff --git a/utill/db/pymysql/constants/COMMAND.py b/kcweb/utill/db/pymysql/constants/COMMAND.py similarity index 100% rename from utill/db/pymysql/constants/COMMAND.py rename to kcweb/utill/db/pymysql/constants/COMMAND.py diff --git a/utill/db/pymysql/constants/CR.py b/kcweb/utill/db/pymysql/constants/CR.py similarity index 100% rename from utill/db/pymysql/constants/CR.py rename to kcweb/utill/db/pymysql/constants/CR.py diff --git a/utill/db/pymysql/constants/ER.py b/kcweb/utill/db/pymysql/constants/ER.py similarity index 100% rename from utill/db/pymysql/constants/ER.py rename to kcweb/utill/db/pymysql/constants/ER.py diff --git a/utill/db/pymysql/constants/FIELD_TYPE.py b/kcweb/utill/db/pymysql/constants/FIELD_TYPE.py similarity index 100% rename from utill/db/pymysql/constants/FIELD_TYPE.py rename to kcweb/utill/db/pymysql/constants/FIELD_TYPE.py diff --git a/utill/db/pymysql/constants/FLAG.py b/kcweb/utill/db/pymysql/constants/FLAG.py similarity index 100% rename from utill/db/pymysql/constants/FLAG.py rename to kcweb/utill/db/pymysql/constants/FLAG.py diff --git a/utill/db/pymysql/constants/SERVER_STATUS.py b/kcweb/utill/db/pymysql/constants/SERVER_STATUS.py similarity index 100% rename from utill/db/pymysql/constants/SERVER_STATUS.py rename to kcweb/utill/db/pymysql/constants/SERVER_STATUS.py diff --git a/utill/db/pymysql/constants/__init__.py b/kcweb/utill/db/pymysql/constants/__init__.py similarity index 100% rename from utill/db/pymysql/constants/__init__.py rename to kcweb/utill/db/pymysql/constants/__init__.py diff --git a/utill/db/pymysql/converters.py b/kcweb/utill/db/pymysql/converters.py similarity index 100% rename from utill/db/pymysql/converters.py rename to kcweb/utill/db/pymysql/converters.py diff --git a/utill/db/pymysql/cursors.py b/kcweb/utill/db/pymysql/cursors.py similarity index 100% rename from utill/db/pymysql/cursors.py rename to kcweb/utill/db/pymysql/cursors.py diff --git a/utill/db/pymysql/err.py b/kcweb/utill/db/pymysql/err.py similarity index 100% rename from utill/db/pymysql/err.py rename to kcweb/utill/db/pymysql/err.py diff --git a/utill/db/pymysql/optionfile.py b/kcweb/utill/db/pymysql/optionfile.py similarity index 100% rename from utill/db/pymysql/optionfile.py rename to kcweb/utill/db/pymysql/optionfile.py diff --git a/utill/db/pymysql/protocol.py b/kcweb/utill/db/pymysql/protocol.py similarity index 100% rename from utill/db/pymysql/protocol.py rename to kcweb/utill/db/pymysql/protocol.py diff --git a/utill/db/pymysql/times.py b/kcweb/utill/db/pymysql/times.py similarity index 100% rename from utill/db/pymysql/times.py rename to kcweb/utill/db/pymysql/times.py diff --git a/utill/db/pymysql/util.py b/kcweb/utill/db/pymysql/util.py similarity index 100% rename from utill/db/pymysql/util.py rename to kcweb/utill/db/pymysql/util.py diff --git a/utill/db/sqlite.py b/kcweb/utill/db/sqlite.py similarity index 100% rename from utill/db/sqlite.py rename to kcweb/utill/db/sqlite.py diff --git a/utill/db/sqlitedata/kcwdb b/kcweb/utill/db/sqlitedata/kcwdb similarity index 100% rename from utill/db/sqlitedata/kcwdb rename to kcweb/utill/db/sqlitedata/kcwdb diff --git a/utill/filetype/__init__.py b/kcweb/utill/filetype/__init__.py similarity index 100% rename from utill/filetype/__init__.py rename to kcweb/utill/filetype/__init__.py diff --git a/utill/filetype/filetype.py b/kcweb/utill/filetype/filetype.py similarity index 100% rename from utill/filetype/filetype.py rename to kcweb/utill/filetype/filetype.py diff --git a/utill/filetype/helpers.py b/kcweb/utill/filetype/helpers.py similarity index 100% rename from utill/filetype/helpers.py rename to kcweb/utill/filetype/helpers.py diff --git a/utill/filetype/match.py b/kcweb/utill/filetype/match.py similarity index 100% rename from utill/filetype/match.py rename to kcweb/utill/filetype/match.py diff --git a/utill/filetype/types/__init__.py b/kcweb/utill/filetype/types/__init__.py similarity index 100% rename from utill/filetype/types/__init__.py rename to kcweb/utill/filetype/types/__init__.py diff --git a/utill/filetype/types/archive.py b/kcweb/utill/filetype/types/archive.py similarity index 100% rename from utill/filetype/types/archive.py rename to kcweb/utill/filetype/types/archive.py diff --git a/utill/filetype/types/audio.py b/kcweb/utill/filetype/types/audio.py similarity index 100% rename from utill/filetype/types/audio.py rename to kcweb/utill/filetype/types/audio.py diff --git a/utill/filetype/types/base.py b/kcweb/utill/filetype/types/base.py similarity index 100% rename from utill/filetype/types/base.py rename to kcweb/utill/filetype/types/base.py diff --git a/utill/filetype/types/font.py b/kcweb/utill/filetype/types/font.py similarity index 100% rename from utill/filetype/types/font.py rename to kcweb/utill/filetype/types/font.py diff --git a/utill/filetype/types/image.py b/kcweb/utill/filetype/types/image.py similarity index 100% rename from utill/filetype/types/image.py rename to kcweb/utill/filetype/types/image.py diff --git a/utill/filetype/types/isobmff.py b/kcweb/utill/filetype/types/isobmff.py similarity index 100% rename from utill/filetype/types/isobmff.py rename to kcweb/utill/filetype/types/isobmff.py diff --git a/utill/filetype/types/video.py b/kcweb/utill/filetype/types/video.py similarity index 100% rename from utill/filetype/types/video.py rename to kcweb/utill/filetype/types/video.py diff --git a/utill/filetype/utils.py b/kcweb/utill/filetype/utils.py similarity index 100% rename from utill/filetype/utils.py rename to kcweb/utill/filetype/utils.py diff --git a/utill/http.py b/kcweb/utill/http.py similarity index 100% rename from utill/http.py rename to kcweb/utill/http.py diff --git a/utill/queues.py b/kcweb/utill/queues.py similarity index 100% rename from utill/queues.py rename to kcweb/utill/queues.py diff --git a/utill/redis.py b/kcweb/utill/redis.py similarity index 100% rename from utill/redis.py rename to kcweb/utill/redis.py diff --git a/utill/rediss/__init__.py b/kcweb/utill/rediss/__init__.py similarity index 100% rename from utill/rediss/__init__.py rename to kcweb/utill/rediss/__init__.py diff --git a/utill/rediss/_compat.py b/kcweb/utill/rediss/_compat.py similarity index 100% rename from utill/rediss/_compat.py rename to kcweb/utill/rediss/_compat.py diff --git a/utill/rediss/client.py b/kcweb/utill/rediss/client.py similarity index 100% rename from utill/rediss/client.py rename to kcweb/utill/rediss/client.py diff --git a/utill/rediss/connection.py b/kcweb/utill/rediss/connection.py similarity index 100% rename from utill/rediss/connection.py rename to kcweb/utill/rediss/connection.py diff --git a/utill/rediss/exceptions.py b/kcweb/utill/rediss/exceptions.py similarity index 100% rename from utill/rediss/exceptions.py rename to kcweb/utill/rediss/exceptions.py diff --git a/utill/rediss/lock.py b/kcweb/utill/rediss/lock.py similarity index 100% rename from utill/rediss/lock.py rename to kcweb/utill/rediss/lock.py diff --git a/utill/rediss/sentinel.py b/kcweb/utill/rediss/sentinel.py similarity index 100% rename from utill/rediss/sentinel.py rename to kcweb/utill/rediss/sentinel.py diff --git a/utill/rediss/utils.py b/kcweb/utill/rediss/utils.py similarity index 100% rename from utill/rediss/utils.py rename to kcweb/utill/rediss/utils.py diff --git a/server.py b/server.py new file mode 100644 index 0000000..359d84f --- /dev/null +++ b/server.py @@ -0,0 +1,3 @@ +from kcweb.common import * #导入kcweb框架所有模块 +server=create("app","api") #创建一个应用和模块实例 +server.installmodular() #在应用下安装模块 (取决于create的参数) \ No newline at end of file diff --git a/setup.py b/setup.py index dec34f5..99a4a9d 100644 --- a/setup.py +++ b/setup.py @@ -16,11 +16,11 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='2.40.9' #项目版本 -confkcw['description']='基于python后端开发框架' #项目的简单描述 -confkcw['long_description']="完整文档:http://intapp.kwebapp.cn/doc/docde?id=1" #项目详细描述 +confkcw['version']='3.0.0' #项目版本 +confkcw['description']='' #项目的简单描述 +confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -confkcw['url']='http://intapp.kwebapp.cn/doc/docde?id=1' +confkcw['url']='' confkcw['author']='禄可集团-坤坤' #名字 confkcw['author_email']='fk1402936534@qq.com' #邮件地址 confkcw['maintainer']='坤坤' #维护人员的名字 -- Gitee From ff1b5ba18c3ddf89e2af0edf909d81af09c99436 Mon Sep 17 00:00:00 2001 From: kunkun Date: Fri, 29 May 2020 22:45:55 +0800 Subject: [PATCH 12/52] kun --- kcweb/.gitignore => .gitignore | 0 kcweb/Events.py => Events.py | 0 kcweb/LICENSE => LICENSE | 0 kcweb/README.md => README.md | 0 kcweb/__init__.py => __init__.py | 0 kcweb/app.py => app.py | 0 .../application => application}/__init__.py | 0 .../api/__init__.py | 0 .../api/common/__init__.py | 0 .../api/common/autoload.py | 0 .../api/controller/__init__.py | 0 .../api/controller/plug/__init__.py | 0 .../api/controller/plug/index.py | 0 .../api/controller/plug1/__init__.py | 0 .../api/controller/plug1/index.py | 0 .../api/controller/plug2/__init__.py | 0 .../api/controller/plug2/index.py | 0 .../api/tpl/plug1/index/index.html | 0 .../api/tpl/plug2/index/index.html | 0 .../common/__init__.py | 0 .../common/autoload.py | 0 .../config/__init__.py | 0 .../config/other.py | 0 {kcweb/common => common}/__init__.py | 0 {kcweb/common => common}/autoload.py | 9 ++- {kcweb/common => common}/globals.py | 0 {kcweb/common => common}/request.py | 0 {kcweb/common => common}/session.py | 0 {kcweb/config => config}/__init__.py | 0 kcweb/setup.py | 58 ------------------- server.py | 3 - {kcweb/tpl => tpl}/error.html | 0 {kcweb/utill => utill}/app.py | 0 {kcweb/utill => utill}/cache/cache.py | 0 {kcweb/utill => utill}/dateutil/__init__.py | 0 {kcweb/utill => utill}/dateutil/_common.py | 0 {kcweb/utill => utill}/dateutil/_version.py | 0 {kcweb/utill => utill}/dateutil/easter.py | 0 .../dateutil/parser/__init__.py | 0 .../dateutil/parser/_parser.py | 0 .../dateutil/parser/isoparser.py | 0 .../utill => utill}/dateutil/relativedelta.py | 0 {kcweb/utill => utill}/dateutil/rrule.py | 0 .../utill => utill}/dateutil/tz/__init__.py | 0 {kcweb/utill => utill}/dateutil/tz/_common.py | 0 .../utill => utill}/dateutil/tz/_factories.py | 0 {kcweb/utill => utill}/dateutil/tz/tz.py | 0 {kcweb/utill => utill}/dateutil/tz/win.py | 0 {kcweb/utill => utill}/dateutil/tzwin.py | 0 {kcweb/utill => utill}/dateutil/utils.py | 0 .../dateutil/zoneinfo/__init__.py | 0 .../dateutil/zoneinfo/rebuild.py | 0 {kcweb/utill => utill}/db/model.py | 0 {kcweb/utill => utill}/db/mongodb.py | 0 {kcweb/utill => utill}/db/mysql.py | 0 {kcweb/utill => utill}/db/pymysql/__init__.py | 0 {kcweb/utill => utill}/db/pymysql/_auth.py | 0 {kcweb/utill => utill}/db/pymysql/_compat.py | 0 .../utill => utill}/db/pymysql/_socketio.py | 0 {kcweb/utill => utill}/db/pymysql/charset.py | 0 .../utill => utill}/db/pymysql/connections.py | 0 .../db/pymysql/constants/CLIENT.py | 0 .../db/pymysql/constants/COMMAND.py | 0 .../db/pymysql/constants/CR.py | 0 .../db/pymysql/constants/ER.py | 0 .../db/pymysql/constants/FIELD_TYPE.py | 0 .../db/pymysql/constants/FLAG.py | 0 .../db/pymysql/constants/SERVER_STATUS.py | 0 .../db/pymysql/constants/__init__.py | 0 .../utill => utill}/db/pymysql/converters.py | 0 {kcweb/utill => utill}/db/pymysql/cursors.py | 0 {kcweb/utill => utill}/db/pymysql/err.py | 0 .../utill => utill}/db/pymysql/optionfile.py | 0 {kcweb/utill => utill}/db/pymysql/protocol.py | 0 {kcweb/utill => utill}/db/pymysql/times.py | 0 {kcweb/utill => utill}/db/pymysql/util.py | 0 {kcweb/utill => utill}/db/sqlite.py | 0 {kcweb/utill => utill}/db/sqlitedata/kcwdb | 0 {kcweb/utill => utill}/filetype/__init__.py | 0 {kcweb/utill => utill}/filetype/filetype.py | 0 {kcweb/utill => utill}/filetype/helpers.py | 0 {kcweb/utill => utill}/filetype/match.py | 0 .../filetype/types/__init__.py | 0 .../utill => utill}/filetype/types/archive.py | 0 .../utill => utill}/filetype/types/audio.py | 0 {kcweb/utill => utill}/filetype/types/base.py | 0 {kcweb/utill => utill}/filetype/types/font.py | 0 .../utill => utill}/filetype/types/image.py | 0 .../utill => utill}/filetype/types/isobmff.py | 0 .../utill => utill}/filetype/types/video.py | 0 {kcweb/utill => utill}/filetype/utils.py | 0 {kcweb/utill => utill}/http.py | 0 {kcweb/utill => utill}/queues.py | 0 {kcweb/utill => utill}/redis.py | 0 {kcweb/utill => utill}/rediss/__init__.py | 0 {kcweb/utill => utill}/rediss/_compat.py | 0 {kcweb/utill => utill}/rediss/client.py | 0 {kcweb/utill => utill}/rediss/connection.py | 0 {kcweb/utill => utill}/rediss/exceptions.py | 0 {kcweb/utill => utill}/rediss/lock.py | 0 {kcweb/utill => utill}/rediss/sentinel.py | 0 {kcweb/utill => utill}/rediss/utils.py | 0 102 files changed, 4 insertions(+), 66 deletions(-) rename kcweb/.gitignore => .gitignore (100%) rename kcweb/Events.py => Events.py (100%) rename kcweb/LICENSE => LICENSE (100%) rename kcweb/README.md => README.md (100%) rename kcweb/__init__.py => __init__.py (100%) rename kcweb/app.py => app.py (100%) rename {kcweb/application => application}/__init__.py (100%) rename {kcweb/application => application}/api/__init__.py (100%) rename {kcweb/application => application}/api/common/__init__.py (100%) rename {kcweb/application => application}/api/common/autoload.py (100%) rename {kcweb/application => application}/api/controller/__init__.py (100%) rename {kcweb/application => application}/api/controller/plug/__init__.py (100%) rename {kcweb/application => application}/api/controller/plug/index.py (100%) rename {kcweb/application => application}/api/controller/plug1/__init__.py (100%) rename {kcweb/application => application}/api/controller/plug1/index.py (100%) rename {kcweb/application => application}/api/controller/plug2/__init__.py (100%) rename {kcweb/application => application}/api/controller/plug2/index.py (100%) rename {kcweb/application => application}/api/tpl/plug1/index/index.html (100%) rename {kcweb/application => application}/api/tpl/plug2/index/index.html (100%) rename {kcweb/application => application}/common/__init__.py (100%) rename {kcweb/application => application}/common/autoload.py (100%) rename {kcweb/application => application}/config/__init__.py (100%) rename {kcweb/application => application}/config/other.py (100%) rename {kcweb/common => common}/__init__.py (100%) rename {kcweb/common => common}/autoload.py (99%) rename {kcweb/common => common}/globals.py (100%) rename {kcweb/common => common}/request.py (100%) rename {kcweb/common => common}/session.py (100%) rename {kcweb/config => config}/__init__.py (100%) delete mode 100644 kcweb/setup.py delete mode 100644 server.py rename {kcweb/tpl => tpl}/error.html (100%) rename {kcweb/utill => utill}/app.py (100%) rename {kcweb/utill => utill}/cache/cache.py (100%) rename {kcweb/utill => utill}/dateutil/__init__.py (100%) rename {kcweb/utill => utill}/dateutil/_common.py (100%) rename {kcweb/utill => utill}/dateutil/_version.py (100%) rename {kcweb/utill => utill}/dateutil/easter.py (100%) rename {kcweb/utill => utill}/dateutil/parser/__init__.py (100%) rename {kcweb/utill => utill}/dateutil/parser/_parser.py (100%) rename {kcweb/utill => utill}/dateutil/parser/isoparser.py (100%) rename {kcweb/utill => utill}/dateutil/relativedelta.py (100%) rename {kcweb/utill => utill}/dateutil/rrule.py (100%) rename {kcweb/utill => utill}/dateutil/tz/__init__.py (100%) rename {kcweb/utill => utill}/dateutil/tz/_common.py (100%) rename {kcweb/utill => utill}/dateutil/tz/_factories.py (100%) rename {kcweb/utill => utill}/dateutil/tz/tz.py (100%) rename {kcweb/utill => utill}/dateutil/tz/win.py (100%) rename {kcweb/utill => utill}/dateutil/tzwin.py (100%) rename {kcweb/utill => utill}/dateutil/utils.py (100%) rename {kcweb/utill => utill}/dateutil/zoneinfo/__init__.py (100%) rename {kcweb/utill => utill}/dateutil/zoneinfo/rebuild.py (100%) rename {kcweb/utill => utill}/db/model.py (100%) rename {kcweb/utill => utill}/db/mongodb.py (100%) rename {kcweb/utill => utill}/db/mysql.py (100%) rename {kcweb/utill => utill}/db/pymysql/__init__.py (100%) rename {kcweb/utill => utill}/db/pymysql/_auth.py (100%) rename {kcweb/utill => utill}/db/pymysql/_compat.py (100%) rename {kcweb/utill => utill}/db/pymysql/_socketio.py (100%) rename {kcweb/utill => utill}/db/pymysql/charset.py (100%) rename {kcweb/utill => utill}/db/pymysql/connections.py (100%) rename {kcweb/utill => utill}/db/pymysql/constants/CLIENT.py (100%) rename {kcweb/utill => utill}/db/pymysql/constants/COMMAND.py (100%) rename {kcweb/utill => utill}/db/pymysql/constants/CR.py (100%) rename {kcweb/utill => utill}/db/pymysql/constants/ER.py (100%) rename {kcweb/utill => utill}/db/pymysql/constants/FIELD_TYPE.py (100%) rename {kcweb/utill => utill}/db/pymysql/constants/FLAG.py (100%) rename {kcweb/utill => utill}/db/pymysql/constants/SERVER_STATUS.py (100%) rename {kcweb/utill => utill}/db/pymysql/constants/__init__.py (100%) rename {kcweb/utill => utill}/db/pymysql/converters.py (100%) rename {kcweb/utill => utill}/db/pymysql/cursors.py (100%) rename {kcweb/utill => utill}/db/pymysql/err.py (100%) rename {kcweb/utill => utill}/db/pymysql/optionfile.py (100%) rename {kcweb/utill => utill}/db/pymysql/protocol.py (100%) rename {kcweb/utill => utill}/db/pymysql/times.py (100%) rename {kcweb/utill => utill}/db/pymysql/util.py (100%) rename {kcweb/utill => utill}/db/sqlite.py (100%) rename {kcweb/utill => utill}/db/sqlitedata/kcwdb (100%) rename {kcweb/utill => utill}/filetype/__init__.py (100%) rename {kcweb/utill => utill}/filetype/filetype.py (100%) rename {kcweb/utill => utill}/filetype/helpers.py (100%) rename {kcweb/utill => utill}/filetype/match.py (100%) rename {kcweb/utill => utill}/filetype/types/__init__.py (100%) rename {kcweb/utill => utill}/filetype/types/archive.py (100%) rename {kcweb/utill => utill}/filetype/types/audio.py (100%) rename {kcweb/utill => utill}/filetype/types/base.py (100%) rename {kcweb/utill => utill}/filetype/types/font.py (100%) rename {kcweb/utill => utill}/filetype/types/image.py (100%) rename {kcweb/utill => utill}/filetype/types/isobmff.py (100%) rename {kcweb/utill => utill}/filetype/types/video.py (100%) rename {kcweb/utill => utill}/filetype/utils.py (100%) rename {kcweb/utill => utill}/http.py (100%) rename {kcweb/utill => utill}/queues.py (100%) rename {kcweb/utill => utill}/redis.py (100%) rename {kcweb/utill => utill}/rediss/__init__.py (100%) rename {kcweb/utill => utill}/rediss/_compat.py (100%) rename {kcweb/utill => utill}/rediss/client.py (100%) rename {kcweb/utill => utill}/rediss/connection.py (100%) rename {kcweb/utill => utill}/rediss/exceptions.py (100%) rename {kcweb/utill => utill}/rediss/lock.py (100%) rename {kcweb/utill => utill}/rediss/sentinel.py (100%) rename {kcweb/utill => utill}/rediss/utils.py (100%) diff --git a/kcweb/.gitignore b/.gitignore similarity index 100% rename from kcweb/.gitignore rename to .gitignore diff --git a/kcweb/Events.py b/Events.py similarity index 100% rename from kcweb/Events.py rename to Events.py diff --git a/kcweb/LICENSE b/LICENSE similarity index 100% rename from kcweb/LICENSE rename to LICENSE diff --git a/kcweb/README.md b/README.md similarity index 100% rename from kcweb/README.md rename to README.md diff --git a/kcweb/__init__.py b/__init__.py similarity index 100% rename from kcweb/__init__.py rename to __init__.py diff --git a/kcweb/app.py b/app.py similarity index 100% rename from kcweb/app.py rename to app.py diff --git a/kcweb/application/__init__.py b/application/__init__.py similarity index 100% rename from kcweb/application/__init__.py rename to application/__init__.py diff --git a/kcweb/application/api/__init__.py b/application/api/__init__.py similarity index 100% rename from kcweb/application/api/__init__.py rename to application/api/__init__.py diff --git a/kcweb/application/api/common/__init__.py b/application/api/common/__init__.py similarity index 100% rename from kcweb/application/api/common/__init__.py rename to application/api/common/__init__.py diff --git a/kcweb/application/api/common/autoload.py b/application/api/common/autoload.py similarity index 100% rename from kcweb/application/api/common/autoload.py rename to application/api/common/autoload.py diff --git a/kcweb/application/api/controller/__init__.py b/application/api/controller/__init__.py similarity index 100% rename from kcweb/application/api/controller/__init__.py rename to application/api/controller/__init__.py diff --git a/kcweb/application/api/controller/plug/__init__.py b/application/api/controller/plug/__init__.py similarity index 100% rename from kcweb/application/api/controller/plug/__init__.py rename to application/api/controller/plug/__init__.py diff --git a/kcweb/application/api/controller/plug/index.py b/application/api/controller/plug/index.py similarity index 100% rename from kcweb/application/api/controller/plug/index.py rename to application/api/controller/plug/index.py diff --git a/kcweb/application/api/controller/plug1/__init__.py b/application/api/controller/plug1/__init__.py similarity index 100% rename from kcweb/application/api/controller/plug1/__init__.py rename to application/api/controller/plug1/__init__.py diff --git a/kcweb/application/api/controller/plug1/index.py b/application/api/controller/plug1/index.py similarity index 100% rename from kcweb/application/api/controller/plug1/index.py rename to application/api/controller/plug1/index.py diff --git a/kcweb/application/api/controller/plug2/__init__.py b/application/api/controller/plug2/__init__.py similarity index 100% rename from kcweb/application/api/controller/plug2/__init__.py rename to application/api/controller/plug2/__init__.py diff --git a/kcweb/application/api/controller/plug2/index.py b/application/api/controller/plug2/index.py similarity index 100% rename from kcweb/application/api/controller/plug2/index.py rename to application/api/controller/plug2/index.py diff --git a/kcweb/application/api/tpl/plug1/index/index.html b/application/api/tpl/plug1/index/index.html similarity index 100% rename from kcweb/application/api/tpl/plug1/index/index.html rename to application/api/tpl/plug1/index/index.html diff --git a/kcweb/application/api/tpl/plug2/index/index.html b/application/api/tpl/plug2/index/index.html similarity index 100% rename from kcweb/application/api/tpl/plug2/index/index.html rename to application/api/tpl/plug2/index/index.html diff --git a/kcweb/application/common/__init__.py b/application/common/__init__.py similarity index 100% rename from kcweb/application/common/__init__.py rename to application/common/__init__.py diff --git a/kcweb/application/common/autoload.py b/application/common/autoload.py similarity index 100% rename from kcweb/application/common/autoload.py rename to application/common/autoload.py diff --git a/kcweb/application/config/__init__.py b/application/config/__init__.py similarity index 100% rename from kcweb/application/config/__init__.py rename to application/config/__init__.py diff --git a/kcweb/application/config/other.py b/application/config/other.py similarity index 100% rename from kcweb/application/config/other.py rename to application/config/other.py diff --git a/kcweb/common/__init__.py b/common/__init__.py similarity index 100% rename from kcweb/common/__init__.py rename to common/__init__.py diff --git a/kcweb/common/autoload.py b/common/autoload.py similarity index 99% rename from kcweb/common/autoload.py rename to common/autoload.py index 787215d..7638555 100644 --- a/kcweb/common/autoload.py +++ b/common/autoload.py @@ -459,10 +459,6 @@ class create: if files not in filters: modulars.append(files) content=Templates(self.path+"/application/__init__.py",appname=self.appname,tuple_modular=modulars) - f=open(self.appname+"/__init__.py","a",encoding='utf-8') - f.write(content) - f.close() - if not os.path.exists(self.path): if "Windows" in platform.platform(): pythonname="python" else: @@ -479,7 +475,10 @@ class create: f=open("./"+sys.argv[0]+".py","w+",encoding='utf-8') f.write(content) f.close() - return True + f=open(self.appname+"/__init__.py","a",encoding='utf-8') + f.write(content) + f.close() + return True def __zxmodular(self,sourcep): "处理模块文件" path1=self.path+"/application/api"+sourcep diff --git a/kcweb/common/globals.py b/common/globals.py similarity index 100% rename from kcweb/common/globals.py rename to common/globals.py diff --git a/kcweb/common/request.py b/common/request.py similarity index 100% rename from kcweb/common/request.py rename to common/request.py diff --git a/kcweb/common/session.py b/common/session.py similarity index 100% rename from kcweb/common/session.py rename to common/session.py diff --git a/kcweb/config/__init__.py b/config/__init__.py similarity index 100% rename from kcweb/config/__init__.py rename to config/__init__.py diff --git a/kcweb/setup.py b/kcweb/setup.py deleted file mode 100644 index 99a4a9d..0000000 --- a/kcweb/setup.py +++ /dev/null @@ -1,58 +0,0 @@ - -# python setup.py sdist upload -# twine upload --repository-url https://test.pypi.org/legacy/ dist/* #上传到测试 -# pip install --index-url https://test.pypi.org/simple/ kcweb #安装测试服务上的kcweb -############################################# -from setuptools import setup, find_packages,Extension -import os -def file_get_content(k): - "获取文件内容" - if os.path.isfile(k): - f=open(k,'r',encoding="utf-8") - con=f.read() - f.close() - else: - con='' - return con -confkcw={} -confkcw['name']='kcweb' #项目的名称 -confkcw['version']='3.0.0' #项目版本 -confkcw['description']='' #项目的简单描述 -confkcw['long_description']="" #项目详细描述 -confkcw['license']='MIT License' #开源协议 mit开源 -confkcw['url']='' -confkcw['author']='禄可集团-坤坤' #名字 -confkcw['author_email']='fk1402936534@qq.com' #邮件地址 -confkcw['maintainer']='坤坤' #维护人员的名字 -confkcw['maintainer_email']='fk1402936534@qq.com' #维护人员的邮件地址 -def get_file(folder='./',lists=[]): - lis=os.listdir(folder) - for files in lis: - if not os.path.isfile(folder+"/"+files): - if files=='__pycache__' or files=='.git': - pass - else: - lists.append(folder+"/"+files) - get_file(folder+"/"+files,lists) - else: - pass - return lists -b=get_file("kcweb",['kcweb']) -setup( - name = confkcw["name"], - version = confkcw["version"], - keywords = "kcweb"+confkcw['version'], - description = confkcw["description"], - long_description = confkcw["long_description"], - license = confkcw["license"], - author = confkcw["author"], - author_email = confkcw["author_email"], - maintainer = confkcw["maintainer"], - maintainer_email = confkcw["maintainer_email"], - url=confkcw['url'], - packages = b, - install_requires = ['pymongo>=3.10.0','Mako>=1.1.2','requests>=2.23.0','six>=1.12.0','watchdog>=0.9.0'], #第三方包 - package_data = { - '': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'], - } -) \ No newline at end of file diff --git a/server.py b/server.py deleted file mode 100644 index 359d84f..0000000 --- a/server.py +++ /dev/null @@ -1,3 +0,0 @@ -from kcweb.common import * #导入kcweb框架所有模块 -server=create("app","api") #创建一个应用和模块实例 -server.installmodular() #在应用下安装模块 (取决于create的参数) \ No newline at end of file diff --git a/kcweb/tpl/error.html b/tpl/error.html similarity index 100% rename from kcweb/tpl/error.html rename to tpl/error.html diff --git a/kcweb/utill/app.py b/utill/app.py similarity index 100% rename from kcweb/utill/app.py rename to utill/app.py diff --git a/kcweb/utill/cache/cache.py b/utill/cache/cache.py similarity index 100% rename from kcweb/utill/cache/cache.py rename to utill/cache/cache.py diff --git a/kcweb/utill/dateutil/__init__.py b/utill/dateutil/__init__.py similarity index 100% rename from kcweb/utill/dateutil/__init__.py rename to utill/dateutil/__init__.py diff --git a/kcweb/utill/dateutil/_common.py b/utill/dateutil/_common.py similarity index 100% rename from kcweb/utill/dateutil/_common.py rename to utill/dateutil/_common.py diff --git a/kcweb/utill/dateutil/_version.py b/utill/dateutil/_version.py similarity index 100% rename from kcweb/utill/dateutil/_version.py rename to utill/dateutil/_version.py diff --git a/kcweb/utill/dateutil/easter.py b/utill/dateutil/easter.py similarity index 100% rename from kcweb/utill/dateutil/easter.py rename to utill/dateutil/easter.py diff --git a/kcweb/utill/dateutil/parser/__init__.py b/utill/dateutil/parser/__init__.py similarity index 100% rename from kcweb/utill/dateutil/parser/__init__.py rename to utill/dateutil/parser/__init__.py diff --git a/kcweb/utill/dateutil/parser/_parser.py b/utill/dateutil/parser/_parser.py similarity index 100% rename from kcweb/utill/dateutil/parser/_parser.py rename to utill/dateutil/parser/_parser.py diff --git a/kcweb/utill/dateutil/parser/isoparser.py b/utill/dateutil/parser/isoparser.py similarity index 100% rename from kcweb/utill/dateutil/parser/isoparser.py rename to utill/dateutil/parser/isoparser.py diff --git a/kcweb/utill/dateutil/relativedelta.py b/utill/dateutil/relativedelta.py similarity index 100% rename from kcweb/utill/dateutil/relativedelta.py rename to utill/dateutil/relativedelta.py diff --git a/kcweb/utill/dateutil/rrule.py b/utill/dateutil/rrule.py similarity index 100% rename from kcweb/utill/dateutil/rrule.py rename to utill/dateutil/rrule.py diff --git a/kcweb/utill/dateutil/tz/__init__.py b/utill/dateutil/tz/__init__.py similarity index 100% rename from kcweb/utill/dateutil/tz/__init__.py rename to utill/dateutil/tz/__init__.py diff --git a/kcweb/utill/dateutil/tz/_common.py b/utill/dateutil/tz/_common.py similarity index 100% rename from kcweb/utill/dateutil/tz/_common.py rename to utill/dateutil/tz/_common.py diff --git a/kcweb/utill/dateutil/tz/_factories.py b/utill/dateutil/tz/_factories.py similarity index 100% rename from kcweb/utill/dateutil/tz/_factories.py rename to utill/dateutil/tz/_factories.py diff --git a/kcweb/utill/dateutil/tz/tz.py b/utill/dateutil/tz/tz.py similarity index 100% rename from kcweb/utill/dateutil/tz/tz.py rename to utill/dateutil/tz/tz.py diff --git a/kcweb/utill/dateutil/tz/win.py b/utill/dateutil/tz/win.py similarity index 100% rename from kcweb/utill/dateutil/tz/win.py rename to utill/dateutil/tz/win.py diff --git a/kcweb/utill/dateutil/tzwin.py b/utill/dateutil/tzwin.py similarity index 100% rename from kcweb/utill/dateutil/tzwin.py rename to utill/dateutil/tzwin.py diff --git a/kcweb/utill/dateutil/utils.py b/utill/dateutil/utils.py similarity index 100% rename from kcweb/utill/dateutil/utils.py rename to utill/dateutil/utils.py diff --git a/kcweb/utill/dateutil/zoneinfo/__init__.py b/utill/dateutil/zoneinfo/__init__.py similarity index 100% rename from kcweb/utill/dateutil/zoneinfo/__init__.py rename to utill/dateutil/zoneinfo/__init__.py diff --git a/kcweb/utill/dateutil/zoneinfo/rebuild.py b/utill/dateutil/zoneinfo/rebuild.py similarity index 100% rename from kcweb/utill/dateutil/zoneinfo/rebuild.py rename to utill/dateutil/zoneinfo/rebuild.py diff --git a/kcweb/utill/db/model.py b/utill/db/model.py similarity index 100% rename from kcweb/utill/db/model.py rename to utill/db/model.py diff --git a/kcweb/utill/db/mongodb.py b/utill/db/mongodb.py similarity index 100% rename from kcweb/utill/db/mongodb.py rename to utill/db/mongodb.py diff --git a/kcweb/utill/db/mysql.py b/utill/db/mysql.py similarity index 100% rename from kcweb/utill/db/mysql.py rename to utill/db/mysql.py diff --git a/kcweb/utill/db/pymysql/__init__.py b/utill/db/pymysql/__init__.py similarity index 100% rename from kcweb/utill/db/pymysql/__init__.py rename to utill/db/pymysql/__init__.py diff --git a/kcweb/utill/db/pymysql/_auth.py b/utill/db/pymysql/_auth.py similarity index 100% rename from kcweb/utill/db/pymysql/_auth.py rename to utill/db/pymysql/_auth.py diff --git a/kcweb/utill/db/pymysql/_compat.py b/utill/db/pymysql/_compat.py similarity index 100% rename from kcweb/utill/db/pymysql/_compat.py rename to utill/db/pymysql/_compat.py diff --git a/kcweb/utill/db/pymysql/_socketio.py b/utill/db/pymysql/_socketio.py similarity index 100% rename from kcweb/utill/db/pymysql/_socketio.py rename to utill/db/pymysql/_socketio.py diff --git a/kcweb/utill/db/pymysql/charset.py b/utill/db/pymysql/charset.py similarity index 100% rename from kcweb/utill/db/pymysql/charset.py rename to utill/db/pymysql/charset.py diff --git a/kcweb/utill/db/pymysql/connections.py b/utill/db/pymysql/connections.py similarity index 100% rename from kcweb/utill/db/pymysql/connections.py rename to utill/db/pymysql/connections.py diff --git a/kcweb/utill/db/pymysql/constants/CLIENT.py b/utill/db/pymysql/constants/CLIENT.py similarity index 100% rename from kcweb/utill/db/pymysql/constants/CLIENT.py rename to utill/db/pymysql/constants/CLIENT.py diff --git a/kcweb/utill/db/pymysql/constants/COMMAND.py b/utill/db/pymysql/constants/COMMAND.py similarity index 100% rename from kcweb/utill/db/pymysql/constants/COMMAND.py rename to utill/db/pymysql/constants/COMMAND.py diff --git a/kcweb/utill/db/pymysql/constants/CR.py b/utill/db/pymysql/constants/CR.py similarity index 100% rename from kcweb/utill/db/pymysql/constants/CR.py rename to utill/db/pymysql/constants/CR.py diff --git a/kcweb/utill/db/pymysql/constants/ER.py b/utill/db/pymysql/constants/ER.py similarity index 100% rename from kcweb/utill/db/pymysql/constants/ER.py rename to utill/db/pymysql/constants/ER.py diff --git a/kcweb/utill/db/pymysql/constants/FIELD_TYPE.py b/utill/db/pymysql/constants/FIELD_TYPE.py similarity index 100% rename from kcweb/utill/db/pymysql/constants/FIELD_TYPE.py rename to utill/db/pymysql/constants/FIELD_TYPE.py diff --git a/kcweb/utill/db/pymysql/constants/FLAG.py b/utill/db/pymysql/constants/FLAG.py similarity index 100% rename from kcweb/utill/db/pymysql/constants/FLAG.py rename to utill/db/pymysql/constants/FLAG.py diff --git a/kcweb/utill/db/pymysql/constants/SERVER_STATUS.py b/utill/db/pymysql/constants/SERVER_STATUS.py similarity index 100% rename from kcweb/utill/db/pymysql/constants/SERVER_STATUS.py rename to utill/db/pymysql/constants/SERVER_STATUS.py diff --git a/kcweb/utill/db/pymysql/constants/__init__.py b/utill/db/pymysql/constants/__init__.py similarity index 100% rename from kcweb/utill/db/pymysql/constants/__init__.py rename to utill/db/pymysql/constants/__init__.py diff --git a/kcweb/utill/db/pymysql/converters.py b/utill/db/pymysql/converters.py similarity index 100% rename from kcweb/utill/db/pymysql/converters.py rename to utill/db/pymysql/converters.py diff --git a/kcweb/utill/db/pymysql/cursors.py b/utill/db/pymysql/cursors.py similarity index 100% rename from kcweb/utill/db/pymysql/cursors.py rename to utill/db/pymysql/cursors.py diff --git a/kcweb/utill/db/pymysql/err.py b/utill/db/pymysql/err.py similarity index 100% rename from kcweb/utill/db/pymysql/err.py rename to utill/db/pymysql/err.py diff --git a/kcweb/utill/db/pymysql/optionfile.py b/utill/db/pymysql/optionfile.py similarity index 100% rename from kcweb/utill/db/pymysql/optionfile.py rename to utill/db/pymysql/optionfile.py diff --git a/kcweb/utill/db/pymysql/protocol.py b/utill/db/pymysql/protocol.py similarity index 100% rename from kcweb/utill/db/pymysql/protocol.py rename to utill/db/pymysql/protocol.py diff --git a/kcweb/utill/db/pymysql/times.py b/utill/db/pymysql/times.py similarity index 100% rename from kcweb/utill/db/pymysql/times.py rename to utill/db/pymysql/times.py diff --git a/kcweb/utill/db/pymysql/util.py b/utill/db/pymysql/util.py similarity index 100% rename from kcweb/utill/db/pymysql/util.py rename to utill/db/pymysql/util.py diff --git a/kcweb/utill/db/sqlite.py b/utill/db/sqlite.py similarity index 100% rename from kcweb/utill/db/sqlite.py rename to utill/db/sqlite.py diff --git a/kcweb/utill/db/sqlitedata/kcwdb b/utill/db/sqlitedata/kcwdb similarity index 100% rename from kcweb/utill/db/sqlitedata/kcwdb rename to utill/db/sqlitedata/kcwdb diff --git a/kcweb/utill/filetype/__init__.py b/utill/filetype/__init__.py similarity index 100% rename from kcweb/utill/filetype/__init__.py rename to utill/filetype/__init__.py diff --git a/kcweb/utill/filetype/filetype.py b/utill/filetype/filetype.py similarity index 100% rename from kcweb/utill/filetype/filetype.py rename to utill/filetype/filetype.py diff --git a/kcweb/utill/filetype/helpers.py b/utill/filetype/helpers.py similarity index 100% rename from kcweb/utill/filetype/helpers.py rename to utill/filetype/helpers.py diff --git a/kcweb/utill/filetype/match.py b/utill/filetype/match.py similarity index 100% rename from kcweb/utill/filetype/match.py rename to utill/filetype/match.py diff --git a/kcweb/utill/filetype/types/__init__.py b/utill/filetype/types/__init__.py similarity index 100% rename from kcweb/utill/filetype/types/__init__.py rename to utill/filetype/types/__init__.py diff --git a/kcweb/utill/filetype/types/archive.py b/utill/filetype/types/archive.py similarity index 100% rename from kcweb/utill/filetype/types/archive.py rename to utill/filetype/types/archive.py diff --git a/kcweb/utill/filetype/types/audio.py b/utill/filetype/types/audio.py similarity index 100% rename from kcweb/utill/filetype/types/audio.py rename to utill/filetype/types/audio.py diff --git a/kcweb/utill/filetype/types/base.py b/utill/filetype/types/base.py similarity index 100% rename from kcweb/utill/filetype/types/base.py rename to utill/filetype/types/base.py diff --git a/kcweb/utill/filetype/types/font.py b/utill/filetype/types/font.py similarity index 100% rename from kcweb/utill/filetype/types/font.py rename to utill/filetype/types/font.py diff --git a/kcweb/utill/filetype/types/image.py b/utill/filetype/types/image.py similarity index 100% rename from kcweb/utill/filetype/types/image.py rename to utill/filetype/types/image.py diff --git a/kcweb/utill/filetype/types/isobmff.py b/utill/filetype/types/isobmff.py similarity index 100% rename from kcweb/utill/filetype/types/isobmff.py rename to utill/filetype/types/isobmff.py diff --git a/kcweb/utill/filetype/types/video.py b/utill/filetype/types/video.py similarity index 100% rename from kcweb/utill/filetype/types/video.py rename to utill/filetype/types/video.py diff --git a/kcweb/utill/filetype/utils.py b/utill/filetype/utils.py similarity index 100% rename from kcweb/utill/filetype/utils.py rename to utill/filetype/utils.py diff --git a/kcweb/utill/http.py b/utill/http.py similarity index 100% rename from kcweb/utill/http.py rename to utill/http.py diff --git a/kcweb/utill/queues.py b/utill/queues.py similarity index 100% rename from kcweb/utill/queues.py rename to utill/queues.py diff --git a/kcweb/utill/redis.py b/utill/redis.py similarity index 100% rename from kcweb/utill/redis.py rename to utill/redis.py diff --git a/kcweb/utill/rediss/__init__.py b/utill/rediss/__init__.py similarity index 100% rename from kcweb/utill/rediss/__init__.py rename to utill/rediss/__init__.py diff --git a/kcweb/utill/rediss/_compat.py b/utill/rediss/_compat.py similarity index 100% rename from kcweb/utill/rediss/_compat.py rename to utill/rediss/_compat.py diff --git a/kcweb/utill/rediss/client.py b/utill/rediss/client.py similarity index 100% rename from kcweb/utill/rediss/client.py rename to utill/rediss/client.py diff --git a/kcweb/utill/rediss/connection.py b/utill/rediss/connection.py similarity index 100% rename from kcweb/utill/rediss/connection.py rename to utill/rediss/connection.py diff --git a/kcweb/utill/rediss/exceptions.py b/utill/rediss/exceptions.py similarity index 100% rename from kcweb/utill/rediss/exceptions.py rename to utill/rediss/exceptions.py diff --git a/kcweb/utill/rediss/lock.py b/utill/rediss/lock.py similarity index 100% rename from kcweb/utill/rediss/lock.py rename to utill/rediss/lock.py diff --git a/kcweb/utill/rediss/sentinel.py b/utill/rediss/sentinel.py similarity index 100% rename from kcweb/utill/rediss/sentinel.py rename to utill/rediss/sentinel.py diff --git a/kcweb/utill/rediss/utils.py b/utill/rediss/utils.py similarity index 100% rename from kcweb/utill/rediss/utils.py rename to utill/rediss/utils.py -- Gitee From f7971cedf3c29841c96c96c600efcc42420e72cd Mon Sep 17 00:00:00 2001 From: kunkun Date: Sat, 30 May 2020 01:38:44 +0800 Subject: [PATCH 13/52] kun --- common/autoload.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index 7638555..62b9251 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -463,8 +463,8 @@ class create: pythonname="python" else: pythonname="python3" - sys.argv[0]=re.sub('.py','',sys.argv[0]) - content=('# #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ + # sys.argv[0]=re.sub('.py','',sys.argv[0]) + servertext=('# #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ 'from kcweb import web\n'+ 'import '+self.appname+' as application\n'+ 'from '+self.appname+'.common import *\n'+ @@ -472,8 +472,8 @@ class create: 'if __name__ == "__main__":\n'+ ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ ' app.run(host="0.0.0.0",port="39001",name="'+pythonname+'")') - f=open("./"+sys.argv[0]+".py","w+",encoding='utf-8') - f.write(content) + f=open("./server.py","w+",encoding='utf-8') + f.write(servertext) f.close() f=open(self.appname+"/__init__.py","a",encoding='utf-8') f.write(content) -- Gitee From 87c3a6e0ea37b075c54e85630b539b6b5bd820ec Mon Sep 17 00:00:00 2001 From: kunkun Date: Sat, 30 May 2020 20:55:43 +0800 Subject: [PATCH 14/52] kun --- Events.py | 14 +-- app.py | 13 ++- application/__init__.py | 5 - application/api/__init__.py | 2 - application/api/common/__init__.py | 19 ---- application/api/common/autoload.py | 2 - application/api/controller/__init__.py | 2 - application/api/controller/plug/__init__.py | 4 - application/api/controller/plug/index.py | 8 -- application/api/controller/plug1/__init__.py | 4 - application/api/controller/plug1/index.py | 16 --- application/api/controller/plug2/__init__.py | 4 - application/api/controller/plug2/index.py | 10 -- application/api/tpl/plug1/index/index.html | 29 ----- application/api/tpl/plug2/index/index.html | 29 ----- application/common/__init__.py | 75 ------------- application/common/autoload.py | 5 - application/config/__init__.py | 40 ------- application/config/other.py | 15 --- common/autoload.py | 110 +++++++++---------- config/__init__.py | 7 +- setup.py | 3 +- 22 files changed, 72 insertions(+), 344 deletions(-) delete mode 100644 application/__init__.py delete mode 100644 application/api/__init__.py delete mode 100644 application/api/common/__init__.py delete mode 100644 application/api/common/autoload.py delete mode 100644 application/api/controller/__init__.py delete mode 100644 application/api/controller/plug/__init__.py delete mode 100644 application/api/controller/plug/index.py delete mode 100644 application/api/controller/plug1/__init__.py delete mode 100644 application/api/controller/plug1/index.py delete mode 100644 application/api/controller/plug2/__init__.py delete mode 100644 application/api/controller/plug2/index.py delete mode 100644 application/api/tpl/plug1/index/index.html delete mode 100644 application/api/tpl/plug2/index/index.html delete mode 100644 application/common/__init__.py delete mode 100644 application/common/autoload.py delete mode 100644 application/config/__init__.py delete mode 100644 application/config/other.py diff --git a/Events.py b/Events.py index 9993b28..5e202b0 100644 --- a/Events.py +++ b/Events.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import os, sys, time, subprocess +import os, sys, time, subprocess,signal from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler class MyFileSystemEventHander(FileSystemEventHandler): @@ -10,18 +10,15 @@ class MyFileSystemEventHander(FileSystemEventHandler): def on_any_event(self, event): if event.src_path.endswith('.py'): print('* 更新文件:%s' % event.src_path) - time.sleep(0.2) + time.sleep(0.1) self.restart() class Events: command = ['echo', 'ok'] process = None def __init__(self,argv): - argv=argv - # print(argv) - if 'python' not in argv[0]: - argv.insert(0, 'python3') + if '--server' not in argv and 'python' not in argv[0] or 'kcw.py' in argv: + argv.insert(0, 'python') self.command = argv - # print(self.command) paths = os.path.abspath('.') self.start_watch(paths, None) @@ -39,6 +36,7 @@ class Events: def restart_process(self): "重启" self.kill_process() + time.sleep(0.1) self.start_process() def start_watch(self,path, callback): @@ -49,7 +47,7 @@ class Events: self.start_process() try: while True: - time.sleep(0.5) + time.sleep(0.1) except KeyboardInterrupt: self.kill_process() # observer.stop() diff --git a/app.py b/app.py index bf09386..fae236f 100644 --- a/app.py +++ b/app.py @@ -53,23 +53,26 @@ class web: return apps else: return super().__new__(self) - def run(self,host="127.0.0.1",port="39001",name='python'): + def run(self,host="127.0.0.1",port="39001",name=None): """运行开发环境 host: 监听地址 port: 端口 - name: python命令行解释机名字 默认python + name: python命令行解释机名字 """ - if len(sys.argv)==1 or (len(sys.argv)==2 and sys.argv[1]=='eventlog'): + if '--web' in sys.argv or True: filename=sys.argv[0][:-3] if self.__config.app['app_debug']: arg=sys.argv - if len(arg)==2 and arg[1]=='eventlog': + if 'eventlog' in arg: self.__impl(host=host,port=port,filename=filename) else: - Events([name,str(filename)+'.py','eventlog']) + if name: + arg.insert(0,name) + arg.append('eventlog') + Events(arg) else: self.__impl( host=host, diff --git a/application/__init__.py b/application/__init__.py deleted file mode 100644 index 915fbee..0000000 --- a/application/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -#导入模块 -% for i in tuple_modular: -from . import ${i} -% endfor diff --git a/application/api/__init__.py b/application/api/__init__.py deleted file mode 100644 index 0f9c434..0000000 --- a/application/api/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# -*- coding: utf-8 -*- -from . import controller \ No newline at end of file diff --git a/application/api/common/__init__.py b/application/api/common/__init__.py deleted file mode 100644 index 0917cdf..0000000 --- a/application/api/common/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -from .autoload import * -#下面的方法在当前模块中有效 -def before_request(): - G.userinfo=get_session("userinfo") - print('${modular}模块在请求前执行,我是要在配置文件配置后才能生效哦!',G.userinfo) -def after_request(): - print('${modular}模块在请求后执行,我是要在配置文件配置后才能生效哦!') -def set_session(name,value,expire=None): - "设置session" - return session.set("${appname}${modular}"+str(name),value,expire) -def get_session(name): - "获取session" - return session.get("${appname}${modular}"+str(name)) -def del_session(name): - "删除session" - return session.rm("${appname}${modular}"+str(name)) -def tpl(path,**context): - return Template("/${modular}/tpl/"+str(path),**context) diff --git a/application/api/common/autoload.py b/application/api/common/autoload.py deleted file mode 100644 index 05965c2..0000000 --- a/application/api/common/autoload.py +++ /dev/null @@ -1,2 +0,0 @@ -# -*- coding: utf-8 -*- -from ${appname}.common import * \ No newline at end of file diff --git a/application/api/controller/__init__.py b/application/api/controller/__init__.py deleted file mode 100644 index cd4aab3..0000000 --- a/application/api/controller/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# -*- coding: utf-8 -*- -from . import plug,plug1,plug2 \ No newline at end of file diff --git a/application/api/controller/plug/__init__.py b/application/api/controller/plug/__init__.py deleted file mode 100644 index ab68b08..0000000 --- a/application/api/controller/plug/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from . import index -# def error(err,data): -# "该函数在找不到模块时执行函数时和框架报错时被调用" -# return str(err) \ No newline at end of file diff --git a/application/api/controller/plug/index.py b/application/api/controller/plug/index.py deleted file mode 100644 index b7eedd7..0000000 --- a/application/api/controller/plug/index.py +++ /dev/null @@ -1,8 +0,0 @@ -# -*- coding: utf-8 -*- -from ${appname}.${modular}.common import * -def inter(id='',title=""): - data={ - 'title':title, - 'id':id - } - return successjson(data) \ No newline at end of file diff --git a/application/api/controller/plug1/__init__.py b/application/api/controller/plug1/__init__.py deleted file mode 100644 index ab68b08..0000000 --- a/application/api/controller/plug1/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from . import index -# def error(err,data): -# "该函数在找不到模块时执行函数时和框架报错时被调用" -# return str(err) \ No newline at end of file diff --git a/application/api/controller/plug1/index.py b/application/api/controller/plug1/index.py deleted file mode 100644 index bc863e5..0000000 --- a/application/api/controller/plug1/index.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -from ${appname}.${modular}.common import * -def index(): - return tpl("/plug1/index/index.html",title="欢迎使用kcweb框架",data=['这是${appname}应用${modular}模块下plug插件的一个模板渲染测试效果']) -def inter(id='',title=""): - data={ - 'title':title, - 'id':id - } - return successjson(data) -def home(id='',title=""): - data={ - "title":"标题是"+title, - "id":"id是"+id - } - return successjson(data) \ No newline at end of file diff --git a/application/api/controller/plug2/__init__.py b/application/api/controller/plug2/__init__.py deleted file mode 100644 index ab68b08..0000000 --- a/application/api/controller/plug2/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from . import index -# def error(err,data): -# "该函数在找不到模块时执行函数时和框架报错时被调用" -# return str(err) \ No newline at end of file diff --git a/application/api/controller/plug2/index.py b/application/api/controller/plug2/index.py deleted file mode 100644 index 679977c..0000000 --- a/application/api/controller/plug2/index.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -from ${appname}.${modular}.common import * -def index(): - return tpl("/plug2/index/index.html",title="欢迎使用kcweb框架",data=['这是${appname}应用${modular}模块下plug2版本的一个模板渲染测试效果']) -def inter(): - data={ - 'title':'欢迎使用kcweb框架', - 'desc':'这是${appname}应用${modular}模块下plug2版本的json输出效果' - } - return successjson(data) \ No newline at end of file diff --git a/application/api/tpl/plug1/index/index.html b/application/api/tpl/plug1/index/index.html deleted file mode 100644 index 5110512..0000000 --- a/application/api/tpl/plug1/index/index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - -${title} - - - - - - - -
-

这是plug1模板文件

- % if title: -

${title}

- % endif - % if isinstance(data,str): - ${data} - % elif isinstance(data,list): -
    - % for i in data: -
  • ${i}
  • - % endfor -
- % endif -
- - - \ No newline at end of file diff --git a/application/api/tpl/plug2/index/index.html b/application/api/tpl/plug2/index/index.html deleted file mode 100644 index c8b3513..0000000 --- a/application/api/tpl/plug2/index/index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - -${title} - - - - - - - -
-

这是plug2模板文件

- % if title: -

${title}

- % endif - % if isinstance(data,str): - ${data} - % elif isinstance(data,list): -
    - % for i in data: -
  • ${i}
  • - % endfor -
- % endif -
- - - \ No newline at end of file diff --git a/application/common/__init__.py b/application/common/__init__.py deleted file mode 100644 index 05e1c79..0000000 --- a/application/common/__init__.py +++ /dev/null @@ -1,75 +0,0 @@ -# -*- coding: utf-8 -*- -from .autoload import * -def return_list(lists,count,pagenow,pagesize): - """返回分页列表 - - lists 数据库列表数据 - - count 数据库总数量 - - pagenow 页码 - - pagesize 每页数量 - """ - data={ - 'count':count, - 'pagenow':pagenow, - 'pagesize':pagesize, - 'pagecount':math.ceil(int(count)/int(pagesize)), - 'lists':lists - } - return data -def successjson(data=[],code=0,msg="成功",status='200 ok'): - """成功说在浏览器输出包装过的json - - 参数 data 结果 默认[] - - 参数 code body状态码 默认0 - - 参数 msg body状态描述 默认 成功 - - 参数 status http状态码 默认 200 - - 返回 json字符串结果集 - """ - res={ - "code":code, - "msg":msg, - "time":times(), - "data":data - } - return json_encode(res),status,{"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"} -def errorjson(data=[],code=1,msg="失败",status='500 error'): - """错误时在浏览器输出包装过的json - - 参数 data 结果 默认[] - - 参数 code body状态码 默认0 - - 参数 msg body状态描述 默认 成功 - - 参数 status http状态码 默认 200 - - 返回 json字符串结果集 - """ - return successjson(data=data,code=code,msg=msg,status=status) -def randoms(lens=6,types=1): - """生成随机字符串 - - lens 长度 - - types 1数字 2字母 3字母加数字 - """ - strs="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM,!@#$%^&*()_+=-;',./:<>?" - if types==1: - strs="0123456789" - elif types==2: - strs="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" - elif types==3: - strs="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" - k='' - i=0 - while i < lens: - k+=random.choice(strs) - i+=1 - return k \ No newline at end of file diff --git a/application/common/autoload.py b/application/common/autoload.py deleted file mode 100644 index 99a5719..0000000 --- a/application/common/autoload.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -from kcweb.common import * -from ${appname} import config -import math,random -G=globals.G \ No newline at end of file diff --git a/application/config/__init__.py b/application/config/__init__.py deleted file mode 100644 index 3257846..0000000 --- a/application/config/__init__.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -from .other import * -#下面的配置都是全局的 -# 应用配置 -app['app_debug']=True #是否开启调试模式 -app['tpl_folder']='./${appname}' #设置模板文件目录名 注意:所有的配置目录都是以您的运行文件所在目录开始 -app['before_request']='before_request' #设置请求前要执行的函数名 -app['after_request']='after_request' #设置请求后要执行的函数名 -app['staticpath']='${appname}/static' #静态主要目录 -# redis配置 -redis['host']='127.0.0.1' #服务器地址 -redis['port']=6379 #端口 -redis['password']='' #密码 -redis['db']=0 #Redis数据库 注:Redis用0或1或2等表示 -redis['pattern']=True # True连接池链接 False非连接池链接 -redis['ex']=0 #过期时间 (秒) -#缓存配置 -cache['type']='File' #驱动方式 支持 File Redis -cache['path']='./${appname}/runtime/cachepath' #缓存保存目录 -cache['expire']=120 #缓存有效期 0表示永久缓存 -cache['host']=redis['host'] #Redis服务器地址 -cache['port']=redis['port'] #Redis 端口 -cache['password']=redis['password'] #Redis登录密码 -cache['db']=1 #Redis数据库 注:Redis用1或2或3等表示 -# session配置 -session['type']='File' #session 存储类型 支持 file、Redis -session['path']='./${appname}/runtime/session/temp' #session缓存目录 -session['expire']=86400 #session默认有效期 该时间是指session在服务的保留时间,通常情况下浏览器上会保留该值的10倍 -session['prefix']="KCW" # SESSION 前缀 -session['host']=redis['host'] #Redis服务器地址 -session['port']=redis['port'] #Redis 端口 -session['password']=redis['password'] #Redis登录密码 -session['db']=2 #Redis数据库 注:Redis用1或2或3等表示 - -#email配置 -email['sender']='' #发件人邮箱账号 -email['pwd']='' #发件人邮箱密码(如申请的smtp给的口令) -email['sendNick']='' #发件人昵称 -email['theme']='' #默认主题 -email['recNick']='' #默认收件人昵称 \ No newline at end of file diff --git a/application/config/other.py b/application/config/other.py deleted file mode 100644 index e2b9dc5..0000000 --- a/application/config/other.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -from kcweb.config import * -#路由配置 -route['default']=True #是否开启默认路由 默认路由开启后面不影响以下配置的路由,模块名/版本名/控制器文件名/方法名 作为路由地址 如:http://www.kcw.com/api/v1/index/index/ -route['modular']='${modular}' -route['plug']='plug1' -route['files']='index' #默认路由文件(控制器) -route['funct']='index' #默认路由函数 (操作方法) -route['methods']=['POST','GET'] #默认请求方式 -route['children']=[ - {'title':'首页','path':'','component':'index/home','methods':['POST','GET']}, - {'title':'接口','path':'/inter/:id','component':'index/inter','methods':['POST','GET']} -] -#sqlite配置 -sqlite['db']='kcwlicuxweb' #sqlite数据库文件 diff --git a/common/autoload.py b/common/autoload.py index 62b9251..168893f 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import time,hashlib,json,re,os,platform,sys,shutil,zipfile +import time,hashlib,json,re,os,platform,sys,shutil,zipfile,requests import datetime as core_datetime from kcweb import config from kcweb.utill.dateutil.relativedelta import relativedelta as core_relativedelta @@ -413,52 +413,44 @@ class create: def installmodular(self): "创建模块,如果应用不存,则创建默认应用,如果在您的应用目录下没有模块包,则创建默认模块文件" if not os.path.exists(self.appname): - os.makedirs(self.appname) + # os.makedirs(self.appname) + r=requests.get(config.domain['kcwebfile']+"/kcweb/app.zip") + f = open("./app.zip", "wb") + for chunk in r.iter_content(chunk_size=512): + if chunk: + f.write(chunk) + f.close() + zip.unzip_file("./app.zip","./") + os.remove("./app.zip") + if not os.path.isfile("./server.py"): + if "Windows" in platform.platform(): + pythonname="python" + else: + pythonname="python3" + servertext=('# #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ + 'from kcweb import web\n'+ + 'import '+self.appname+' as application\n'+ + 'from '+self.appname+'.common import *\n'+ + 'app=web(__name__,application)\n'+ + 'if __name__ == "__main__":\n'+ + ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ + ' app.run(host="0.0.0.0",port="39001",name="'+pythonname+'")') + f=open("./server.py","w+",encoding='utf-8') + f.write(servertext) + f.close() + return True else: if not os.path.isfile(self.appname+"/__init__.py") or not os.path.exists(self.appname+"/common"): raise Exception(self.appname+"不是kcweb应用") - if not os.path.exists(self.appname+"/common"): - os.makedirs(self.appname+"/common") - f=open(self.appname+"/common/__init__.py","w+",encoding='utf-8') - content=Templates(self.path+"/application/common/__init__.py",appname=self.appname,modular=self.modular) - f.write(content) - f.close() - f=open(self.appname+"/common/autoload.py","w+",encoding='utf-8') - content=Templates(self.path+"/application/common/autoload.py",appname=self.appname,modular=self.modular) - f.write(content) - f.close() - if not os.path.exists(self.appname+"/config"): - os.makedirs(self.appname+"/config") - f=open(self.appname+"/config/__init__.py","w+",encoding='utf-8') - content=Templates(self.path+"/application/config/__init__.py",appname=self.appname,modular=self.modular) - f.write(content) - f.close() - f=open(self.appname+"/config/other.py","w+",encoding='utf-8') - content=Templates(self.path+"/application/config/other.py",appname=self.appname,modular=self.modular) - f.write(content) - f.close() + if os.path.exists(self.appname+"/"+self.modular): raise Exception(self.appname+"/"+self.modular+"已存在") else: if os.path.isfile(self.appname+"/"+self.modular+".zip"):#安装打包好的模块 zip.unzip_file(self.appname+"/"+self.modular+".zip",self.appname+"/"+self.modular+"/") os.remove(self.appname+"/"+self.modular+".zip") - else: - os.makedirs(self.appname+"/"+self.modular)#创建模块 - self.__zxmodular("") - if os.path.isfile(self.appname+"/__init__.py"): content="\nfrom . import "+self.modular - else: - #在应用目录下创建初始化文件 - lists=os.listdir(self.appname) - modulars=[] - filters=['__init__','__pycache__','common','config','runtime','log'] - for files in lists: - if not os.path.isfile(self.appname+"/"+files): - if files not in filters: - modulars.append(files) - content=Templates(self.path+"/application/__init__.py",appname=self.appname,tuple_modular=modulars) if "Windows" in platform.platform(): pythonname="python" else: @@ -479,26 +471,26 @@ class create: f.write(content) f.close() return True - def __zxmodular(self,sourcep): - "处理模块文件" - path1=self.path+"/application/api"+sourcep - path2=self.appname+"/"+self.modular+sourcep - lists=os.listdir(path1) - for files in lists: - if os.path.isfile(path1+"/"+files): - if ".py" in files: - content=Templates(path1+"/"+files,appname=self.appname,modular=self.modular) - f=open(path2+"/"+files,"w+",encoding='utf-8') - f.write(content) - f.close() - else: - f=open(path1+"/"+files,"r",encoding='utf-8') - content=f.read() - f.close() - f=open(path2+"/"+files,"w+",encoding='utf-8') - f.write(content) - f.close() - elif files != '__pycache__': - if not os.path.exists(path2+"/"+files): - os.makedirs(path2+"/"+files) - self.__zxmodular(sourcep+"/"+files) \ No newline at end of file + # def __zxmodular(self,sourcep): + # "处理模块文件" + # path1=self.path+"/application/api"+sourcep + # path2=self.appname+"/"+self.modular+sourcep + # lists=os.listdir(path1) + # for files in lists: + # if os.path.isfile(path1+"/"+files): + # if ".py" in files: + # content=Templates(path1+"/"+files,appname=self.appname,modular=self.modular) + # f=open(path2+"/"+files,"w+",encoding='utf-8') + # f.write(content) + # f.close() + # else: + # f=open(path1+"/"+files,"r",encoding='utf-8') + # content=f.read() + # f.close() + # f=open(path2+"/"+files,"w+",encoding='utf-8') + # f.write(content) + # f.close() + # elif files != '__pycache__': + # if not os.path.exists(path2+"/"+files): + # os.makedirs(path2+"/"+files) + # self.__zxmodular(sourcep+"/"+files) \ No newline at end of file diff --git a/config/__init__.py b/config/__init__.py index d8a17cf..6b28588 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -6,7 +6,7 @@ app['tpl_folder']='./tpl' #设置模板文件目录名 注意:不能配置目 app['before_request']='' #设置请求前执行的函数 app['after_request']='' #设置请求后执行的函数 app['staticpath']='static' -app['http_server']='wsgiref' #使用的开发服务器 支持 wsgiref、kcweb、kcweb_server +app['http_server']='kcweb_server' #使用的开发服务器 支持 wsgiref、kcweb、kcweb_server # redis配置 redis={} redis['host']='127.0.0.1' #服务器地址 @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='3.0.0' #项目版本 +kcweb['version']='3.0.10' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 @@ -100,6 +100,9 @@ kcweb['author_email']='fk1402936534@qq.com' #邮件地址 kcweb['maintainer']='坤坤' #维护人员的名字 kcweb['maintainer_email']='fk1402936534@qq.com' #维护人员的邮件地址 +domain={} +domain['kcwebfile']="http://file.kwebapp.cn" + #其他配置 other={} diff --git a/setup.py b/setup.py index 99a4a9d..84ed29a 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='3.0.0' #项目版本 +confkcw['version']='3.0.10' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 @@ -51,6 +51,7 @@ setup( maintainer_email = confkcw["maintainer_email"], url=confkcw['url'], packages = b, + # data_files=[('Scripts', ['kcweb/bin/kcw.exe'])], install_requires = ['pymongo>=3.10.0','Mako>=1.1.2','requests>=2.23.0','six>=1.12.0','watchdog>=0.9.0'], #第三方包 package_data = { '': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'], -- Gitee From 733bded8d9b6b39794f6cf168b9005c6fb44d3bc Mon Sep 17 00:00:00 2001 From: kunkun Date: Sat, 30 May 2020 21:18:28 +0800 Subject: [PATCH 15/52] kun --- common/autoload.py | 27 +++++++-------------------- config/__init__.py | 2 +- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index 168893f..d648b0c 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -376,22 +376,9 @@ class create: if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - else:#安装默认插件 - if not os.path.exists(self.appname+"/"+self.modular+"/controller/"+plug): - os.makedirs(self.appname+"/"+self.modular+"/controller/"+plug) - content=Templates(self.path+"/application/api/controller/plug/__init__.py",appname=self.appname,modular=self.modular) - f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/__init__.py","a",encoding='utf-8') - f.write(content) - f.close() - content=Templates(self.path+"/application/api/controller/plug/index.py",appname=self.appname,modular=self.modular) - f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/index.py","a",encoding='utf-8') - f.write(content) - f.close() - content="\nfrom . import "+plug - f=open(self.appname+"/"+self.modular+"/controller/__init__.py","a",encoding='utf-8') - f.write(content) - f.close() - return True + return True + else: + raise Exception("找不到插件安装包") def uninstallmodular(self): "卸载模块" f=open(self.appname+"/__init__.py","r") @@ -449,8 +436,11 @@ class create: if os.path.isfile(self.appname+"/"+self.modular+".zip"):#安装打包好的模块 zip.unzip_file(self.appname+"/"+self.modular+".zip",self.appname+"/"+self.modular+"/") os.remove(self.appname+"/"+self.modular+".zip") - if os.path.isfile(self.appname+"/__init__.py"): content="\nfrom . import "+self.modular + f=open(self.appname+"/__init__.py","a",encoding='utf-8') + f.write(content) + f.close() + if not os.path.isfile("./server.py"): if "Windows" in platform.platform(): pythonname="python" else: @@ -467,9 +457,6 @@ class create: f=open("./server.py","w+",encoding='utf-8') f.write(servertext) f.close() - f=open(self.appname+"/__init__.py","a",encoding='utf-8') - f.write(content) - f.close() return True # def __zxmodular(self,sourcep): # "处理模块文件" diff --git a/config/__init__.py b/config/__init__.py index 6b28588..080dc94 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='3.0.10' #项目版本 +kcweb['version']='3.0.2' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 -- Gitee From 23840c7ddbcd56205a7e400ee8a5ff30d624d733 Mon Sep 17 00:00:00 2001 From: kunkun Date: Mon, 1 Jun 2020 00:18:24 +0800 Subject: [PATCH 16/52] kun --- common/autoload.py | 150 +++++++++++++++++++++++++++++++++------------ config/__init__.py | 3 + 2 files changed, 113 insertions(+), 40 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index d648b0c..d30fb51 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -352,7 +352,7 @@ class create: f.write(text) f.close() shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug) - return True + return True,"成功" def packplug(self,plug): """打包插件 @@ -361,24 +361,60 @@ class create: """打包模块""" if os.path.exists(self.appname+"/"+self.modular+"/controller/"+plug): zip.packzip(self.appname+"/"+self.modular+"/controller/"+plug,self.appname+"/"+self.modular+"/controller/"+plug+".zip") - return True + return True,"成功" + else: + return False,"失败" + def uploadplug(self,plug,username,password): + "上传一个插件" + timestamp=times() + sign=md5(str(username)+str(timestamp)+md5(md5(password))) + http=Http() + http.set_header['username']=username + http.set_header['timestamp']=str(timestamp) + http.set_header['sign']=sign + http.openurl(config.domain['kcwebapi']+"/user/uploadplug/",'POST', + data={'name':str(plug),'describes':'','modular':self.modular}, + files={'file':open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", 'rb')}) + arr=json_decode(http.get_text) + del http + if arr and arr['code']==0: + return True,arr['msg'],arr['data'] + elif arr: + return False,arr['msg'] else: - return False - def installplug(self,plug): + return False,"上传失败,服务器暂时无法处理上传" + def installplug(self,plug,edition=''): """创建一个插件,如果您的模块目录下没有插件包,则创建默认插件文件 plug 插件名 """ plug=str(plug) if os.path.exists(self.appname+"/"+self.modular+"/controller/"+plug): - raise Exception("该插件已存在") + return False,"该插件已存在" else: - if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 - zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") - os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - return True + http=Http() + http.openurl(config.domain['kcwebapi']+"/pub/plug","POST",data={"modular":self.modular,"name":str(plug),"edition":str(edition)}) + arr=json_decode(http.get_text)['data'] + del http + if arr: + r=requests.get(config.domain['kcwebfile']+"/"+arr['fileurl']) + f = open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", "wb") + for chunk in r.iter_content(chunk_size=512): + if chunk: + f.write(chunk) + f.close() + if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 + zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + f=open(self.appname+"/"+self.modular+"/controller/__init__.py","a",encoding='utf-8') + text="\nfrom . import "+plug + f.write(text) + f.close() + return True,"插件安装成功,"+plug+"=="+str(arr['edition']) + else: + return False,str(plug)+"插件下载失败" else: - raise Exception("找不到插件安装包") + return False,self.modular+"模块下找不到"+str(plug)+"插件" def uninstallmodular(self): "卸载模块" f=open(self.appname+"/__init__.py","r") @@ -389,14 +425,33 @@ class create: f.write(text) f.close() shutil.rmtree(self.appname+"/"+self.modular) - return True + return True,"成功" def packmodular(self): """打包模块""" if os.path.exists(self.appname+"/"+self.modular): zip.packzip(self.appname+"/"+self.modular,self.appname+"/"+self.modular+".zip") - return True + return True,"成功" + else: + return False,"失败" + def uploadmodular(self,username,password): + "上传模块" + timestamp=times() + sign=md5(str(username)+str(timestamp)+md5(md5(password))) + http=Http() + http.set_header['username']=username + http.set_header['timestamp']=str(timestamp) + http.set_header['sign']=sign + http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/",'POST', + data={'name':str(self.modular),'describes':''}, + files={'file':open(self.appname+"/"+self.modular+".zip", 'rb')}) + arr=json_decode(http.get_text) + del http + if arr and arr['code']==0: + return True,arr['msg'] + elif arr: + return False,arr['msg'] else: - return False + return False,"上传失败,服务器暂时无法处理上传" def installmodular(self): "创建模块,如果应用不存,则创建默认应用,如果在您的应用目录下没有模块包,则创建默认模块文件" if not os.path.exists(self.appname): @@ -425,39 +480,54 @@ class create: f=open("./server.py","w+",encoding='utf-8') f.write(servertext) f.close() - return True + return True,"应用创建成功" else: if not os.path.isfile(self.appname+"/__init__.py") or not os.path.exists(self.appname+"/common"): - raise Exception(self.appname+"不是kcweb应用") - + return False,self.appname+"不是kcweb应用" if os.path.exists(self.appname+"/"+self.modular): - raise Exception(self.appname+"/"+self.modular+"已存在") + return False,self.appname+"/"+self.modular+"已存在" else: - if os.path.isfile(self.appname+"/"+self.modular+".zip"):#安装打包好的模块 - zip.unzip_file(self.appname+"/"+self.modular+".zip",self.appname+"/"+self.modular+"/") - os.remove(self.appname+"/"+self.modular+".zip") - content="\nfrom . import "+self.modular - f=open(self.appname+"/__init__.py","a",encoding='utf-8') - f.write(content) + http=Http() + http.openurl(config.domain['kcwebapi']+"/pub/modular","POST",data={"name":self.modular}) + arr=json_decode(http.get_text)['data'] + print(config.domain['kcwebapi']+"/pub/modular") + del http + if arr: + r=requests.get(config.domain['kcwebfile']+"/"+arr['fileurl']) + f = open(self.appname+"/"+self.modular+".zip", "wb") + for chunk in r.iter_content(chunk_size=1024*100): + if chunk: + f.write(chunk) f.close() - if not os.path.isfile("./server.py"): - if "Windows" in platform.platform(): - pythonname="python" + if os.path.isfile(self.appname+"/"+self.modular+".zip"):#安装打包好的模块 + zip.unzip_file(self.appname+"/"+self.modular+".zip",self.appname+"/"+self.modular+"/") + os.remove(self.appname+"/"+self.modular+".zip") + content="\nfrom . import "+self.modular + f=open(self.appname+"/__init__.py","a",encoding='utf-8') + f.write(content) + f.close() else: - pythonname="python3" - # sys.argv[0]=re.sub('.py','',sys.argv[0]) - servertext=('# #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ - 'from kcweb import web\n'+ - 'import '+self.appname+' as application\n'+ - 'from '+self.appname+'.common import *\n'+ - 'app=web(__name__,application)\n'+ - 'if __name__ == "__main__":\n'+ - ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ - ' app.run(host="0.0.0.0",port="39001",name="'+pythonname+'")') - f=open("./server.py","w+",encoding='utf-8') - f.write(servertext) - f.close() - return True + return False,self.modular+"模块下载失败" + if not os.path.isfile("./server.py"): + if "Windows" in platform.platform(): + pythonname="python" + else: + pythonname="python3" + # sys.argv[0]=re.sub('.py','',sys.argv[0]) + servertext=('# #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ + 'from kcweb import web\n'+ + 'import '+self.appname+' as application\n'+ + 'from '+self.appname+'.common import *\n'+ + 'app=web(__name__,application)\n'+ + 'if __name__ == "__main__":\n'+ + ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ + ' app.run(host="0.0.0.0",port="39001",name="'+pythonname+'")') + f=open("./server.py","w+",encoding='utf-8') + f.write(servertext) + f.close() + return True,"安装成功" + else: + return False,"找不到"+self.modular+"模块" # def __zxmodular(self,sourcep): # "处理模块文件" # path1=self.path+"/application/api"+sourcep diff --git a/config/__init__.py b/config/__init__.py index 080dc94..29b988a 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -99,9 +99,12 @@ kcweb['author']='禄可集团-坤坤' #名字 kcweb['author_email']='fk1402936534@qq.com' #邮件地址 kcweb['maintainer']='坤坤' #维护人员的名字 kcweb['maintainer_email']='fk1402936534@qq.com' #维护人员的邮件地址 +kcweb['username']='' +kcweb['password']='' domain={} domain['kcwebfile']="http://file.kwebapp.cn" +domain['kcwebapi']="http://kcweb.kwebapp.cn" #其他配置 other={} -- Gitee From 4a6782f64e175772ee9c8306e097593f28a09ab4 Mon Sep 17 00:00:00 2001 From: kunkun Date: Mon, 1 Jun 2020 18:35:38 +0800 Subject: [PATCH 17/52] kun --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index fae236f..00e38ff 100644 --- a/app.py +++ b/app.py @@ -62,7 +62,7 @@ class web: name: python命令行解释机名字 """ - if '--web' in sys.argv or True: + if 'eventlog' in sys.argv or len(sys.argv)==1: filename=sys.argv[0][:-3] if self.__config.app['app_debug']: arg=sys.argv -- Gitee From cfac847888f1240e142fab45af7d218f27e1e2fc Mon Sep 17 00:00:00 2001 From: kunkun Date: Tue, 2 Jun 2020 22:10:47 +0800 Subject: [PATCH 18/52] kun --- app.py | 3 ++- common/request.py | 7 +++++-- config/__init__.py | 2 +- setup.py | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index fae236f..8676e49 100644 --- a/app.py +++ b/app.py @@ -200,7 +200,7 @@ class web: param=[] urls='' i=0 - HTTP_HOST=header['HTTP_HOST'].split(".")[0] + # HTTP_HOST=header['HTTP_HOST'].split(".")[0] ##默认路由start ################################################################################# if modular: @@ -331,6 +331,7 @@ class web: if PATH_INFO[0]==' ' or PATH_INFO[0]=='': del PATH_INFO[0] methods,modular,plug,files,funct,param=web.defaultroute(self,header,PATH_INFO) + globals.VAR.component=(methods,modular,plug,files,funct,param) if header['REQUEST_METHOD'] in methods: try: obj=getattr(web.__appname,modular) diff --git a/common/request.py b/common/request.py index 3b2582a..46245e0 100644 --- a/common/request.py +++ b/common/request.py @@ -26,9 +26,9 @@ class HEADER: def Method(): return kcwglobals.HEADER.Method def URL(): - return kcwglobals.HEADER.URL + return kcwglobals.HEADER.URL.lstrip() def PATH_INFO(): - return kcwglobals.HEADER.PATH_INFO + return kcwglobals.HEADER.PATH_INFO.lstrip() def SERVER_PROTOCOL(): return kcwglobals.HEADER.SERVER_PROTOCOL def HTTP_HOST(): @@ -42,3 +42,6 @@ def get_json(): return json.loads(kcwglobals.HEADER.BODY_DATA) except: return None +def getroutecomponent(): + "获取路由" + return kcwglobals.VAR.component diff --git a/config/__init__.py b/config/__init__.py index 29b988a..7638907 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='3.0.2' #项目版本 +kcweb['version']='3.1.0' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index 84ed29a..c1e513f 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='3.0.10' #项目版本 +confkcw['version']='3.1.0' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From 1b02b4be568737c3d82644c85a1762611a0188f1 Mon Sep 17 00:00:00 2001 From: kunkun Date: Tue, 2 Jun 2020 22:11:29 +0800 Subject: [PATCH 19/52] kun --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index d86adf8..8676e49 100644 --- a/app.py +++ b/app.py @@ -62,7 +62,7 @@ class web: name: python命令行解释机名字 """ - if 'eventlog' in sys.argv or len(sys.argv)==1: + if '--web' in sys.argv or True: filename=sys.argv[0][:-3] if self.__config.app['app_debug']: arg=sys.argv -- Gitee From 5d0f55e9730726b008ee648c8f43f5109b8877bf Mon Sep 17 00:00:00 2001 From: kunkun Date: Fri, 5 Jun 2020 16:32:56 +0800 Subject: [PATCH 20/52] kun --- utill/db/mongodb.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/utill/db/mongodb.py b/utill/db/mongodb.py index aa17924..8f0c87a 100644 --- a/utill/db/mongodb.py +++ b/utill/db/mongodb.py @@ -46,6 +46,13 @@ class mongo: "获取mongodb链接实例" self.__setconn() return self.__tabobj + __order=None + def order(self,order): + """设置排序 + + str="id desc" + """ + self.__order=order def select(self,id=None): """查询所有文档 @@ -57,7 +64,7 @@ class mongo: self.where('_id',id) lists=[] if self.__field: - arr=self.__tabobj.find(self.__where,self.__field) + arr=self.__tabobj.find(self.__where,self.__field,sort=self.__order) else: arr=self.__tabobj.find(self.__where) if self.__limit: @@ -209,6 +216,7 @@ class mongo: mongo.__field={} mongo.__where={} mongo.__table=None + mongo.__order=None __where={} def where(self,where = None,*wheres): """设置过滤条件 -- Gitee From 2e12bd39e0661dd2302c2b6e2c233bc1cfaff26f Mon Sep 17 00:00:00 2001 From: kunkun Date: Fri, 5 Jun 2020 16:43:01 +0800 Subject: [PATCH 21/52] kun --- utill/db/mongodb.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utill/db/mongodb.py b/utill/db/mongodb.py index 8f0c87a..d365abe 100644 --- a/utill/db/mongodb.py +++ b/utill/db/mongodb.py @@ -50,9 +50,10 @@ class mongo: def order(self,order): """设置排序 - str="id desc" + order [('_id', -1)] """ self.__order=order + return self def select(self,id=None): """查询所有文档 @@ -66,7 +67,8 @@ class mongo: if self.__field: arr=self.__tabobj.find(self.__where,self.__field,sort=self.__order) else: - arr=self.__tabobj.find(self.__where) + arr=self.__tabobj.find(self.__where,sort=self.__order) + print(self.__order) if self.__limit: if self.__limit[1]: arr.limit(self.__limit[1]) -- Gitee From 4f63bba17d5c83a048838d76401b28b6a4a26336 Mon Sep 17 00:00:00 2001 From: kunkun Date: Fri, 5 Jun 2020 17:15:43 +0800 Subject: [PATCH 22/52] kun --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 8676e49..d86adf8 100644 --- a/app.py +++ b/app.py @@ -62,7 +62,7 @@ class web: name: python命令行解释机名字 """ - if '--web' in sys.argv or True: + if 'eventlog' in sys.argv or len(sys.argv)==1: filename=sys.argv[0][:-3] if self.__config.app['app_debug']: arg=sys.argv -- Gitee From 79fbbc66831db7d5a2e5556acc3d4a4cd96b5515 Mon Sep 17 00:00:00 2001 From: kunkun Date: Sun, 7 Jun 2020 18:33:45 +0800 Subject: [PATCH 23/52] kun --- common/autoload.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index d30fb51..5ef07cf 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -514,10 +514,9 @@ class create: else: pythonname="python3" # sys.argv[0]=re.sub('.py','',sys.argv[0]) - servertext=('# #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ + servertext=('# -*- coding: utf-8 -*-\n#gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ 'from kcweb import web\n'+ 'import '+self.appname+' as application\n'+ - 'from '+self.appname+'.common import *\n'+ 'app=web(__name__,application)\n'+ 'if __name__ == "__main__":\n'+ ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ @@ -528,7 +527,7 @@ class create: return True,"安装成功" else: return False,"找不到"+self.modular+"模块" - # def __zxmodular(self,sourcep): + # def __zxmodular(self,sourcep): # "处理模块文件" # path1=self.path+"/application/api"+sourcep # path2=self.appname+"/"+self.modular+sourcep -- Gitee From d1d37b454f77afc0fe3290ef8ac32ff50df4a8de Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 10 Jun 2020 20:44:16 +0800 Subject: [PATCH 24/52] kun --- common/autoload.py | 3 +-- config/__init__.py | 6 ++++-- utill/db/mysql.py | 22 ++++++++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index 5ef07cf..073ede6 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -469,10 +469,9 @@ class create: pythonname="python" else: pythonname="python3" - servertext=('# #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ + servertext=('# -*- coding: utf-8 -*-\n #gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ 'from kcweb import web\n'+ 'import '+self.appname+' as application\n'+ - 'from '+self.appname+'.common import *\n'+ 'app=web(__name__,application)\n'+ 'if __name__ == "__main__":\n'+ ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ diff --git a/config/__init__.py b/config/__init__.py index 7638907..f6a244b 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -6,7 +6,7 @@ app['tpl_folder']='./tpl' #设置模板文件目录名 注意:不能配置目 app['before_request']='' #设置请求前执行的函数 app['after_request']='' #设置请求后执行的函数 app['staticpath']='static' -app['http_server']='kcweb_server' #使用的开发服务器 支持 wsgiref、kcweb、kcweb_server +app['http_server']='wsgiref' #使用的开发服务器 支持 wsgiref、kcweb、kcweb_server # redis配置 redis={} redis['host']='127.0.0.1' #服务器地址 @@ -103,7 +103,9 @@ kcweb['username']='' kcweb['password']='' domain={} -domain['kcwebfile']="http://file.kwebapp.cn" +domain['kcwebfile']="https://file.kwebapp.cn" +domain['kcwebstatic']="https://static.kwebapp.cn" +domain['kcwebimg']="https://img.kwebapp.cn" domain['kcwebapi']="http://kcweb.kwebapp.cn" #其他配置 diff --git a/utill/db/mysql.py b/utill/db/mysql.py index 2f9e2e1..e802c64 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -18,11 +18,20 @@ class mysql: __slaveidentifier='' # 从服务器标识 def __del__(self): if not self.__config['pattern'] and self.__conn: - try: + if isinstance(self.__conn,dict): + i=0 + for thost in self.__config['host']: + identifier=self.__config['host'][i]+str(self.__config['port'][i])+self.__config['db'][i] + for k in self.__conn[identifier]: + try: + k['obj'].close() + except Exception as e: + print(k,"连接关闭失败",str(e)) + i+=1 + self.__conn={} + elif isinstance(self.__conn,object): self.__conn.close() - except Exception as e: - if self.__config['debug']: - print("关闭失败",e) + self.__conn={} __dbcount=1 def __setdbcount(self): "设置数据库配置总数量" @@ -63,7 +72,6 @@ class mysql: 参数 typess :数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL """ - try: if self.__config['deploy']==0: # 集中式(单一服务器) if self.__config['pattern']: # 长连接情况下 @@ -349,7 +357,9 @@ class mysql: except Exception as e: if self.__config['debug']: print("关闭异常",e) - raise Exception(e) + else: + self.__connects(typess) + self.__execute(typess) else: # 短连接情况下 if self.__config['debug']: print("服务器正在被关闭,关闭当前连接后重试") -- Gitee From d11ad8d1d05b48f38eb4def982e817c5198eb43f Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 17 Jun 2020 23:26:05 +0800 Subject: [PATCH 25/52] kun --- common/autoload.py | 4 ++++ config/__init__.py | 6 +++--- utill/db/mysql.py | 8 ++++---- utill/queues.py | 43 +++++++++++++++++++++++-------------------- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index 073ede6..2e95eb8 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -314,6 +314,8 @@ def list_to_tree(data, pk = 'id', pid = 'pid', child = 'lowerlist', root=0,child v[child]=kkkk arr.append(v) return arr + + class zip: def packzip(dirname,zipfilename): filelist = [] @@ -377,6 +379,7 @@ class create: files={'file':open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", 'rb')}) arr=json_decode(http.get_text) del http + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") if arr and arr['code']==0: return True,arr['msg'],arr['data'] elif arr: @@ -446,6 +449,7 @@ class create: files={'file':open(self.appname+"/"+self.modular+".zip", 'rb')}) arr=json_decode(http.get_text) del http + os.remove(self.appname+"/"+self.modular+".zip") if arr and arr['code']==0: return True,arr['msg'] elif arr: diff --git a/config/__init__.py b/config/__init__.py index f6a244b..c9c54e8 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -103,9 +103,9 @@ kcweb['username']='' kcweb['password']='' domain={} -domain['kcwebfile']="https://file.kwebapp.cn" -domain['kcwebstatic']="https://static.kwebapp.cn" -domain['kcwebimg']="https://img.kwebapp.cn" +domain['kcwebfile']="http://file.kwebapp.cn" +domain['kcwebstatic']="http://static.kwebapp.cn" +domain['kcwebimg']="http://img.kwebapp.cn" domain['kcwebapi']="http://kcweb.kwebapp.cn" #其他配置 diff --git a/utill/db/mysql.py b/utill/db/mysql.py index e802c64..3235a9a 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -21,7 +21,7 @@ class mysql: if isinstance(self.__conn,dict): i=0 for thost in self.__config['host']: - identifier=self.__config['host'][i]+str(self.__config['port'][i])+self.__config['db'][i] + identifier=thost+str(self.__config['port'][i])+self.__config['user'][i]+self.__config['password'][i]+self.__config['db'][i] for k in self.__conn[identifier]: try: k['obj'].close() @@ -75,7 +75,7 @@ class mysql: try: if self.__config['deploy']==0: # 集中式(单一服务器) if self.__config['pattern']: # 长连接情况下 - self.__masteridentifier=self.__config['host'][0]+str(self.__config['port'][0])+self.__config['db'][0] # 服务器标识 + self.__masteridentifier=self.__config['host'][0]+str(self.__config['port'][0])+self.__config['user'][0]+self.__config['password'][0]+self.__config['db'][0] # 服务器标识 if self.__masteridentifier not in mysql.__conn or len(mysql.__conn[self.__masteridentifier])<1: i=0 masterlistsdb=[] @@ -94,12 +94,12 @@ class mysql: j=0 self.__masteridentifier='' while j < self.__config['master_num']: - self.__masteridentifier=self.__masteridentifier+self.__config['host'][j]+str(self.__config['port'][j])+self.__config['db'][j] # 主服务器标识 + self.__masteridentifier=self.__masteridentifier+self.__config['host'][j]+str(self.__config['port'][j])+self.__config['user'][j]+self.__config['password'][j]+self.__config['db'][j] # 主服务器标识 j=j+1 j=self.__config['master_num'] self.__slaveidentifier='' while j < self.__dbcount: - self.__slaveidentifier=self.__slaveidentifier+self.__config['host'][j]+str(self.__config['port'][j])+self.__config['db'][j] # 从服务器标识 + self.__slaveidentifier=self.__slaveidentifier+self.__config['host'][j]+str(self.__config['port'][j])+self.__config['user'][j]+self.__config['password'][j]+self.__config['db'][j] # 从服务器标识 j=j+1 if self.__masteridentifier not in mysql.__conn or len(mysql.__conn[self.__masteridentifier]) Date: Wed, 17 Jun 2020 23:30:00 +0800 Subject: [PATCH 26/52] kun --- config/__init__.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index c9c54e8..f0c60c9 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -24,7 +24,7 @@ cache['expire']=120 #缓存有效期 0表示永久缓存 cache['host']=redis['host'] #Redis服务器地址 cache['port']=redis['port'] #Redis 端口 cache['password']=redis['password'] #Redis登录密码 -cache['db']=1 #Redis数据库 注:Redis用1或2或3等表示 +cache['db']=0 #Redis数据库 注:Redis用1或2或3等表示 # session配置 session={} @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='3.1.0' #项目版本 +kcweb['version']='3.5.0' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index c1e513f..d647f61 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='3.1.0' #项目版本 +confkcw['version']='3.5.0' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From 10d78787e2c61fa0652c0d41a937cf6515a425b7 Mon Sep 17 00:00:00 2001 From: kunkun Date: Sat, 20 Jun 2020 01:04:15 +0800 Subject: [PATCH 27/52] kun --- Events.py | 2 +- common/autoload.py | 292 +++++++++++++++++++++++++++++---------------- config/__init__.py | 2 +- setup.py | 2 +- 4 files changed, 193 insertions(+), 105 deletions(-) diff --git a/Events.py b/Events.py index 5e202b0..4654f28 100644 --- a/Events.py +++ b/Events.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- import os, sys, time, subprocess,signal from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler diff --git a/common/autoload.py b/common/autoload.py index 2e95eb8..a04c56e 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import time,hashlib,json,re,os,platform,sys,shutil,zipfile,requests +import time,hashlib,json,re,os,platform,sys,shutil,zipfile,requests,importlib import datetime as core_datetime from kcweb import config from kcweb.utill.dateutil.relativedelta import relativedelta as core_relativedelta @@ -307,7 +307,6 @@ def list_to_tree(data, pk = 'id', pid = 'pid', child = 'lowerlist', root=0,child if v[pid] == root: kkkk=list_to_tree(data,pk,pid,child,v[pk],childstatus) if childstatus: - # print(kkkk) v[child]=kkkk else: if kkkk: @@ -327,7 +326,6 @@ class zip: zf = zipfile.ZipFile(zipfilename, "w", zipfile.zlib.DEFLATED) for tar in filelist: arcname = tar[len(dirname):] - #print arcname zf.write(tar,arcname) zf.close() def unzip_file(zipfilename, unziptodir): @@ -349,8 +347,9 @@ class create: f=open(self.appname+"/"+self.modular+"/controller/__init__.py","r",encoding='utf-8') text=f.read() f.close() - f=open(self.appname+"/"+self.modular+"/controller/__init__.py","w",encoding='utf-8') + text=re.sub("\nfrom . import "+plug,"",text) text=re.sub("from . import "+plug,"",text) + f=open(self.appname+"/"+self.modular+"/controller/__init__.py","w",encoding='utf-8') f.write(text) f.close() shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug) @@ -366,27 +365,46 @@ class create: return True,"成功" else: return False,"失败" - def uploadplug(self,plug,username,password): + def uploadplug(self,plug,username='',password='',cli=False): "上传一个插件" - timestamp=times() - sign=md5(str(username)+str(timestamp)+md5(md5(password))) + i=0 http=Http() - http.set_header['username']=username - http.set_header['timestamp']=str(timestamp) - http.set_header['sign']=sign - http.openurl(config.domain['kcwebapi']+"/user/uploadplug/",'POST', - data={'name':str(plug),'describes':'','modular':self.modular}, - files={'file':open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", 'rb')}) - arr=json_decode(http.get_text) - del http - os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - if arr and arr['code']==0: - return True,arr['msg'],arr['data'] - elif arr: - return False,arr['msg'] - else: - return False,"上传失败,服务器暂时无法处理上传" - def installplug(self,plug,edition=''): + while True: + timestamp=times() + sign=md5(str(username)+str(timestamp)+md5(md5(password))) + http=Http() + http.set_header['username']=username + http.set_header['timestamp']=str(timestamp) + http.set_header['sign']=sign + http.openurl(config.domain['kcwebapi']+"/user/uploadplug/",'POST', + data={'name':str(plug),'describes':'','modular':self.modular}, + files={'file':open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", 'rb')}) + arr=json_decode(http.get_text) + if not arr: + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + return False,"上传失败,服务器暂时无法处理上传" + if (arr['code']==-1 or arr['code']==2) and cli: + if i >= 3: + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + return False,"用户名或密码错误" + elif i: + print("用户名或密码错误,请重新输入") + username = input("请输入用户名(手机号)\n") + password = input("请输入密码\n") + else: + username = input("请输入用户名(手机号)\n") + password = input("请输入密码\n") + i+=1 + elif arr['code']==-1: + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + return False,"用户名或密码错误" + elif arr['code']==0: + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + return True,arr['msg'] + else: + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + return False,arr['msg'] + def installplug(self,plug,edition='',token='',cli=False): """创建一个插件,如果您的模块目录下没有插件包,则创建默认插件文件 plug 插件名 @@ -396,35 +414,62 @@ class create: return False,"该插件已存在" else: http=Http() - http.openurl(config.domain['kcwebapi']+"/pub/plug","POST",data={"modular":self.modular,"name":str(plug),"edition":str(edition)}) - arr=json_decode(http.get_text)['data'] - del http - if arr: - r=requests.get(config.domain['kcwebfile']+"/"+arr['fileurl']) - f = open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", "wb") - for chunk in r.iter_content(chunk_size=512): - if chunk: - f.write(chunk) - f.close() - if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 - zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") - os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - f=open(self.appname+"/"+self.modular+"/controller/__init__.py","a",encoding='utf-8') - text="\nfrom . import "+plug - f.write(text) - f.close() - return True,"插件安装成功,"+plug+"=="+str(arr['edition']) + i=0 + while True: + http.openurl(config.domain['kcwebapi']+"/pub/plug","POST",data={"modular":self.modular,"name":str(plug),"edition":str(edition),"token":token}) + arr=json_decode(http.get_text) + if arr: + if arr['code']==-1 and cli: + if i >= 3: + return False,plug+"插件授权码错误" + elif i: + token = input("授权码错误,请重新输入授权码,从而获得该插件\n") + else: + token = input("请输入授权码,从而获得该插件\n") + i+=1 + elif arr['code']==-1: + return False,plug+"插件授权码错误" + elif arr['code']==0: + arr=arr['data'] + r=requests.get(arr['dowurl']) + f = open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", "wb") + for chunk in r.iter_content(chunk_size=512): + if chunk: + f.write(chunk) + f.close() + if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 + zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + try: + m=importlib.import_module(self.appname+"."+self.modular+"/controller/"+plug+".install") + except: + shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + return False,"插件依赖包文件不存在或依赖包文件格式错误" + else: + try: + m.install() + except: + shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + return False,"插件依赖包install函数被破坏" + f=open(self.appname+"/"+self.modular+"/controller/__init__.py","a",encoding='utf-8') + text="\nfrom . import "+plug + f.write(text) + f.close() + return True,"插件安装成功,"+plug+"=="+str(arr['edition']) + else: + return False,str(plug)+"插件下载失败" + else: + return False,str(plug)+"插件下载失败" else: - return False,str(plug)+"插件下载失败" - else: - return False,self.modular+"模块下找不到"+str(plug)+"插件" + return False,self.modular+"模块下找不到"+str(plug)+"插件" def uninstallmodular(self): "卸载模块" f=open(self.appname+"/__init__.py","r") text=f.read() f.close() - f=open(self.appname+"/__init__.py","w") + text=re.sub("\nfrom . import "+self.modular,"",text) text=re.sub("from . import "+self.modular,"",text) + f=open(self.appname+"/__init__.py","w") f.write(text) f.close() shutil.rmtree(self.appname+"/"+self.modular) @@ -436,27 +481,45 @@ class create: return True,"成功" else: return False,"失败" - def uploadmodular(self,username,password): + def uploadmodular(self,username='',password='',cli=False): "上传模块" - timestamp=times() - sign=md5(str(username)+str(timestamp)+md5(md5(password))) + i=0 http=Http() - http.set_header['username']=username - http.set_header['timestamp']=str(timestamp) - http.set_header['sign']=sign - http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/",'POST', - data={'name':str(self.modular),'describes':''}, - files={'file':open(self.appname+"/"+self.modular+".zip", 'rb')}) - arr=json_decode(http.get_text) - del http - os.remove(self.appname+"/"+self.modular+".zip") - if arr and arr['code']==0: - return True,arr['msg'] - elif arr: - return False,arr['msg'] - else: - return False,"上传失败,服务器暂时无法处理上传" - def installmodular(self): + while True: + timestamp=times() + sign=md5(str(username)+str(timestamp)+md5(md5(password))) + http.set_header['username']=username + http.set_header['timestamp']=str(timestamp) + http.set_header['sign']=sign + http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/",'POST', + data={'name':str(self.modular),'describes':''}, + files={'file':open(self.appname+"/"+self.modular+".zip", 'rb')}) + arr=json_decode(http.get_text) + if not arr: + os.remove(self.appname+"/"+self.modular+".zip") + return False,"上传失败,服务器暂时无法处理上传" + if (arr['code']==-1 or arr['code']==2) and cli: + if i >= 3: + os.remove(self.appname+"/"+self.modular+".zip") + return False,"用户名或密码错误" + elif i: + print("用户名或密码错误,请重新输入") + username = input("请输入用户名(手机号)\n") + password = input("请输入密码\n") + else: + username = input("请输入用户名(手机号)\n") + password = input("请输入密码\n") + i+=1 + elif arr['code']==-1: + os.remove(self.appname+"/"+self.modular+".zip") + return False,"用户名或密码错误" + elif arr['code']==0: + os.remove(self.appname+"/"+self.modular+".zip") + return True,arr['msg'] + else: + os.remove(self.appname+"/"+self.modular+".zip") + return False,arr['msg'] + def installmodular(self,token='',cli=False): "创建模块,如果应用不存,则创建默认应用,如果在您的应用目录下没有模块包,则创建默认模块文件" if not os.path.exists(self.appname): # os.makedirs(self.appname) @@ -491,45 +554,70 @@ class create: return False,self.appname+"/"+self.modular+"已存在" else: http=Http() - http.openurl(config.domain['kcwebapi']+"/pub/modular","POST",data={"name":self.modular}) - arr=json_decode(http.get_text)['data'] - print(config.domain['kcwebapi']+"/pub/modular") - del http - if arr: - r=requests.get(config.domain['kcwebfile']+"/"+arr['fileurl']) - f = open(self.appname+"/"+self.modular+".zip", "wb") - for chunk in r.iter_content(chunk_size=1024*100): - if chunk: - f.write(chunk) - f.close() - if os.path.isfile(self.appname+"/"+self.modular+".zip"):#安装打包好的模块 - zip.unzip_file(self.appname+"/"+self.modular+".zip",self.appname+"/"+self.modular+"/") - os.remove(self.appname+"/"+self.modular+".zip") - content="\nfrom . import "+self.modular - f=open(self.appname+"/__init__.py","a",encoding='utf-8') - f.write(content) - f.close() - else: - return False,self.modular+"模块下载失败" - if not os.path.isfile("./server.py"): - if "Windows" in platform.platform(): - pythonname="python" + i=0 + while True: + http.openurl(config.domain['kcwebapi']+"/pub/modular","POST",data={"name":self.modular,"token":token}) + arr=json_decode(http.get_text) + if arr: + if arr['code']==-1 and cli: + if i >= 3: + return False,self.modular+"模块授权码错误" + elif i: + token = input("授权码错误,请重新输入授权码,从而获得该模块\n") + else: + token = input("请输入授权码,从而获得该模块\n") + i+=1 + elif arr['code']==-1: + return False,self.modular+"模块授权码错误" + elif arr['code']==0: + arr=arr['data'] + r=requests.get(arr['dowurl']) + f = open(self.appname+"/"+self.modular+".zip", "wb") + for chunk in r.iter_content(chunk_size=1024*100): + if chunk: + f.write(chunk) + f.close() + if os.path.isfile(self.appname+"/"+self.modular+".zip"):#安装打包好的模块 + zip.unzip_file(self.appname+"/"+self.modular+".zip",self.appname+"/"+self.modular+"/") + os.remove(self.appname+"/"+self.modular+".zip") + try: + m=importlib.import_module(self.appname+'.'+self.modular+'.install') + except: + shutil.rmtree(self.appname+"/"+self.modular) + return False,"模块依赖包文件不存在或依赖包文件格式错误" + else: + try: + m.install() + except: + shutil.rmtree(self.appname+"/"+self.modular) + return False,"模块依赖包install函数被破坏" + content="\nfrom . import "+self.modular + f=open(self.appname+"/__init__.py","a",encoding='utf-8') + f.write(content) + f.close() + else: + return False,self.modular+"模块下载失败" + if not os.path.isfile("./server.py"): + if "Windows" in platform.platform(): + pythonname="python" + else: + pythonname="python3" + # sys.argv[0]=re.sub('.py','',sys.argv[0]) + servertext=('# -*- coding: utf-8 -*-\n#gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ + 'from kcweb import web\n'+ + 'import '+self.appname+' as application\n'+ + 'app=web(__name__,application)\n'+ + 'if __name__ == "__main__":\n'+ + ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ + ' app.run(host="0.0.0.0",port="39001",name="'+pythonname+'")') + f=open("./server.py","w+",encoding='utf-8') + f.write(servertext) + f.close() + return True,"安装成功" else: - pythonname="python3" - # sys.argv[0]=re.sub('.py','',sys.argv[0]) - servertext=('# -*- coding: utf-8 -*-\n#gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+ - 'from kcweb import web\n'+ - 'import '+self.appname+' as application\n'+ - 'app=web(__name__,application)\n'+ - 'if __name__ == "__main__":\n'+ - ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+ - ' app.run(host="0.0.0.0",port="39001",name="'+pythonname+'")') - f=open("./server.py","w+",encoding='utf-8') - f.write(servertext) - f.close() - return True,"安装成功" - else: - return False,"找不到"+self.modular+"模块" + return False,"模块下载失败" + else: + return False,"找不到"+self.modular+"模块" # def __zxmodular(self,sourcep): # "处理模块文件" # path1=self.path+"/application/api"+sourcep diff --git a/config/__init__.py b/config/__init__.py index f0c60c9..34c2071 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='3.5.0' #项目版本 +kcweb['version']='4.0.0' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index d647f61..c4d8c18 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='3.5.0' #项目版本 +confkcw['version']='4.0.0' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From c1cd78fe72642b7e8c0cced9d19a8b4e1307ac7e Mon Sep 17 00:00:00 2001 From: kunkun Date: Sat, 20 Jun 2020 03:03:23 +0800 Subject: [PATCH 28/52] kun --- common/session.py | 4 +--- config/__init__.py | 4 ++-- setup.py | 2 +- utill/cache/cache.py | 14 ++++++++------ utill/redis.py | 22 ++++++++++++++++------ 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/common/session.py b/common/session.py index 373ca2f..13bb78a 100644 --- a/common/session.py +++ b/common/session.py @@ -26,10 +26,8 @@ def set(name,value,expire=None): if not token: strs="kcw"+str(time.time())+str(random.randint(0,9)) token=__md5(strs) - # print(token) kcwglobals.set_cookie=SESSIONID+"="+token+";expires="+datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')+"; Max-Age=%d;Path=/" % (int(expire)*10) - kcwcache.cache().set_config(kcwsession).set_cache(token,value,expire) - return True + return kcwcache.cache().set_config(kcwsession).set_cache(token,value,expire) def get(name): "获取session" HTTP_COOKIE=kcwglobals.HEADER.HTTP_COOKIE diff --git a/config/__init__.py b/config/__init__.py index 34c2071..6195161 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -24,7 +24,7 @@ cache['expire']=120 #缓存有效期 0表示永久缓存 cache['host']=redis['host'] #Redis服务器地址 cache['port']=redis['port'] #Redis 端口 cache['password']=redis['password'] #Redis登录密码 -cache['db']=0 #Redis数据库 注:Redis用1或2或3等表示 +cache['db']=1 #Redis数据库 注:Redis用1或2或3等表示 # session配置 session={} @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.0.0' #项目版本 +kcweb['version']='4.10.1' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index c4d8c18..4ed00c1 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.0.0' #项目版本 +confkcw['version']='4.10.1' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 diff --git a/utill/cache/cache.py b/utill/cache/cache.py index 17c87f1..710b854 100644 --- a/utill/cache/cache.py +++ b/utill/cache/cache.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import os,sys,time,hashlib,json from kcweb import config -from kcweb.utill import redis +from kcweb.utill import rediss as red from kcweb.utill.db.mysql import mysql import time,hashlib @@ -63,15 +63,15 @@ class cache: conf['db']=self.__config['db'] if conf['pattern']: if conf['password']: - redis_pool=redis.ConnectionPool(host=conf['host'],password=conf['password'],port=conf['port'],db=conf['db']) + redis_pool=red.ConnectionPool(host=conf['host'],password=conf['password'],port=conf['port'],db=conf['db']) else: - redis_pool=redis.ConnectionPool(host=conf['host'],port=conf['port'],db=conf['db']) - self.__redisobj=redis.Redis(connection_pool=redis_pool) + redis_pool=red.ConnectionPool(host=conf['host'],port=conf['port'],db=conf['db']) + self.__redisobj=red.Redis(connection_pool=redis_pool) else: if conf['password']: - self.__redisobj=redis.Redis(host=conf['host'],password=conf['password'],port=conf['port'],db=conf['db']) + self.__redisobj=red.Redis(host=conf['host'],password=conf['password'],port=conf['port'],db=conf['db']) else: - self.__redisobj=redis.Redis(host=conf['host'],port=conf['port'],db=conf['db']) + self.__redisobj=red.Redis(host=conf['host'],port=conf['port'],db=conf['db']) def set_cache(self,name,values,expire = 'no'): """设置缓存 @@ -140,6 +140,8 @@ class cache: return self.__getmysqlcache() elif types == 'del': return self.__delmysqlcache() + else: + raise Exception("缓存类型错误") def __setmysqlcache(self): ######################################################################################## """设置mysql缓存 diff --git a/utill/redis.py b/utill/redis.py index d717e68..48655a2 100644 --- a/utill/redis.py +++ b/utill/redis.py @@ -5,22 +5,29 @@ import json class redis: "redis 注意:连接池链接模式下不支持动态配置" __redisObj=None + __coninfo={} __config=config.redis + __identifier='' def __connects(self): """设置redis链接""" if self.__config['pattern']: - if not self.__redisObj: + self.__identifier=self.__config['host']+self.__config['password']+str(self.__config['port'])+str(self.__config['db']) + if self.__identifier not in self.__coninfo: if self.__config['password']: redis_pool=red.ConnectionPool(host=self.__config['host'],password=self.__config['password'],port=self.__config['port'],db=self.__config['db']) else: redis_pool=red.ConnectionPool(host=self.__config['host'],port=self.__config['port'],db=self.__config['db']) - self.__redisObj=red.Redis(connection_pool=redis_pool) + self.__coninfo[self.__identifier]=red.Redis(connection_pool=redis_pool) + if config.app['app_debug']: + print("建立redis连接池",self.__identifier) + self.__redisObj=self.__coninfo[self.__identifier] else: if self.__config['password']: self.__redisObj=red.Redis(host=self.__config['host'],password=self.__config['password'],port=self.__config['port'],db=self.__config['db']) else: self.__redisObj=red.Redis(host=self.__config['host'],port=self.__config['port'],db=self.__config['db']) - # print(self.__redisObj) + if config.app['app_debug']: + print("建立redis连接",self.__identifier) def __json_decode(self,strs): """json字符串转python类型""" try: @@ -43,7 +50,9 @@ class redis: 返回 redis """ if config: - if isinstance(config,dict): + if isinstance(config,int): + self.__config['db']=config + elif isinstance(config,dict): if "host" in config: self.__config['host']=config['host'] if "port" in config: @@ -52,6 +61,8 @@ class redis: self.__config['password']=config['password'] if "db" in config: self.__config['db']=config['db'] + else: + raise Exception("配置信息错误") return self def redisObj(self): "得到一个redis连接对象,执行更多高级操作" @@ -109,8 +120,7 @@ class redis: xx,如果设置为True,则只有key存在时,当前set操作才执行 """ - if not self.__redisObj: - self.__connects() + self.__connects() if not ex and not px: if self.__config['ex']: ex=self.__config['ex'] -- Gitee From ed65e9691dae29e63a293fc11fb04c8a7fa803a3 Mon Sep 17 00:00:00 2001 From: kunkun Date: Sat, 20 Jun 2020 05:55:12 +0800 Subject: [PATCH 29/52] kun --- common/autoload.py | 92 ++++++++++++++++++++++++++++++++++------------ config/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 71 insertions(+), 25 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index a04c56e..fc800bf 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import time,hashlib,json,re,os,platform,sys,shutil,zipfile,requests,importlib +import time,hashlib,json,re,os,platform,sys,shutil,zipfile,requests,importlib,traceback,pip import datetime as core_datetime from kcweb import config from kcweb.utill.dateutil.relativedelta import relativedelta as core_relativedelta @@ -440,17 +440,40 @@ class create: if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - try: - m=importlib.import_module(self.appname+"."+self.modular+"/controller/"+plug+".install") - except: - shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) - return False,"插件依赖包文件不存在或依赖包文件格式错误" - else: - try: - m.install() - except: - shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) - return False,"插件依赖包install函数被破坏" + + if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt"): #安装依赖包 + install_requires=[] + f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt") + while True: + line = f.readline() + if not line: + break + elif len(line) > 2: + install_requires.append(line) + if len(install_requires): + try: + install_requires.insert(0,"install") + if 0 != pip.main(install_requires): + shutil.rmtree(self.appname+"/"+self.modular) + return False,"error" + except AttributeError as e: + print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") + return False,str(e) + # try: + # m=importlib.import_module(self.appname+"."+self.modular+"/controller/"+plug+".install") + # except: + # shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + # print(traceback.format_exc()) + # return False,"插件依赖包文件不存在或依赖包文件格式错误" + # else: + # try: + # a=m.install() + # except: + # shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + # return False,"插件依赖包install函数被破坏" + # if not a[0]: + # shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + # return False,str(a[1]) f=open(self.appname+"/"+self.modular+"/controller/__init__.py","a",encoding='utf-8') text="\nfrom . import "+plug f.write(text) @@ -580,17 +603,40 @@ class create: if os.path.isfile(self.appname+"/"+self.modular+".zip"):#安装打包好的模块 zip.unzip_file(self.appname+"/"+self.modular+".zip",self.appname+"/"+self.modular+"/") os.remove(self.appname+"/"+self.modular+".zip") - try: - m=importlib.import_module(self.appname+'.'+self.modular+'.install') - except: - shutil.rmtree(self.appname+"/"+self.modular) - return False,"模块依赖包文件不存在或依赖包文件格式错误" - else: - try: - m.install() - except: - shutil.rmtree(self.appname+"/"+self.modular) - return False,"模块依赖包install函数被破坏" + + if os.path.isfile(self.appname+"/"+self.modular+"/install.txt"): #安装依赖包 + install_requires=[] + f=open(self.appname+"/"+self.modular+"/install.txt") + while True: + line = f.readline() + if not line: + break + elif len(line) > 3: + install_requires.append(line) + if len(install_requires): + try: + install_requires.insert(0,"install") + if 0 != pip.main(install_requires): + shutil.rmtree(self.appname+"/"+self.modular) + return False,"error" + except AttributeError as e: + print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") + return False,str(e) + # try: + # m=importlib.import_module(self.appname+'.'+self.modular+'.install') + # except: + # shutil.rmtree(self.appname+"/"+self.modular) + # print(traceback.format_exc()) + # return False,"模块依赖包文件不存在或依赖包文件格式错误" + # else: + # try: + # a=m.install() + # except: + # shutil.rmtree(self.appname+"/"+self.modular) + # return False,"模块依赖包install方法被破坏" + # if not a[0]: + # shutil.rmtree(self.appname+"/"+self.modular) + # return False,str(a[1]) content="\nfrom . import "+self.modular f=open(self.appname+"/__init__.py","a",encoding='utf-8') f.write(content) diff --git a/config/__init__.py b/config/__init__.py index 6195161..c51b73e 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.10.1' #项目版本 +kcweb['version']='4.10.5' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index 4ed00c1..4b37e53 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.10.1' #项目版本 +confkcw['version']='4.10.5' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From 7004144be520d6ebc5adb3bf9ce012134b822916 Mon Sep 17 00:00:00 2001 From: kunkun Date: Mon, 22 Jun 2020 02:37:32 +0800 Subject: [PATCH 30/52] kun --- common/autoload.py | 79 +++++++++++++++++++++++++++++++++++++--------- config/__init__.py | 10 +++--- setup.py | 2 +- utill/queues.py | 16 +++++++--- 4 files changed, 81 insertions(+), 26 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index fc800bf..d7093f0 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -332,6 +332,38 @@ class zip: zf = zipfile.ZipFile(zipfilename) zf.extractall(unziptodir) zf.close() + + + +class response: + def tpl(path=None,**context): + "返回模板内容" + getroutecomponent=globals.VAR.component + if path: + if path[:1]=="/": + Temppath=path + else: + Temppath="/"+getroutecomponent[1]+"/controller/"+getroutecomponent[2]+"/tpl/"+path+".html" + else: + Temppath="/"+getroutecomponent[1]+"/controller/"+getroutecomponent[2]+"/tpl/"+getroutecomponent[3]+"/"+getroutecomponent[4]+".html" + return Template(Temppath,config=config,**context) + def json(res=[],status='200 ok'): + "响应json内容" + return json_encode(res),status,{"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"} + def redirect(url,status="302 Found",html='',header={"Content-Type":"application/html; charset=utf-8"}): + """重定向 + + 参数 url 重定向地址 必须 + + 参数 status 响应码 可选 + + 参数 html body响应内容 可选 + + 参数 header 响应头 可选 + """ + header['Location']=url + return html,status,header + class create: appname=None modular=None @@ -376,12 +408,14 @@ class create: http.set_header['username']=username http.set_header['timestamp']=str(timestamp) http.set_header['sign']=sign + http.set_timeout=300 http.openurl(config.domain['kcwebapi']+"/user/uploadplug/",'POST', data={'name':str(plug),'describes':'','modular':self.modular}, files={'file':open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", 'rb')}) arr=json_decode(http.get_text) if not arr: os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + print(http.get_text) return False,"上传失败,服务器暂时无法处理上传" if (arr['code']==-1 or arr['code']==2) and cli: if i >= 3: @@ -443,22 +477,29 @@ class create: if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt"): #安装依赖包 install_requires=[] - f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt") - while True: - line = f.readline() - if not line: - break - elif len(line) > 2: - install_requires.append(line) + try: + f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt") + while True: + line = f.readline() + if not line: + break + elif len(line) > 2: + install_requires.append(line) + f.close() + except: + shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + return False,"error" if len(install_requires): try: install_requires.insert(0,"install") if 0 != pip.main(install_requires): - shutil.rmtree(self.appname+"/"+self.modular) + shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) return False,"error" except AttributeError as e: + shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") return False,str(e) + # try: # m=importlib.import_module(self.appname+"."+self.modular+"/controller/"+plug+".install") # except: @@ -514,12 +555,14 @@ class create: http.set_header['username']=username http.set_header['timestamp']=str(timestamp) http.set_header['sign']=sign + http.set_timeout=300 http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/",'POST', data={'name':str(self.modular),'describes':''}, files={'file':open(self.appname+"/"+self.modular+".zip", 'rb')}) arr=json_decode(http.get_text) if not arr: os.remove(self.appname+"/"+self.modular+".zip") + print(http.get_text) return False,"上传失败,服务器暂时无法处理上传" if (arr['code']==-1 or arr['code']==2) and cli: if i >= 3: @@ -606,13 +649,18 @@ class create: if os.path.isfile(self.appname+"/"+self.modular+"/install.txt"): #安装依赖包 install_requires=[] - f=open(self.appname+"/"+self.modular+"/install.txt") - while True: - line = f.readline() - if not line: - break - elif len(line) > 3: - install_requires.append(line) + try: + f=open(self.appname+"/"+self.modular+"/install.txt") + while True: + line = f.readline() + if not line: + break + elif len(line) > 3: + install_requires.append(line) + f.close() + except: + shutil.rmtree(self.appname+"/"+self.modular) + return False,"error" if len(install_requires): try: install_requires.insert(0,"install") @@ -620,6 +668,7 @@ class create: shutil.rmtree(self.appname+"/"+self.modular) return False,"error" except AttributeError as e: + shutil.rmtree(self.appname+"/"+self.modular) print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") return False,str(e) # try: diff --git a/config/__init__.py b/config/__init__.py index c51b73e..4baa062 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.10.5' #项目版本 +kcweb['version']='4.11.3' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 @@ -103,10 +103,10 @@ kcweb['username']='' kcweb['password']='' domain={} -domain['kcwebfile']="http://file.kwebapp.cn" -domain['kcwebstatic']="http://static.kwebapp.cn" -domain['kcwebimg']="http://img.kwebapp.cn" -domain['kcwebapi']="http://kcweb.kwebapp.cn" +domain['kcwebfile']="https://file.kwebapp.cn" +domain['kcwebstatic']="https://static.kwebapp.cn" +domain['kcwebimg']="https://img.kwebapp.cn" +domain['kcwebapi']="https://kcweb.kwebapp.cn" #其他配置 other={} diff --git a/setup.py b/setup.py index 4b37e53..821bcec 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.10.5' #项目版本 +confkcw['version']='4.11.3' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 diff --git a/utill/queues.py b/utill/queues.py index 8204914..f62f307 100644 --- a/utill/queues.py +++ b/utill/queues.py @@ -56,7 +56,7 @@ class Queues(): kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":4,"msg":"执行完成"}) else: time.sleep(1) - def insert(target,args=None,title="默认任务",describes="",msg='等待中'): #add_queue + def insert(target,args=None,title="默认任务",describes="",msg='等待中',taskid=None): #add_queue """添加队列 target 方法名 必须 @@ -71,9 +71,10 @@ class Queues(): """ Queues.start() ttt=int(time.time()) - m = hashlib.md5() - m.update((str(ttt)+str(random.randint(100000,999999))).encode(encoding='utf-8')) - taskid=m.hexdigest() + if not taskid: + m = hashlib.md5() + m.update((str(ttt)+str(random.randint(100000,999999))).encode(encoding='utf-8')) + taskid=m.hexdigest() task={"taskid":taskid,"title":title,"describes":describes,"code":2,"msg":msg,"error":"","addtime":ttt} key={"target":target,"args":args,"task":task} kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").insert(task) @@ -92,7 +93,12 @@ class Queues(): where=False if code: where="code="+str(code) - return kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").field("taskid,title,describes,code,msg,error,addtime").where(where).select() + try: + return kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").field("taskid,title,describes,code,msg,error,addtime").where(where).select() + except: + model_kcweb_tasks=model_kcweb_task() + model_kcweb_tasks.create_table() + return [] def status(taskid): """获取任务状态 -- Gitee From 7fcc19d8a9db1f90e53338627a243892774597d6 Mon Sep 17 00:00:00 2001 From: kunkun Date: Mon, 22 Jun 2020 11:51:53 +0800 Subject: [PATCH 31/52] kun --- utill/queues.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utill/queues.py b/utill/queues.py index f62f307..0e9d6da 100644 --- a/utill/queues.py +++ b/utill/queues.py @@ -44,14 +44,14 @@ class Queues(): try: value['target'](*value['args']) except Exception as e: - kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":1,"msg":"失败","error":str(e)}) + kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":1,"msg":"收到一个异常","error":str(e)}) else: kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":4,"msg":"执行完成"}) else: try: value['target']() except Exception as e: - kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":1,"msg":"失败","error":str(e)}) + kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":1,"msg":"收到一个异常","error":str(e)}) else: kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":4,"msg":"执行完成"}) else: -- Gitee From fadd38fd6c7c203c0f774c791089a239a4de117d Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 24 Jun 2020 22:18:09 +0800 Subject: [PATCH 32/52] kun --- utill/queues.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/utill/queues.py b/utill/queues.py index 0e9d6da..8d5fe12 100644 --- a/utill/queues.py +++ b/utill/queues.py @@ -35,7 +35,7 @@ class Queues(): t.daemon=True t.start() def __messagequeue(): - kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("1=1").delete() + kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("code",3).delete() while True: if not Queues.__globalqueue.empty(): value=Queues.__globalqueue.get() @@ -44,14 +44,14 @@ class Queues(): try: value['target'](*value['args']) except Exception as e: - kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":1,"msg":"收到一个异常","error":str(e)}) + kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":1,"msg":"失败","error":str(e)}) else: kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":4,"msg":"执行完成"}) else: try: value['target']() except Exception as e: - kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":1,"msg":"收到一个异常","error":str(e)}) + kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":1,"msg":"失败","error":str(e)}) else: kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("taskid = '"+value['task']['taskid']+"' and code!=4").update({"code":4,"msg":"执行完成"}) else: @@ -80,7 +80,7 @@ class Queues(): kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").insert(task) Queues.__globalqueue.put(key) return taskid - def getall(code=''): + def getall(pagenow=1,pagesize=20,where=None): """获取全部队列 code 1获取失败的任务 2获取等待中的任务 3获取正在执行中的任务 4获取执行完成的任务 @@ -90,15 +90,14 @@ class Queues(): if not os.path.isfile(queuesdbpath): model_kcweb_tasks=model_kcweb_task() model_kcweb_tasks.create_table() - where=False - if code: - where="code="+str(code) try: - return kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").field("taskid,title,describes,code,msg,error,addtime").where(where).select() + lists=kcwsqlite.sqlite().connect(queuesdbpath).where(where).table("model_kcweb_queues").page(pagenow,pagesize).select() + count=kcwsqlite.sqlite().connect(queuesdbpath).where(where).table("model_kcweb_queues").count() + return lists,count except: model_kcweb_tasks=model_kcweb_task() model_kcweb_tasks.create_table() - return [] + return [],0 def status(taskid): """获取任务状态 -- Gitee From 2a6eb98ba15e667ba15adf40885c4b425fa685f2 Mon Sep 17 00:00:00 2001 From: kunkun Date: Fri, 26 Jun 2020 03:41:26 +0800 Subject: [PATCH 33/52] kun --- utill/queues.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utill/queues.py b/utill/queues.py index 8d5fe12..3211e65 100644 --- a/utill/queues.py +++ b/utill/queues.py @@ -35,7 +35,7 @@ class Queues(): t.daemon=True t.start() def __messagequeue(): - kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("code",3).delete() + kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("code",,"in",2,3).delete() while True: if not Queues.__globalqueue.empty(): value=Queues.__globalqueue.get() @@ -91,7 +91,7 @@ class Queues(): model_kcweb_tasks=model_kcweb_task() model_kcweb_tasks.create_table() try: - lists=kcwsqlite.sqlite().connect(queuesdbpath).where(where).table("model_kcweb_queues").page(pagenow,pagesize).select() + lists=kcwsqlite.sqlite().connect(queuesdbpath).where(where).table("model_kcweb_queues").order("id desc").page(pagenow,pagesize).select() count=kcwsqlite.sqlite().connect(queuesdbpath).where(where).table("model_kcweb_queues").count() return lists,count except: @@ -111,7 +111,7 @@ class Queues(): return Boolean """ - if kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("code",3).count(): + if kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("code","in",2,3).count(): return True else: return False -- Gitee From d6b6c90a338f1c3ee262f6106d4b624929fbb688 Mon Sep 17 00:00:00 2001 From: kunkun Date: Fri, 26 Jun 2020 03:47:48 +0800 Subject: [PATCH 34/52] kun --- utill/queues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utill/queues.py b/utill/queues.py index 3211e65..19b2903 100644 --- a/utill/queues.py +++ b/utill/queues.py @@ -35,7 +35,7 @@ class Queues(): t.daemon=True t.start() def __messagequeue(): - kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("code",,"in",2,3).delete() + kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("code","in",2,3).delete() while True: if not Queues.__globalqueue.empty(): value=Queues.__globalqueue.get() -- Gitee From bb06fe87a00b7af84c456fb4ecd513dff1e553bf Mon Sep 17 00:00:00 2001 From: kunkun Date: Sun, 5 Jul 2020 17:30:26 +0800 Subject: [PATCH 35/52] kun --- Events.py | 12 ++++++++---- app.py | 4 ++-- common/autoload.py | 15 +++++++++++---- config/__init__.py | 2 +- setup.py | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Events.py b/Events.py index 4654f28..54f63cf 100644 --- a/Events.py +++ b/Events.py @@ -2,16 +2,20 @@ import os, sys, time, subprocess,signal from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler +eventgtimexz=0 class MyFileSystemEventHander(FileSystemEventHandler): def __init__(self, fn): super(MyFileSystemEventHander, self).__init__() self.restart = fn def on_any_event(self, event): - if event.src_path.endswith('.py'): - print('* 更新文件:%s' % event.src_path) - time.sleep(0.1) - self.restart() + if '.py' in event.src_path and event.src_path.endswith('.py'): + global eventgtimexz + if time.time()-eventgtimexz > 3: + eventgtimexz=time.time() + # print('* 更新文件:%s' % event.src_path) + time.sleep(2) + self.restart() class Events: command = ['echo', 'ok'] process = None diff --git a/app.py b/app.py index d86adf8..20ede5c 100644 --- a/app.py +++ b/app.py @@ -340,7 +340,7 @@ class web: body=web.__tpl( title = status, e=status, - data="无法找到目录:"+str(modular)+"/" + data="路由不存在:"+str(modular)+"/" ) else: try: @@ -350,7 +350,7 @@ class web: body=web.__tpl( title = status, e=status, - data="无法找到目录:"+str(modular)+"/controller/" + data="路由不存在:"+str(modular)+"/controller/" ) else: try: diff --git a/common/autoload.py b/common/autoload.py index d7093f0..92a9c7f 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -438,13 +438,13 @@ class create: else: os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") return False,arr['msg'] - def installplug(self,plug,edition='',token='',cli=False): + def installplug(self,plug,edition='',token='',cli=False,mandatory=False): """创建一个插件,如果您的模块目录下没有插件包,则创建默认插件文件 plug 插件名 """ plug=str(plug) - if os.path.exists(self.appname+"/"+self.modular+"/controller/"+plug): + if os.path.exists(self.appname+"/"+self.modular+"/controller/"+plug) and not mandatory: return False,"该插件已存在" else: http=Http() @@ -515,8 +515,15 @@ class create: # if not a[0]: # shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) # return False,str(a[1]) - f=open(self.appname+"/"+self.modular+"/controller/__init__.py","a",encoding='utf-8') - text="\nfrom . import "+plug + + f=open(self.appname+"/"+self.modular+"/controller/__init__.py","r",encoding='utf-8') + text=f.read() + f.close() + text=re.sub("\nfrom . import "+plug,"",text) + text=re.sub("from . import "+plug,"",text) + + f=open(self.appname+"/"+self.modular+"/controller/__init__.py","w",encoding='utf-8') + text+="\nfrom . import "+plug f.write(text) f.close() return True,"插件安装成功,"+plug+"=="+str(arr['edition']) diff --git a/config/__init__.py b/config/__init__.py index 4baa062..88486c9 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.11.3' #项目版本 +kcweb['version']='4.11.4' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index 821bcec..914821b 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.11.3' #项目版本 +confkcw['version']='4.11.4' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From 85450d59b5bd96aae8c358778703ca4525770f56 Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 8 Jul 2020 09:51:52 +0800 Subject: [PATCH 36/52] kun --- app.py | 2 +- config/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 20ede5c..3eaa571 100644 --- a/app.py +++ b/app.py @@ -79,7 +79,7 @@ class web: port=port, filename=filename ) - else: + elif len(sys.argv)==3 and sys.argv[2]!='--cli': try: RAW_URI=sys.argv[1] except:pass diff --git a/config/__init__.py b/config/__init__.py index 88486c9..6c8cb02 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -90,7 +90,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.11.4' #项目版本 +kcweb['version']='4.11.5' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index 914821b..3d812bf 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.11.4' #项目版本 +confkcw['version']='4.11.5' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From 303805e21ae9f742fc04914d9a7cc36dbbd6a2a8 Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 8 Jul 2020 10:23:29 +0800 Subject: [PATCH 37/52] kun --- config/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/__init__.py b/config/__init__.py index 6c8cb02..0a01684 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -7,6 +7,13 @@ app['before_request']='' #设置请求前执行的函数 app['after_request']='' #设置请求后执行的函数 app['staticpath']='static' app['http_server']='wsgiref' #使用的开发服务器 支持 wsgiref、kcweb、kcweb_server +try: + if sys.argv[2]=='--cli': + app['cli']=True + else: + app['cli']=False +except: + app['cli']=False # redis配置 redis={} redis['host']='127.0.0.1' #服务器地址 -- Gitee From fce738c86035602b63a53983c395ffb212f734b5 Mon Sep 17 00:00:00 2001 From: kunkun Date: Thu, 16 Jul 2020 17:34:30 +0800 Subject: [PATCH 38/52] kun --- common/autoload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/autoload.py b/common/autoload.py index 92a9c7f..0aa6d80 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -215,7 +215,7 @@ def json_decode(strs): try: return json.loads(strs) except Exception: - return {} + return [] def json_encode(strs): """python列表或字典转成字符串""" try: -- Gitee From cd941abb9a1caa5bb67b2666949b75fd5a37775f Mon Sep 17 00:00:00 2001 From: kunkun Date: Sat, 18 Jul 2020 21:36:38 +0800 Subject: [PATCH 39/52] kun --- app.py | 2 +- common/autoload.py | 96 ++++++++++++++++++++++++++++++++++------------ config/__init__.py | 2 +- setup.py | 2 +- 4 files changed, 74 insertions(+), 28 deletions(-) diff --git a/app.py b/app.py index 3eaa571..ed03af0 100644 --- a/app.py +++ b/app.py @@ -79,7 +79,7 @@ class web: port=port, filename=filename ) - elif len(sys.argv)==3 and sys.argv[2]!='--cli': + elif len(sys.argv)==3 and sys.argv[2]=='--cli': try: RAW_URI=sys.argv[1] except:pass diff --git a/common/autoload.py b/common/autoload.py index 92a9c7f..5e6a4d0 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -215,7 +215,7 @@ def json_decode(strs): try: return json.loads(strs) except Exception: - return {} + return [] def json_encode(strs): """python列表或字典转成字符串""" try: @@ -399,24 +399,24 @@ class create: return False,"失败" def uploadplug(self,plug,username='',password='',cli=False): "上传一个插件" + if not os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"): + self.packplug(plug=plug) i=0 http=Http() + http.set_timeout=300 while True: timestamp=times() sign=md5(str(username)+str(timestamp)+md5(md5(password))) - http=Http() http.set_header['username']=username http.set_header['timestamp']=str(timestamp) http.set_header['sign']=sign - http.set_timeout=300 - http.openurl(config.domain['kcwebapi']+"/user/uploadplug/",'POST', - data={'name':str(plug),'describes':'','modular':self.modular}, - files={'file':open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", 'rb')}) + http.openurl(config.domain['kcwebapi']+"/user/userinfo") arr=json_decode(http.get_text) if not arr: os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - print(http.get_text) - return False,"上传失败,服务器暂时无法处理上传" + if config.app['app_debug']: + print(http.get_text) + return False,"用户身份验证失败,服务器暂时无法处理" if (arr['code']==-1 or arr['code']==2) and cli: if i >= 3: os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") @@ -429,15 +429,29 @@ class create: username = input("请输入用户名(手机号)\n") password = input("请输入密码\n") i+=1 - elif arr['code']==-1: - os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - return False,"用户名或密码错误" elif arr['code']==0: - os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - return True,arr['msg'] + break else: os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") return False,arr['msg'] + http.openurl(config.domain['kcwebapi']+"/user/uploadplug/",'POST', + data={'name':str(plug),'describes':'','modular':self.modular}, + files={'file':open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", 'rb')}) + arr=json_decode(http.get_text) + if not arr: + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + if config.app['app_debug']: + print(http.get_text) + return False,"上传失败,服务器暂时无法处理上传" + elif arr['code']==-1 or arr['code']==2: + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + return False,"用户名或密码错误" + elif arr['code']==0: + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + return True,arr['msg'] + else: + os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") + return False,arr['msg'] def installplug(self,plug,edition='',token='',cli=False,mandatory=False): """创建一个插件,如果您的模块目录下没有插件包,则创建默认插件文件 @@ -449,8 +463,10 @@ class create: else: http=Http() i=0 + tplug=plug + modular=self.modular while True: - http.openurl(config.domain['kcwebapi']+"/pub/plug","POST",data={"modular":self.modular,"name":str(plug),"edition":str(edition),"token":token}) + http.openurl(config.domain['kcwebapi']+"/pub/plug","POST",data={"modular":modular,"name":str(tplug),"edition":str(edition),"token":token}) arr=json_decode(http.get_text) if arr: if arr['code']==-1 and cli: @@ -463,7 +479,10 @@ class create: i+=1 elif arr['code']==-1: return False,plug+"插件授权码错误" - elif arr['code']==0: + elif not arr['data']: + modular="api" + tplug="index" #默认插件 + elif arr['code']==0 and arr['data']: arr=arr['data'] r=requests.get(arr['dowurl']) f = open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", "wb") @@ -497,7 +516,8 @@ class create: return False,"error" except AttributeError as e: shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) - print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") + if config.app['app_debug']: + print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") return False,str(e) # try: @@ -554,23 +574,26 @@ class create: return False,"失败" def uploadmodular(self,username='',password='',cli=False): "上传模块" + if not os.path.isfile(self.appname+"/"+self.modular+".zip"): + self.packmodular() i=0 http=Http() + http.set_timeout=300 while True: timestamp=times() sign=md5(str(username)+str(timestamp)+md5(md5(password))) http.set_header['username']=username http.set_header['timestamp']=str(timestamp) http.set_header['sign']=sign - http.set_timeout=300 http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/",'POST', data={'name':str(self.modular),'describes':''}, files={'file':open(self.appname+"/"+self.modular+".zip", 'rb')}) arr=json_decode(http.get_text) if not arr: os.remove(self.appname+"/"+self.modular+".zip") - print(http.get_text) - return False,"上传失败,服务器暂时无法处理上传" + if config.app['app_debug']: + print(http.get_text) + return False,"用户身份验证失败,服务器暂时无法处理" if (arr['code']==-1 or arr['code']==2) and cli: if i >= 3: os.remove(self.appname+"/"+self.modular+".zip") @@ -583,15 +606,33 @@ class create: username = input("请输入用户名(手机号)\n") password = input("请输入密码\n") i+=1 + elif arr['code']==0: + break elif arr['code']==-1: os.remove(self.appname+"/"+self.modular+".zip") return False,"用户名或密码错误" - elif arr['code']==0: - os.remove(self.appname+"/"+self.modular+".zip") - return True,arr['msg'] else: os.remove(self.appname+"/"+self.modular+".zip") return False,arr['msg'] + + http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/",'POST', + data={'name':str(self.modular),'describes':''}, + files={'file':open(self.appname+"/"+self.modular+".zip", 'rb')}) + arr=json_decode(http.get_text) + if not arr: + os.remove(self.appname+"/"+self.modular+".zip") + if config.app['app_debug']: + print(http.get_text) + return False,"上传失败,服务器暂时无法处理上传" + elif arr['code']==-1 or arr['code']==2: + os.remove(self.appname+"/"+self.modular+".zip") + return False,"用户名或密码错误" + elif arr['code']==0: + os.remove(self.appname+"/"+self.modular+".zip") + return True,arr['msg'] + else: + os.remove(self.appname+"/"+self.modular+".zip") + return False,arr['msg'] def installmodular(self,token='',cli=False): "创建模块,如果应用不存,则创建默认应用,如果在您的应用目录下没有模块包,则创建默认模块文件" if not os.path.exists(self.appname): @@ -628,8 +669,9 @@ class create: else: http=Http() i=0 + modular=self.modular while True: - http.openurl(config.domain['kcwebapi']+"/pub/modular","POST",data={"name":self.modular,"token":token}) + http.openurl(config.domain['kcwebapi']+"/pub/modular","POST",data={"name":modular,"token":token}) arr=json_decode(http.get_text) if arr: if arr['code']==-1 and cli: @@ -642,7 +684,9 @@ class create: i+=1 elif arr['code']==-1: return False,self.modular+"模块授权码错误" - elif arr['code']==0: + elif not arr['data']: + modular="api" + elif arr['code']==0 and arr['data']: arr=arr['data'] r=requests.get(arr['dowurl']) f = open(self.appname+"/"+self.modular+".zip", "wb") @@ -676,7 +720,8 @@ class create: return False,"error" except AttributeError as e: shutil.rmtree(self.appname+"/"+self.modular) - print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") + if config.app['app_debug']: + print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") return False,str(e) # try: # m=importlib.import_module(self.appname+'.'+self.modular+'.install') @@ -717,6 +762,7 @@ class create: f.close() return True,"安装成功" else: + return False,"模块下载失败" else: return False,"找不到"+self.modular+"模块" diff --git a/config/__init__.py b/config/__init__.py index 0a01684..e52b882 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -97,7 +97,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.11.5' #项目版本 +kcweb['version']='4.11.6' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index 3d812bf..40d5af0 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.11.5' #项目版本 +confkcw['version']='4.11.6' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From 97370273c7a642a90b2411283935d1dc115bf4fc Mon Sep 17 00:00:00 2001 From: kunkun Date: Sun, 19 Jul 2020 02:24:20 +0800 Subject: [PATCH 40/52] kun --- common/autoload.py | 32 ++++++++++++++++++++++++++++++-- config/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index 5e6a4d0..48fc635 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -541,11 +541,19 @@ class create: f.close() text=re.sub("\nfrom . import "+plug,"",text) text=re.sub("from . import "+plug,"",text) - f=open(self.appname+"/"+self.modular+"/controller/__init__.py","w",encoding='utf-8') text+="\nfrom . import "+plug f.write(text) f.close() + + f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/common/autoload.py","r",encoding='utf-8') + text=f.read() + f.close() + text=re.sub("app.api",self.appname+"."+self.modular,text) + f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/common/autoload.py","w",encoding='utf-8') + f.write(text) + f.close() + return True,"插件安装成功,"+plug+"=="+str(arr['edition']) else: return False,str(plug)+"插件下载失败" @@ -643,7 +651,7 @@ class create: if chunk: f.write(chunk) f.close() - zip.unzip_file("./app.zip","./") + zip.unzip_file("./app.zip","./"+self.appname) os.remove("./app.zip") if not os.path.isfile("./server.py"): if "Windows" in platform.platform(): @@ -660,6 +668,17 @@ class create: f=open("./server.py","w+",encoding='utf-8') f.write(servertext) f.close() + f=open(self.appname+"/common/autoload.py","w",encoding='utf-8') + f.write("from kcweb.common import *\n"+ + "from "+self.appname+" import config\n"+ + "G=globals.G") + f.close() + f=open(self.appname+"/"+self.modular+"/common/autoload.py","w",encoding='utf-8') + f.write("from "+self.appname+".common import *") + f.close() + f=open(self.appname+"/"+self.modular+"/controller/index/common/autoload.py","w",encoding='utf-8') + f.write("from "+self.appname+"."+self.modular+".common import *") + f.close() return True,"应用创建成功" else: if not os.path.isfile(self.appname+"/__init__.py") or not os.path.exists(self.appname+"/common"): @@ -742,6 +761,15 @@ class create: f=open(self.appname+"/__init__.py","a",encoding='utf-8') f.write(content) f.close() + + + f.close() + f=open(self.appname+"/"+self.modular+"/common/autoload.py","w",encoding='utf-8') + f.write("from "+self.appname+".common import *") + f.close() + f=open(self.appname+"/"+self.modular+"/controller/index/common/autoload.py","w",encoding='utf-8') + f.write("from "+self.appname+"."+self.modular+".common import *") + f.close() else: return False,self.modular+"模块下载失败" if not os.path.isfile("./server.py"): diff --git a/config/__init__.py b/config/__init__.py index e52b882..a846d73 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -97,7 +97,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.11.6' #项目版本 +kcweb['version']='4.11.7' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index 40d5af0..8f2c47e 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.11.6' #项目版本 +confkcw['version']='4.11.7' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From 9838470775f3aa4e472a1717b126c81bd6f6c5e0 Mon Sep 17 00:00:00 2001 From: kunkun Date: Sun, 26 Jul 2020 16:41:19 +0800 Subject: [PATCH 41/52] kun --- common/autoload.py | 6 ++---- config/__init__.py | 3 ++- setup.py | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index 48fc635..cb0bebe 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -493,7 +493,6 @@ class create: if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt"): #安装依赖包 install_requires=[] try: @@ -512,14 +511,13 @@ class create: try: install_requires.insert(0,"install") if 0 != pip.main(install_requires): - shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug) return False,"error" except AttributeError as e: - shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug) if config.app['app_debug']: print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") return False,str(e) - # try: # m=importlib.import_module(self.appname+"."+self.modular+"/controller/"+plug+".install") # except: diff --git a/config/__init__.py b/config/__init__.py index a846d73..eef962f 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # 应用配置 +import sys app={} app['app_debug']=True #是否开启调试模式 app['tpl_folder']='./tpl' #设置模板文件目录名 注意:不能配置目录路径 @@ -97,7 +98,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.11.7' #项目版本 +kcweb['version']='4.11.8' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index 8f2c47e..328b102 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.11.7' #项目版本 +confkcw['version']='4.11.8' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From 71ff985173f2b72443a2f11baf564633db66d093 Mon Sep 17 00:00:00 2001 From: kunkun Date: Sun, 23 Aug 2020 23:30:40 +0800 Subject: [PATCH 42/52] kun --- app.py | 59 ++++++--- common/autoload.py | 303 ++++++++++++++++++++++++++++++++++++++++++--- common/globals.py | 2 +- common/request.py | 82 +++++++++++- config/__init__.py | 18 +-- setup.py | 6 +- tpl/err.html | 55 ++++++++ utill/db/mysql.py | 138 ++++++++++++++------- utill/redis.py | 3 + 9 files changed, 570 insertions(+), 96 deletions(-) create mode 100644 tpl/err.html diff --git a/app.py b/app.py index ed03af0..6f9e3c8 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import socket,time,re,os,sys,traceback,threading,urllib +import socket,time,re,os,sys,traceback,threading,urllib,cgi from . Events import Events from . common import * from . import config @@ -9,6 +9,7 @@ from threading import local from .utill import filetype from kcweb.utill.cache import cache as kcwcache from wsgiref.simple_server import make_server +from kcweb.utill.db import mysql as kcwmysql class web: __name=None __appname=None @@ -18,10 +19,6 @@ class web: self.__appname=appname if self.__name != '__main__': def apps(env, start_response): - try: - env['BODY_DATA']=str(env['wsgi.input'].next(), encoding = "utf-8") - except: - env['BODY_DATA']="" p=(config.app['staticpath']+env['RAW_URI'].replace(' ','')) status='200 ok' if os.path.isfile(p): @@ -43,6 +40,21 @@ class web: ("Accept-Ranges","bytes"), ] else: + files=None + try: + CONTENT_TYPE=env['CONTENT_TYPE'] + except: + pass + else: + if 'multipart/form-data; boundary' in CONTENT_TYPE:#上传文件 + files = cgi.FieldStorage(fp=env['wsgi.input'], environ=env, keep_blank_values=True) + else: + files=None + env['files']=files + try: + env['BODY_DATA']=str(env['wsgi.input'].next(), encoding = "utf-8") + except: + env['BODY_DATA']="" status,resheader,body=self.__routes(self,env) if type(body) is bytes: pass @@ -190,7 +202,7 @@ class web: routedefault=route['default'] methods=route['methods'] if routedefault: - plug='index' + plug=route['defplug'] files=route['files'] funct=route['funct'] else: @@ -283,6 +295,8 @@ class web: param.append(urllib.parse.unquote(path)) i+=1 #默认路由end ############################################################ + if not modular: + modular=route['defmodular'] return methods,modular,plug,files,funct,tuple(param) def __tran(self,data,status,resheader): "转换控制器返回的内容" @@ -313,6 +327,10 @@ class web: globals.HEADER.SERVER_PROTOCOL=header['SERVER_PROTOCOL'] globals.HEADER.HTTP_HOST=header['HTTP_HOST'] globals.HEADER.BODY_DATA=header['BODY_DATA'] + try: + globals.HEADER.files=header['files'] + except: + globals.HEADER.files=None try: globals.HEADER.HTTP_COOKIE=header['HTTP_COOKIE'] except: @@ -545,6 +563,12 @@ class web: for key in resheader: resheaders.append((key,resheader[key])) web.__del_globals() + + #关闭数据库连接 + dbs=kcwmysql.mysql() + dbs.close() + + if isinstance(resheaders,list): if not body: body='' @@ -566,19 +590,19 @@ class web: def __application(self,env, start_response): # print(env) try: - request_body_size = int(env.get('CONTENT_LENGTH', 0)) + request_body_size = int(env.get('CONTENT_LENGTH', '0')) except (ValueError): request_body_size = 0 - BODY_DATA=env['wsgi.input'].read(request_body_size) - if 'multipart/form-data; boundary' in env['CONTENT_TYPE']: - BODY_DATA=BODY_DATA.decode("ISO-8859-1") - env['BODY_DATA']=BODY_DATA - # lists=BODY_DATA.split("\r\n") - # BODY_DATA=re.sub(lists[0],'',BODY_DATA) - # BODY_DATA=re.sub(lists[1],'',BODY_DATA) - # BODY_DATA=re.sub(lists[2],'',BODY_DATA) - # BODY_DATA=re.sub(lists[len(lists)-2],'',BODY_DATA) + if 'multipart/form-data; boundary' in env['CONTENT_TYPE']:#上传文件 + files = cgi.FieldStorage(fp=env['wsgi.input'], environ=env, keep_blank_values=True) + # open(form["file"].filename, 'wb').write(form["file"].value) + # print(files["file"].name) + # print(files["name"].filename) + # print(files["name"].value) + env['BODY_DATA']=None else: + files=None + BODY_DATA=env['wsgi.input'].read(request_body_size) env['BODY_DATA']=BODY_DATA.decode() env['RAW_URI']=env['PATH_INFO'] if env.get('QUERY_STRING'): @@ -609,7 +633,8 @@ class web: 'HTTP_COOKIE':env['HTTP_COOKIE'], 'REMOTE_ADDR':env['REMOTE_ADDR'], 'HTTP_USER_AGENT':env['HTTP_USER_AGENT'], - 'BODY_DATA':env['BODY_DATA'] + 'BODY_DATA':env['BODY_DATA'], + 'files':files } p=(config.app['staticpath']+reqheader['RAW_URI'].replace(' ','')) status='200 ok' diff --git a/common/autoload.py b/common/autoload.py index cb0bebe..46460b5 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import time,hashlib,json,re,os,platform,sys,shutil,zipfile,requests,importlib,traceback,pip +import time,hashlib,json,re,os,platform,sys,shutil,requests,importlib,traceback,pip,gzip,tarfile,zipfile,random import datetime as core_datetime from kcweb import config from kcweb.utill.dateutil.relativedelta import relativedelta as core_relativedelta @@ -15,7 +15,222 @@ from mako.template import Template as kcwTemplate import smtplib from email.mime.text import MIMEText from email.utils import formataddr +from kcweb.utill import filetype from . import globals + +import asyncio,websockets,urllib,threading +class kcwebsocket: + "websocket服务端" + __clientlists=[] #所有客户端绑定的对象 + __lists=[] #所有客户端 + __group={} #组 + __uid={} #clientid绑定的uid + async def bindUid(self,clientid,uid): + """将clientid与uid绑定,以便通过sendToUid(uid)发送数据 + + clientid 客户端id + + uid uid与client_id是一对多的关系,系统允许一个uid下有多个client_id + """ + try: + self.__uid[uid] + except KeyError: + self.__uid[uid]=[] + self.__uid[uid].append(clientid) + def unbindUid(self,clientid,uid): + """将clientid与uid解绑 当clientid下线(连接断开)时会自动与uid解绑,开发者无需在onClose事件调用unbindUid + + clientid 客户端id + + uid 数字或者字符串 + """ + try: + self.__uid[uid] + except KeyError: + pass + else: + try: + self.__uid[uid].remove(clientid) + except KeyError: + pass + async def sendToUid(self,uid,message): + """向uid绑定的所有在线clientid发送数据 + + uid uid可以是字符串、数字、或者包含uid的列表。如果为列表,则是给列表内所有uid发送数据 + + message 要发送的数据(字符串类型) + """ + if isinstance(uid,str): + for clientid in self.__uid[uid]: + await self.send_client(clientid,message) + elif isinstance(uid,list): + for k in uid: + for clientid in self.__uid[k ]: + try: + await self.send_client(clientid,message) + except ValueError: + if config.app['app_debug']: + print("deluid",clientid) + self.__uid[uid].remove(clientid) + async def joinGroup(self,clientid,group): + """将clientid加入某个组 + + clientid 客户端id + + Group 组名 + """ + try: + self.__group[group] + except KeyError: + self.__group[group]=[] + self.__group[group].append(clientid) + async def leaveGroup(self,clientid,group): + """将clientid从某个组中删除 + + clientid 客户端id + + group 组名 + """ + try: + self.__group[group] + except KeyError: + pass + else: + try: + self.__group[group].remove(clientid) + except KeyError: + pass + async def ungroup(self,group): + """解散分组。 解散分组后所有属于这个分组的用户的连接将被移出分组,此分组将不再存在,除非再次调用 joinGroup + + group 组名 + """ + try: + self.__group[group] + except KeyError: + pass + else: + del self.__group[group] + async def sendToGroup(self,group,message,exclude_clientid=[]): + """向某个分组的所有在线clientid发送数据。 + + group 组名 + + message 要发送的数据(字符串类型) + + exclude_clientid clientid组成的列表。exclude_clientid列表中指定的clientid将被排除在外,不会收到本次发的消息 + """ + try: + self.__group[group] + except KeyError: + pass + else: + for client in self.__group[group]: + if exclude_clientid: + for clientid in exclude_clientid: + if client!=clientid: + try: + await self.send_client(client,message) + except ValueError: + if config.app['app_debug']: + print("delgroup",client) + self.__group[group].remove(client) + else: + try: + await self.send_client(client,message) + except ValueError: + if config.app['app_debug']: + print("delgroup",client) + self.__group[group].remove(client) + async def getClientIdCountByGroup(self,group): + """获取某分组当前在线成连接数(多少clientid在线) + + group 组名 + + return int 返回一个数字 + """ + try: + self.__group[group] + except KeyError: + return 0 + else: + return len(self.__group[group]) + def getAllClientIdCount(self): + """获取当前在线连接总数(多少client_id在线) + + return int 返回一个数字 + """ + return len(self.__lists) + async def send_all(self,message): + "给所有人发送消息,包括自己" + for l in self.__clientlists: + try: + await l['socket'].send(message) + except:pass + async def send_client(self,clientid,message): + "给所指定客户端发送消息" + xb=self.__lists.index(clientid) + websockets=self.__clientlists[xb]['socket'] + try: + await websockets.send(message) + except:pass + async def onConnect(self,clientid,params): + "客户端发来连接时" + if config.app['app_debug']: + print("连接成功",clientid) + async def onMessage(self,clientid,recv_text): + "当客户端发来数据" + await self.send_client(clientid,recv_text) #给当前用户发送消息 + async def onClose(self,clientid): + "客户端与websocket的连接断开时触发" + if config.app['app_debug']: + print("onClose",clientid) + async def __onClose(self,clientid): + xb=self.__lists.index(clientid) + del self.__lists[xb] + del self.__clientlists[xb] + if self.__uid: + for uid in self.__uid.keys(): + try: + self.__uid[uid] + except KeyError: + pass + else: + try: + self.__uid[uid]['clientid'] + except KeyError: + pass + else: + self.__uid[uid].remove(clientid) + async def __main2(self,clientid,websocket,path): + "服务器端主逻辑" + async for message in websocket: + await self.onMessage(clientid, message) + await self.__onClose(clientid) + await self.onClose(clientid) + async def __main1(self,clientid,websocket,path): + t = urllib.parse.parse_qs(urllib.parse.urlparse(path).query) + params={} + for key in t.keys(): + params[key]=t[key][0] + await self.onConnect(clientid, params) + async def __main(self,websocket,path): + "服务器端主逻辑" + clientid=md5(str(random.random())) + self.__clientlists.append({"clientid":clientid,"socket":websocket}) + self.__lists.append(clientid) + task1=asyncio.ensure_future(self.__main1(clientid,websocket,path)) + task2=asyncio.ensure_future(self.__main2(clientid,websocket,path)) + await task1 + await task2 + def start(self,ip='0.0.0.0',port='39020'): + "启动websoeket服务" + asyncio.set_event_loop(asyncio.new_event_loop()) # 防止出现RuntimeError + asyncio.get_event_loop().run_until_complete(websockets.serve(self.__main,ip,port)) + asyncio.get_event_loop().run_forever() +# def start(): +# kwebsocket=kcwebsocket() +# kwebsocket.start() redis=kcwredis() def send_mail(user,text="邮件内容",theme="邮件主题",recNick="收件人昵称"): """发送邮件 @@ -316,27 +531,51 @@ def list_to_tree(data, pk = 'id', pid = 'pid', child = 'lowerlist', root=0,child class zip: - def packzip(dirname,zipfilename): + def packzip(src,dst): + "压缩" filelist = [] - if os.path.isfile(dirname): - filelist.append(dirname) - for root, dirs, files in os.walk(dirname): + if os.path.isfile(src): + filelist.append(src) + for root, dirs, files in os.walk(src): for name in files: filelist.append(os.path.join(root, name)) - zf = zipfile.ZipFile(zipfilename, "w", zipfile.zlib.DEFLATED) + zf = zipfile.ZipFile(dst, "w", zipfile.zlib.DEFLATED) for tar in filelist: - arcname = tar[len(dirname):] + arcname = tar[len(src):] zf.write(tar,arcname) zf.close() - def unzip_file(zipfilename, unziptodir): - zf = zipfile.ZipFile(zipfilename) - zf.extractall(unziptodir) + def unzip_file(dst, src): + "解压" + zf = zipfile.ZipFile(dst) + zf.extractall(src) zf.close() - - +class kcwtar: + def targz(src,dst): + """ + 打包目录为tar.gz + :param src: 需要打包的目录 + :param dst: 压缩文件名 + :return: bool + """ + with tarfile.open(dst, "w:gz") as tar: + tar.add(src, arcname=os.path.basename(src)) + return True + def untar(dst, src): + """ + 解压tar.gz文件 + :param dst: 压缩文件名 + :param src: 解压后的存放路径 + :return: bool + """ + try: + t = tarfile.open(dst) + t.extractall(path = src) + return True + except Exception as e: + return False class response: - def tpl(path=None,**context): + def tpl(path=None,status='200 ok',header={"Content-Type":"text/html; charset=utf-8"},**context): "返回模板内容" getroutecomponent=globals.VAR.component if path: @@ -346,10 +585,41 @@ class response: Temppath="/"+getroutecomponent[1]+"/controller/"+getroutecomponent[2]+"/tpl/"+path+".html" else: Temppath="/"+getroutecomponent[1]+"/controller/"+getroutecomponent[2]+"/tpl/"+getroutecomponent[3]+"/"+getroutecomponent[4]+".html" - return Template(Temppath,config=config,**context) - def json(res=[],status='200 ok'): + return Template(Temppath,config=config,**context),status,header + def json(res=[],status='200 ok',header={"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"}): "响应json内容" - return json_encode(res),status,{"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"} + return json_encode(res),status,header + def pic(body): + """输出图片 + + body 图片二进制内容或图片路径 + """ + if isinstance(body,str): + filename=body + f=open(filename,"rb") + body=f.read() + f.close() + kind = filetype.guess(filename) + ContentType=kind.mime + else: + ContentType="image/png" + return body,'200 ok',{"Content-Type":ContentType,"Cache-Control":"public, max-age=60"} + def download(pathname): + """下载文件 + + pathname 文件路径 + """ + if os.path.isfile(pathname): + f=open(pathname,"rb") + body=f.read() + f.close() + kind = filetype.guess(pathname) + try: + return body,"200 ok",{"Content-Type":"application/"+kind.mime,"Accept-Ranges":"bytes"} + except: + return body,"200 ok",{"Content-Type":"application/text","Accept-Ranges":"bytes"} + else: + return Templates('E:\doc\python\kcwebplus\kcweb/tpl/err.html',title="文件不存在",content="文件不存在",imgsrc=config.domain['kcwebimg']+"/icon/error.png",config=config) def redirect(url,status="302 Found",html='',header={"Content-Type":"application/html; charset=utf-8"}): """重定向 @@ -363,7 +633,6 @@ class response: """ header['Location']=url return html,status,header - class create: appname=None modular=None diff --git a/common/globals.py b/common/globals.py index 64ee2a0..ea553f0 100644 --- a/common/globals.py +++ b/common/globals.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from threading import local -##普通全局变量 请求结束后面删除 +##普通全局变量 请求结束后删除 VAR = local() HEADER = local() G = local() diff --git a/common/request.py b/common/request.py index 46245e0..3468bdf 100644 --- a/common/request.py +++ b/common/request.py @@ -5,23 +5,101 @@ import json class args: "获取url" def get(name): + """获取键值对 + + name 键 + + return 值 + """ params = parse.parse_qs(parse.urlparse(kcwglobals.HEADER.URL).query) try: k=params[name][0] except: k=None return k + def get_json(): + """获取 json get内容 + + return json内容 + """ + try: + lists=kcwglobals.HEADER.URL.split("?")[1] + lists=lists.split("&") + data={} + for k in lists: + ar=k.split("=") + data[ar[0]]=ar[1] + return data + except:return None class froms: - "获取from" + "获取from application/x-www-form-urlencoded 的post内容" def get(name): + """获取键值对 + + name 键 + + return 值 + """ data=kcwglobals.HEADER.BODY_DATA params = parse.parse_qs(parse.urlparse("?"+str(data)).query) - # print(params) try: k=parse.unquote(params[name][0]) except: k=None return k + def get_json(): + """获取post json post内容 + + return json内容 + """ + try: + lists=kcwglobals.HEADER.BODY_DATA.split("&") + data={} + for k in lists: + ar=k.split("=") + data[ar[0]]=ar[1] + return data + except:return None +class binary: + "二进制或文件处理" + def get(name): + """获取文件二进制 + + name 文件标识 + + return 文件二进制 + """ + return kcwglobals.HEADER.files[name].value + def filename(name): + """获取文件名,上传文件时有效,其他情况返回空 + + name 文件标识 + + return 文件名 + """ + return kcwglobals.HEADER.files[name].filename + def filesuffix(name): + """获取文件后缀,上传文件时有效,其他情况返回空 + + name 文件标识 + + return 文件名 + """ + return kcwglobals.HEADER.files[name].filename.split('.')[-1] + def save(name,filename): + """保存二进制文件 + + name 文件标识 + + filename 文件位置 + + return 完整文件名 + """ + if kcwglobals.HEADER.files[name].value: + open(filename, 'wb').write(kcwglobals.HEADER.files[name].value) + return filename + else: + return None class HEADER: def Method(): return kcwglobals.HEADER.Method diff --git a/config/__init__.py b/config/__init__.py index eef962f..8734767 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -56,8 +56,8 @@ database['user']=['root'] #用户名 [用户名1,用户名2,用户名3...] database['password']=['root'] #密码 [密码1,密码2,密码3...] database['db']=['test'] #数据库名 [数据库名1,数据库名2,数据库名3...] database['charset']='utf8' #数据库编码默认采用utf8 -database['pattern']=False # True数据库长连接模式 False数据库短连接模式 注:建议web应用使用短连接,cli应用使用长连接 -database['cli']=False # 是否以cli方式运行 +database['pattern']=False # True数据库长连接模式 False数据库短连接模式 注:建议web应用有效,cli应用方式下,如果长时间运行建议使用mysql().close()关闭 +database['cli']=app['cli'] # 是否以cli方式运行 database['dbObjcount']=1 # 连接池数量(单个数据库地址链接数量),数据库链接实例数量 mysql长链接模式下有效 database['deploy']=0 # 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) mysql数据库有效 database['master_num']=1 #主服务器数量 不能超过host服务器数量 (等于服务器数量表示读写不分离:主主复制。 小于服务器表示读写分离:主从复制。) mysql数据库有效 @@ -81,11 +81,13 @@ mongo['retryWrites']=False #是否支持重新写入 #路由配置 route={} -route['default']=True -route['modular']='' -route['plug']='' -route['files']='index' #默认路由文件 -route['funct']='index' #默认路由函数 +route['default']=True #是否开启默认路由 默认路由开启后面不影响以下配置的路由,模块名/版本名/控制器文件名/方法名 作为路由地址 如:http://www.kcw.com/modular/plug/index/index/ +route['modular']='' #指定访问配置固定模块 (如果配置了该值,将无法通过改变url访问不同模块) +route['plug']='' #指定访问固定插件 (如果配置了该值,将无法通过改变url访问不同插件) +route['defmodular']='index' #默认模块 当url不包括模块名时 +route['defplug']='index' #默认插件 当url不包括插件名时 +route['files']='index' #默认路由文件(控制器) 当url不包括控制器名时 +route['funct']='index' #默认路由函数 (操作方法) 当url不包括操作方法名时 route['methods']=['POST','GET'] #默认请求方式 route['children']=[] #email配置 @@ -98,7 +100,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.11.8' #项目版本 +kcweb['version']='4.11.9' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index 328b102..556d8b2 100644 --- a/setup.py +++ b/setup.py @@ -16,9 +16,9 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.11.8' #项目版本 +confkcw['version']='4.12.0' #项目版本 confkcw['description']='' #项目的简单描述 -confkcw['long_description']="" #项目详细描述 +confkcw['long_description']="增加websocket" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 confkcw['url']='' confkcw['author']='禄可集团-坤坤' #名字 @@ -52,7 +52,7 @@ setup( url=confkcw['url'], packages = b, # data_files=[('Scripts', ['kcweb/bin/kcw.exe'])], - install_requires = ['pymongo>=3.10.0','Mako>=1.1.2','requests>=2.23.0','six>=1.12.0','watchdog>=0.9.0'], #第三方包 + install_requires = ['pymongo>=3.10.0','Mako>=1.1.2','requests>=2.23.0','six>=1.12.0','watchdog>=0.9.0','websockets==8.1'], #第三方包 package_data = { '': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'], } diff --git a/tpl/err.html b/tpl/err.html new file mode 100644 index 0000000..2cfaad4 --- /dev/null +++ b/tpl/err.html @@ -0,0 +1,55 @@ + + + + +${title} + + + + + + + + + + + + + +
+
+ +
+ + + + ${content}
+
+ +
+ + + diff --git a/utill/db/mysql.py b/utill/db/mysql.py index 3235a9a..52f1f8d 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -8,6 +8,7 @@ class mysql: """数据库实例""" __config=dbconfig __conn={} #数据库链接对象 + __connlists=[] #短连接列表 用于关闭 __cursor=None #游标对象 __errorcount=dbconfig['break'] #允许最大链接错误次数 __errorcounts=0 #默认链接错误次数 @@ -17,21 +18,43 @@ class mysql: __masteridentifier='' # 主服务器标识 __slaveidentifier='' # 从服务器标识 def __del__(self): - if not self.__config['pattern'] and self.__conn: - if isinstance(self.__conn,dict): + pass + def close(self): + "关闭连接,该方法无需理会,框架自动完成" + if not self.__config['pattern'] and mysql.__conn: + if self.__connlists: + for k in self.__connlists: + try: + mysql.__conn[k].close() + except Exception as e: + if self.__config['debug']: + print("mysql短连接关闭失败",str(e),k) + else: + if self.__config['debug']: + print("mysql短连接关闭成功",k) + mysql.__connlists=[] + mysql.__conn={} + elif isinstance(mysql.__conn,dict): i=0 for thost in self.__config['host']: identifier=thost+str(self.__config['port'][i])+self.__config['user'][i]+self.__config['password'][i]+self.__config['db'][i] - for k in self.__conn[identifier]: + print(mysql.__conn) + for k in mysql.__conn[identifier]: try: k['obj'].close() + if self.__config['debug']: + print("mysql短连接已关闭",k) except Exception as e: - print(k,"连接关闭失败",str(e)) + if self.__config['debug']: + print("mysql短连接关闭失败",str(e),k) i+=1 - self.__conn={} - elif isinstance(self.__conn,object): - self.__conn.close() - self.__conn={} + mysql.__conn={} + self.__connlists=[] + elif isinstance(mysql.__conn,object): + mysql.__conn[self.__masteridentifier].close() + mysql.__conn={} + if self.__config['debug']: + print("mysql短连接已关闭",mysql.__conn) __dbcount=1 def __setdbcount(self): "设置数据库配置总数量" @@ -61,10 +84,10 @@ class mysql: try: k['obj'].close() if self.__config['debug']: - print(k,"关闭成功") + print("mysql长连接关闭成功",k) except Exception as e: if self.__config['debug']: - print(k,"连接关闭失败",str(e)) + print(k,"mysql长连接关闭失败",str(e)) mysql.__conn[identifier]=[] __dbobjident=None #集中式(单一服务器)并且长连接模式下随机服务器链接标识 和 分布式(主从服务器)模式下随机服务器链接标识 def __connects(self,typess="DQL"): @@ -88,7 +111,14 @@ class mysql: if self.__config['debug']: print("第%s次创建数据库链接对象,长连接模式" % (self.__errorcounts+1)) else: - mysql.__conn=connect(host=self.__config['host'][0], port=self.__config['port'][0], user=self.__config['user'][0], password=self.__config['password'][0], db=self.__config['db'][0], charset=self.__config['charset']) + self.__masteridentifier=self.__config['host'][0]+str(self.__config['port'][0])+self.__config['user'][0]+self.__config['password'][0]+self.__config['db'][0] # 服务器标识 + try: + mysql.__conn[self.__masteridentifier] + except KeyError: # 铺获未知异常 + mysql.__conn[self.__masteridentifier]=connect(host=self.__config['host'][0], port=self.__config['port'][0], user=self.__config['user'][0], password=self.__config['password'][0], db=self.__config['db'][0], charset=self.__config['charset']) + self.__connlists.append(self.__masteridentifier) + if self.__config['debug']: + print("mysql短连接已创建",self.__masteridentifier,mysql.__conn[self.__masteridentifier]) elif self.__config['deploy']==1: # 分布式(主从服务器) if self.__config['pattern']: # 长连接情况下 j=0 @@ -114,7 +144,7 @@ class mysql: j=j+1 mysql.__conn[self.__masteridentifier]=masterlistsdb if self.__config['debug']: - print("次创建数据库链接对象,长连接模式(主)" % (self.__errorcounts+1)) + print("%d次创建数据库链接对象,长连接模式(主)" % (self.__errorcounts+1)) if self.__slaveidentifier not in mysql.__conn or len(mysql.__conn[self.__slaveidentifier]) Date: Tue, 25 Aug 2020 04:18:10 +0800 Subject: [PATCH 43/52] kun --- Events.py | 3 ++- app.py | 55 ++++++++++++++++++++++++++++++++-------------- common/autoload.py | 24 ++++++++++---------- config/__init__.py | 1 + setup.py | 2 +- utill/db/mysql.py | 24 +++++++++++++------- utill/http.py | 4 ++-- 7 files changed, 72 insertions(+), 41 deletions(-) diff --git a/Events.py b/Events.py index 54f63cf..c52d4ef 100644 --- a/Events.py +++ b/Events.py @@ -14,7 +14,8 @@ class MyFileSystemEventHander(FileSystemEventHandler): if time.time()-eventgtimexz > 3: eventgtimexz=time.time() # print('* 更新文件:%s' % event.src_path) - time.sleep(2) + # time.sleep(2) + time.sleep(0.2) self.restart() class Events: command = ['echo', 'ok'] diff --git a/app.py b/app.py index 6f9e3c8..c80d618 100644 --- a/app.py +++ b/app.py @@ -145,19 +145,7 @@ class web: ) except KeyboardInterrupt: pass - def __get_modular(self,header): - "获取模块" - modular='' - route=self.__config.route - if route['modular']: - if isinstance(route['modular'],str): - modular=route['modular'] - else: - HTTP_HOST=header['HTTP_HOST'].split(".")[0] - for mk in route['modular']: - if HTTP_HOST in mk: - modular=mk[HTTP_HOST] - return modular + def __getconfigroute(self,PATH_INFO,header): "使用配置路由" route=self.__config.route @@ -195,10 +183,38 @@ class web: break except:pass return routedefault,PATH_INFO + def __get_modular(self,header): + "获取模块" + modular='' + route=self.__config.route + if route['modular']: + if isinstance(route['modular'],str): + modular=route['modular'] + else: + HTTP_HOST=header['HTTP_HOST'].split(".")[0] + for mk in route['modular']: + if HTTP_HOST in mk: + modular=mk[HTTP_HOST] + return modular + def __get_plug(self,header): + "获取插件" + plug='' + route=self.__config.route + if route['plug']: + if isinstance(route['plug'],str): + plug=route['plug'] + else: + HTTP_HOST=header['HTTP_HOST'].split(".")[0] + for mk in route['plug']: + if HTTP_HOST in mk: + plug=mk[HTTP_HOST] + return plug def defaultroute(self,header,PATH_INFO): "路由匹配" route=self.__config.route modular=web.__get_modular(self,header) + if route['plug']: + getplug=web.__get_plug(self,header) routedefault=route['default'] methods=route['methods'] if routedefault: @@ -216,8 +232,10 @@ class web: ##默认路由start ################################################################################# if modular: - if route['plug']: #匹配模块并且匹配了插件 - plug=route['plug'] + # if route['plug']: #匹配模块并且匹配了插件 + # plug=route['plug'] + if getplug: + plug=getplug routedefault,PATH_INFO=web.__getconfigroute( self, PATH_INFO, @@ -255,8 +273,10 @@ class web: else: param.append(urllib.parse.unquote(path)) i+=1 - elif route['plug']: #配置版本的但没有匹配插件 - plug=route['plug'] + # elif route['plug']: #配置模块但没有匹配插件 + # plug=route['plug'] + elif getplug: + plug=getplug routedefault,PATH_INFO=web.__getconfigroute( self, PATH_INFO, @@ -297,6 +317,7 @@ class web: #默认路由end ############################################################ if not modular: modular=route['defmodular'] + return methods,modular,plug,files,funct,tuple(param) def __tran(self,data,status,resheader): "转换控制器返回的内容" diff --git a/common/autoload.py b/common/autoload.py index 46460b5..0a71c0c 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -676,10 +676,10 @@ class create: while True: timestamp=times() sign=md5(str(username)+str(timestamp)+md5(md5(password))) - http.set_header['username']=username - http.set_header['timestamp']=str(timestamp) - http.set_header['sign']=sign - http.openurl(config.domain['kcwebapi']+"/user/userinfo") + # http.set_header['username']=username + # http.set_header['timestamp']=str(timestamp) + # http.set_header['sign']=sign + http.openurl(config.domain['kcwebapi']+"/user/userinfo/?username="+username+"×tamp="+str(timestamp)+"&sign="+sign) arr=json_decode(http.get_text) if not arr: os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") @@ -703,7 +703,7 @@ class create: else: os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") return False,arr['msg'] - http.openurl(config.domain['kcwebapi']+"/user/uploadplug/",'POST', + http.openurl(config.domain['kcwebapi']+"/user/uploadplug/?username="+username+"×tamp="+str(timestamp)+"&sign="+sign,'POST', data={'name':str(plug),'describes':'','modular':self.modular}, files={'file':open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", 'rb')}) arr=json_decode(http.get_text) @@ -735,7 +735,7 @@ class create: tplug=plug modular=self.modular while True: - http.openurl(config.domain['kcwebapi']+"/pub/plug","POST",data={"modular":modular,"name":str(tplug),"edition":str(edition),"token":token}) + http.openurl(config.domain['kcwebapi']+"/pub/plug","GET",params={"modular":modular,"name":str(tplug),"edition":str(edition),"token":token}) arr=json_decode(http.get_text) if arr: if arr['code']==-1 and cli: @@ -857,10 +857,10 @@ class create: while True: timestamp=times() sign=md5(str(username)+str(timestamp)+md5(md5(password))) - http.set_header['username']=username - http.set_header['timestamp']=str(timestamp) - http.set_header['sign']=sign - http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/",'POST', + # http.set_header['username']=username + # http.set_header['timestamp']=str(timestamp) + # http.set_header['sign']=sign + http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/?username="+username+"×tamp="+str(timestamp)+"&sign="+sign,'POST', data={'name':str(self.modular),'describes':''}, files={'file':open(self.appname+"/"+self.modular+".zip", 'rb')}) arr=json_decode(http.get_text) @@ -890,7 +890,7 @@ class create: os.remove(self.appname+"/"+self.modular+".zip") return False,arr['msg'] - http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/",'POST', + http.openurl(config.domain['kcwebapi']+"/user/uploadmodular/?username="+username+"×tamp="+str(timestamp)+"&sign="+sign,'POST', data={'name':str(self.modular),'describes':''}, files={'file':open(self.appname+"/"+self.modular+".zip", 'rb')}) arr=json_decode(http.get_text) @@ -957,7 +957,7 @@ class create: i=0 modular=self.modular while True: - http.openurl(config.domain['kcwebapi']+"/pub/modular","POST",data={"name":modular,"token":token}) + http.openurl(config.domain['kcwebapi']+"/pub/modular","POST",params={"name":modular,"token":token}) arr=json_decode(http.get_text) if arr: if arr['code']==-1 and cli: diff --git a/config/__init__.py b/config/__init__.py index 8734767..62f0f7c 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -117,6 +117,7 @@ domain['kcwebfile']="https://file.kwebapp.cn" domain['kcwebstatic']="https://static.kwebapp.cn" domain['kcwebimg']="https://img.kwebapp.cn" domain['kcwebapi']="https://kcweb.kwebapp.cn" +# domain['kcwebapi']="http://www.kwebapp.cn" #其他配置 other={} diff --git a/setup.py b/setup.py index 556d8b2..b9e9dca 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.12.0' #项目版本 +confkcw['version']='4.12.1' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="增加websocket" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 diff --git a/utill/db/mysql.py b/utill/db/mysql.py index 52f1f8d..9374dca 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -550,8 +550,11 @@ class mysql: self.__execute() result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() - cou=int(result[0][0]) - return cou + if len(result)>1: + return len(result) + else: + cou=int(result[0][0]) + return cou def max(self,field): """查询某字段的最大值 @@ -761,6 +764,9 @@ class mysql: 参数 length:int 查询数量 """ + offset=int(offset) + if length: + length=int(length) self.__limit=[offset,length] return self def page(self,pagenow=1, length = 20): @@ -770,6 +776,8 @@ class mysql: 参数 length:int 查询数量 """ + pagenow=int(pagenow) + length=int(length) offset=(pagenow-1)*length self.__limit=[offset,length] return self @@ -961,6 +969,12 @@ class mysql: self.__sql=self.__sql + " WHERE %s" % self.__listTrans() else: print("参数where类型错误") + if self.__group: + s=self.__group + if self.__group1: + for key in self.__group1: + s=s+","+key + self.__sql=self.__sql+" GROUP BY "+s if self.__order: s='' if isinstance(self.__order,list): @@ -994,12 +1008,6 @@ class mysql: else: s=self.__order self.__sql=self.__sql+" ORDER BY "+s - if self.__group: - s=self.__group - if self.__group1: - for key in self.__group1: - s=s+","+key - self.__sql=self.__sql+" GROUP BY "+s if self.__having: self.__sql=self.__sql+" HAVING "+self.__having if self.__limit: diff --git a/utill/http.py b/utill/http.py index 05ffb60..762f237 100644 --- a/utill/http.py +++ b/utill/http.py @@ -25,7 +25,7 @@ class Http: def gettext(self): """得到响应text""" return self.get_text - def openurl(self,url,method="GET",data=None,files=None,allow_redirects=True): + def openurl(self,url,method="GET",data=None,params=None,files=None,allow_redirects=True): """模拟浏览器请求 url : 目标地址 @@ -48,7 +48,7 @@ class Http: self.req = requests if self.set_cookies and isinstance(self.set_cookies,str): self.cookieserTdict() - response=self.req.request(method, url,data=data,files=files,proxies=self.set_proxies,cookies=self.set_cookies,headers=self.set_header,timeout=self.set_timeout,verify=self.set_verify,allow_redirects=allow_redirects) + response=self.req.request(method, url,data=data,params=params,files=files,proxies=self.set_proxies,cookies=self.set_cookies,headers=self.set_header,timeout=self.set_timeout,verify=self.set_verify,allow_redirects=allow_redirects) response.encoding=self.set_encoding self.get_header=dict(response.headers) cookie=requests.utils.dict_from_cookiejar(response.cookies) -- Gitee From e0978c5de864cee4bafc697803934479efc07fa8 Mon Sep 17 00:00:00 2001 From: kunkun Date: Tue, 25 Aug 2020 04:41:26 +0800 Subject: [PATCH 44/52] kun --- app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.py b/app.py index c80d618..9615abe 100644 --- a/app.py +++ b/app.py @@ -215,6 +215,8 @@ class web: modular=web.__get_modular(self,header) if route['plug']: getplug=web.__get_plug(self,header) + else: + getplug='' routedefault=route['default'] methods=route['methods'] if routedefault: -- Gitee From 84c4c48386242d23458c1110755f260f4d5d7ede Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 2 Sep 2020 21:42:49 +0800 Subject: [PATCH 45/52] kun --- app.py | 3 + config/__init__.py | 4 +- utill/db/mysql.py | 29 +- utill/db/sqlite copy.py | 685 ++++++++++++++++++++++++++++++++++++++++ utill/queues.py | 1 + 5 files changed, 715 insertions(+), 7 deletions(-) create mode 100644 utill/db/sqlite copy.py diff --git a/app.py b/app.py index 9615abe..65e7359 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,7 @@ from .utill import filetype from kcweb.utill.cache import cache as kcwcache from wsgiref.simple_server import make_server from kcweb.utill.db import mysql as kcwmysql +from kcweb.utill.db import sqlite as kcwsqlite class web: __name=None __appname=None @@ -590,6 +591,8 @@ class web: #关闭数据库连接 dbs=kcwmysql.mysql() dbs.close() + # dbs=kcwsqlite.sqlite() + # dbs.close() if isinstance(resheaders,list): diff --git a/config/__init__.py b/config/__init__.py index 62f0f7c..4dfa759 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -116,8 +116,8 @@ domain={} domain['kcwebfile']="https://file.kwebapp.cn" domain['kcwebstatic']="https://static.kwebapp.cn" domain['kcwebimg']="https://img.kwebapp.cn" -domain['kcwebapi']="https://kcweb.kwebapp.cn" -# domain['kcwebapi']="http://www.kwebapp.cn" +# domain['kcwebapi']="https://kcweb.kwebapp.cn" +domain['kcwebapi']="https://www.kwebapp.cn" #其他配置 other={} diff --git a/utill/db/mysql.py b/utill/db/mysql.py index 9374dca..3df4356 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -431,6 +431,7 @@ class mysql: description=self.__cursor.description #获取字段 result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() + self.__None() if description is None: return res else: @@ -458,6 +459,7 @@ class mysql: description=self.__cursor.description #获取字段 result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() + self.__None() if description is None: return res else: @@ -492,6 +494,7 @@ class mysql: description=self.__cursor.description #获取字段 result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() + self.__None() lists=[] keys =[] for field in description:#获取字段 @@ -523,7 +526,7 @@ class mysql: description=self.__cursor.description #获取字段 result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() - + self.__None() item = dict() keys =[] for field in description:#获取字段 @@ -546,15 +549,20 @@ class mysql: self.__setsql('count') if self.__buildSql: self.__sqls="("+self.__sql+")" + self.__None() return self.__sql self.__execute() result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() - if len(result)>1: - return len(result) + if self.__group: + cou=len(result) else: - cou=int(result[0][0]) - return cou + try: + cou=int(result[0][0]) + except IndexError: + cou=0 + # self.__None() + return cou def max(self,field): """查询某字段的最大值 @@ -564,11 +572,13 @@ class mysql: self.__setsql('max') if self.__buildSql: self.__sqls="("+self.__sql+")" + self.__None() return self.__sql self.__execute() result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() cou=int(result[0][0]) + self.__None() return cou def min(self,field): """查询某字段的最小值 @@ -579,10 +589,12 @@ class mysql: self.__setsql('min') if self.__buildSql: self.__sqls="("+self.__sql+")" + self.__None() return self.__sql self.__execute() result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() + self.__None() cou=int(result[0][0]) return cou def avg(self,field): @@ -594,10 +606,12 @@ class mysql: self.__setsql('avg') if self.__buildSql: self.__sqls="("+self.__sql+")" + self.__None() return self.__sql self.__execute() result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() + self.__None() cou=int(result[0][0]) return cou def sum(self,field): @@ -609,10 +623,12 @@ class mysql: self.__setsql('sum') if self.__buildSql: self.__sqls="("+self.__sql+")" + self.__None() return self.__sql self.__execute() result = self.__cursor.fetchall() #获取查询结果 self.__cursor.close() + self.__None() cou=int(result[0][0]) return cou @@ -632,6 +648,7 @@ class mysql: else: self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() self.__cursor.close() + self.__None() return res def delete(self,affair=False): """数据表删除 @@ -649,6 +666,7 @@ class mysql: else: self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() self.__cursor.close() + self.__None() return res def insert(self,dicts,affair=False): """插入数据库 单条插入或多条插入 @@ -667,6 +685,7 @@ class mysql: else: self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() self.__cursor.close() + self.__None() return res __startTrans=False diff --git a/utill/db/sqlite copy.py b/utill/db/sqlite copy.py new file mode 100644 index 0000000..ba6140e --- /dev/null +++ b/utill/db/sqlite copy.py @@ -0,0 +1,685 @@ +# -*- coding: utf-8 -*- +from kcweb.config import sqlite as sqliteconfig +import time,traceback,re +import random,sqlite3,os,hashlib +class sqlite: + __config=sqliteconfig + __configt={} + __conn={} + __cursor={} + __sql=None + __sqls=None + def md5(self,strs): + """md5加密 + + 参数 strs:要加密的字符串 + + return String类型 + """ + m = hashlib.md5() + b = strs.encode(encoding='utf-8') + m.update(b) + return m.hexdigest() + def close(self): + "关闭连接" + for k in sqlite.__conn.keys(): + sqlite.__cursor[k].close() + sqlite.__conn[k].close() + sqlite.__conn={} + sqlite.__cursor={} + sqlite.__configt={} + def __setconn(self): + if not self.__configt: + self.__configt=sqliteconfig + try: + self.__conn[self.md5(self.__configt['db'])] + except KeyError: + try: + if '/' in self.__configt['db']: + self.__conn[self.md5(self.__configt['db'])] = sqlite3.connect(self.__configt['db'],check_same_thread=False) + else: + self.__conn[self.md5(self.__configt['db'])] = sqlite3.connect(os.path.split(os.path.realpath(__file__))[0]+"/sqlitedata/"+self.__configt['db'],check_same_thread=False) + except Exception as e: + raise Exception(e) + self.__cursor[self.md5(self.__configt['db'])]=self.__conn[self.md5(self.__configt['db'])].cursor() + def __execute(self,typess='DQL'): + self.__setconn() + # print(self.__sql) + try: + res=self.__cursor[self.md5(self.__configt['db'])].execute(self.__sql) + except Exception as e: + + raise Exception(e) + else: + return res + def connect(self,config): + if isinstance(config,str): + self.__configt['db']=config + elif isinstance(config,dict): + if 'db' in config: + self.__configt['db']=config['db'] + return self + __table="" + def table(self,table): + """设置表名 + + 参数 table:str 表名 + """ + self.__table=table + return self + def query(self,sql): + self.__sql=sql + self.__execute(sql,'DQL') + # self.close() + def execute(self,sql): + self.__sql=sql + res=self.__execute('DML') + rowcount=res.rowcount + # self.close() + return rowcount + # def create_table(self): + # self.__sql=("CREATE TABLE "+self.__table+ + # "(ID INT PRIMARY KEY NOT NULL,"+ + # "NAME TEXT NOT NULL,"+ + # "AGE INT NOT NULL,"+ + # "ADDRESS CHAR(50),"+ + # "SALARY REAL);") + # # print(self.__sql) + # # exit() + # self.execute(self.__sql) + def select(self,id=None): + """select查询 + + 返回 list(列表) + """ + if id : + self.__where="id=%d" % id + self.__setsql() + if self.__buildSql: + self.__sqls="("+self.__sql+")" + self.__None() + return self.__sqls + self.__execute() + description=self.__cursor[self.md5(self.__configt['db'])].description #获取字段 + result = self.__cursor[self.md5(self.__configt['db'])].fetchall() #获取查询结果 + # self.close() + lists=[] + data_dict=[] + for field in description:#获取字段 + data_dict.append(field[0]) + for k in result: + i=0 + dicts={} + for j in k: + dicts[data_dict[i]]=j + i=i+1 + lists.append(dicts) + self.__None(table=False) + return lists + def find(self,id=None): + """查询一条记录 + + 返回 字典 + """ + if id : + self.__where="id=%s" % id + self.limit(1) + self.__setsql() + if self.__buildSql: + self.__sqls="("+self.__sql+")" + self.__None() + return self.__sqls + + self.__execute() + description=self.__cursor[self.md5(self.__configt['db'])].description #获取字段 + result = self.__cursor[self.md5(self.__configt['db'])].fetchall() #获取查询结果 + # self.close() + data_dict=[] + for field in description:#获取字段 + data_dict.append(field[0]) + dicts={} + for k in result: + i=0 + for j in k: + dicts[data_dict[i]]=j + i=i+1 + self.__None(table=False) + return dicts + def count(self,field="*"): + """查询数量 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('count') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor[self.md5(self.__configt['db'])].fetchall() #获取查询结果 + # self.close() + if self.__group: + cou=len(result) + else: + try: + cou=int(result[0][0]) + except IndexError: + cou=0 + self.__None(table=False) + return cou + def max(self,field): + """查询某字段的最大值 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('max') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor[self.md5(self.__configt['db'])].fetchall() #获取查询结果 + # self.close() + cou=int(result[0][0]) + self.__None(table=False) + return cou + def min(self,field): + """查询某字段的最小值 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('min') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor[self.md5(self.__configt['db'])].fetchall() #获取查询结果 + # self.close() + cou=int(result[0][0]) + self.__None(table=False) + return cou + def avg(self,field): + """查询某字段的平均值 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('avg') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor[self.md5(self.__configt['db'])].fetchall() #获取查询结果 + # self.close() + cou=int(result[0][0]) + self.__None(table=False) + return cou + def sum(self,field): + """查询某字段之和 + + 返回 int 数字 + """ + self.__field=field + self.__setsql('sum') + if self.__buildSql: + self.__sqls="("+self.__sql+")" + return self.__sql + self.__execute() + result = self.__cursor[self.md5(self.__configt['db'])].fetchall() #获取查询结果 + # self.close() + cou=int(result[0][0]) + self.__None(table=False) + return cou + def update(self,data,affair=False): + """数据表更新 + + 参数 data 要更新的内容 格式:{"name":"测试","age":20} + + 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 + """ + self.__setsql('update',data) + res=self.__execute('DML') + if affair==False and self.__startTrans==False: + self.commit() + rowcount=res.rowcount + # self.close() + self.__None(table=False) + return rowcount + def delete(self,affair=False): + """数据表删除 + + 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 + """ + self.__setsql('delete') + if self.__where: + res=self.__execute('DML') + else: + return 0 + if affair==False and self.__startTrans==False: + self.commit() + rowcount=res.rowcount + # self.close() + self.__None(table=False) + return rowcount + def insert(self,dicts,affair=False): + """插入数据库 单条插入或多条插入 + + 参数 dicts 要插入的内容 单条格式:{"name":"测试","age":20} 。 多条格式:[{"name":"测试","age":20},{"name":"测试","age":20}] + + 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 + + 返回插入的数量 + """ + self.__setsql('insert',dicts) + res=self.__execute('DML') + if affair==False and self.__startTrans==False: + self.commit() + rowcount=res.rowcount + # self.close() + self.__None(table=False) + return rowcount + __startTrans=False + def startTrans(self): + "开启事务,仅对 update方法、delete方法、install方法有效" + self.__startTrans=True + def commit(self): + """事务提交 + + 增删改后的任务进行提交 + """ + self.__conn[self.md5(self.__configt['db'])].commit() + def rollback(self): + """事务回滚 + + 增删改后的任务进行撤销 + """ + self.__conn[self.md5(self.__configt['db'])].rollback() + def getsql(self): + """得到生成的sql语句""" + return self.__sql + __buildSql=None + def buildSql(self): + """构造子查询""" + self.__buildSql=True + return self + def __None(self,table=True): + "清除所有赋值条件" + self.__lock=None + self.__distinct=None + self.__join=None + self.__joinstr='' + self.__alias=None + self.__having=None + self.__group=None + self.__group1=None + self.__order=None + self.__order1=None + self.__limit=None + self.__field="*" + self.__where=None + self.__wheres=() + self.__buildSql=None + if table: + self.__table=None + __where=None + __wheres=() + def where(self,where = None,*wheres): + """设置过滤条件 + + 传入方式: + "id",2 表示id='2' + + "id","in",2,3,4,5,6,...表示 id in (2,3,4,5,6,...) + + "id","in",[2,3,4,5,6,...]表示 id in (2,3,4,5,6,...) + + [("id","gt",6000),"and",("name","like","%超")] 表示 ( id > "6000" and name LIKE "%超" ) + + "id","eq",1 表示 id = '1' + + eq 等于 + neq 不等于 + gt 大于 + egt 大于等于 + lt 小于 + elt 小于等于 + like LIKE + """ + self.__where=where + self.__wheres=wheres + # print(len(self.__wheres)) + return self + __field='*' + def field(self,field = "*"): + """设置过滤显示条件 + + 参数 field:str 字符串 + """ + self.__field=field + return self + __limit=[] + def limit(self,offset, length = None): + """设置查询数量 + + 参数 offset:int 起始位置 + + 参数 length:int 查询数量 + """ + self.__limit=[offset,length] + return self + def page(self,pagenow=1, length = 20): + """设置分页查询 + + 参数 pagenow:int 页码 + + 参数 length:int 查询数量 + """ + offset=(pagenow-1)*length + self.__limit=[offset,length] + return self + __order=None + __order1=None + def order(self,strs=None,*strs1): + """设置排序查询 + + 传入方式: + + "id desc" + + "id",'name','appkey','asc' + + "id",'name','appkey' 不包含asc或desc的情况下 默认是desc + + ['id','taskid',{"task_id":"desc"}] + """ + self.__order=strs + self.__order1=strs1 + return self + __group=None + __group1=None + def group(self,strs=None,*strs1): + """设置分组查询 + + 传入方式: + + "id,name" + + "id","name" + """ + self.__group=strs + self.__group1=strs1 + return self + __having=None + def having(self,strs=None): + """用于配合group方法完成从分组的结果中筛选(通常是聚合条件)数据 + + 参数 strs:string 如:"count(time)>3" + """ + self.__having=strs + return self + + __alias=None + def alias(self,strs=None): + """用于设置当前数据表的别名,便于使用其他的连贯操作例如join方法等。 + + 参数 strs:string 默认当前表作为别名 + """ + if strs: + self.__alias=strs + else: + self.__alias=self.__table + return self + __join=None + __joinstr='' + def join(self,strs,on=None,types='INNER'): + """用于根据两个或多个表中的列之间的关系,从这些表中查询数据 + + 参数 strs string 如:"test t1" test表设置别名t1 + + 参数 on string 如:"t1.id=t2.pid" 设置连接条件 + + 参数 types 支持INNER、LEFT、RIGHT、FULL 默认INNER + + """ + joinstr='' + if strs and on: + joinstr=joinstr+types+" JOIN "+strs+" ON "+on+" " + if joinstr: + self.__joinstr=self.__joinstr+joinstr + return self + __distinct=None + def distinct(self,bools=None): + "用于返回唯一不同的值,配合field方法使用生效,消除所有重复的记录,并只获取唯一一次记录。" + self.__distinct=bools + return self + __lock=None + def lock(self,strs=None): + """用于数据库的锁机制,在查询或者执行操作的时候使用 (暂未实现) + + 排他锁 (Exclusive lock) + + 共享锁 (Shared lock) + + 参数 strs 如:True表示自动在生成的SQL语句最后加上FOR UPDATE, + + + """ + # self.__lock=strs + return self + def __setsql(self,types=None,data = {}): + """生成sql语句""" + if types==None: + self.__sql="SELECT" + if self.__distinct and self.__field: + self.__sql=self.__sql+" DISTINCT" + if self.__alias: + self.__sql=self.__sql+" %s FROM %s %s" % (self.__field,self.__table,self.__alias) + else: + self.__sql=self.__sql+" %s FROM %s" % (self.__field,self.__table) + elif types=='count': + self.__sql="SELECT COUNT(%s) FROM %s" % (self.__field,self.__table) + elif types=='max': + self.__sql="SELECT MAX(%s) FROM %s" % (self.__field,self.__table) + elif types=='min': + self.__sql="SELECT MIN(%s) FROM %s" % (self.__field,self.__table) + elif types=='avg': + self.__sql="SELECT AVG(%s) FROM %s" % (self.__field,self.__table) + elif types=='sum': + self.__sql="SELECT SUM(%s) FROM %s" % (self.__field,self.__table) + elif types=='update': + strs='' + for k in data: + if isinstance(data[k],str): + strs=strs+" %s = '%s' ," % (k,self.escape_string(data[k])) + else: + strs=strs+" %s = %s ," % (k,data[k]) + strs=strs[:-1] + self.__sql="UPDATE %s SET %s" % (self.__table,strs) + # print(self.__sql) + elif types=='delete': + self.__sql="DELETE FROM %s" % (self.__table) + elif types=='insert': + if isinstance(data,dict): + strs='' + val='' + for k in data: + strs=strs+"%s," % k + if isinstance(data[k],str): + val=val+"'%s'," % self.escape_string(data[k]) + else: + val=val+"%s," % data[k] + strs=strs[:-1] + val=val[:-1] + self.__sql="INSERT INTO "+str(self.__table)+" ("+strs+") VALUES ("+val+")" + # print(self.__sql) + elif isinstance(data,list): + strs='' + val='(' + for k in data[0]: + strs=strs+" , "+k + for k in data: + for j in k: + if isinstance(k[j],str): + val=val+"'"+str(k[j])+"'," + else: + val=val+str(k[j])+"," + val=val[:-1] + val=val+"),(" + val=val[:-2] + self.__sql="INSERT INTO "+str(self.__table)+" ("+strs[3:]+") VALUES "+val + + if self.__joinstr: + # print(self.__sql) + self.__sql=self.__sql+" "+self.__joinstr + if self.__where: + if isinstance(self.__where,str): + if self.__wheres: + if len(self.__wheres) == 2: + if isinstance(self.__wheres[1],list): + self.__sql=self.__sql + " WHERE %s %s (" % (self.__where,self.__operator(self.__wheres[0])) + for k in self.__wheres[1]: + self.__sql=self.__sql+str(k)+"," + self.__sql=self.__sql[:-1]+")" + else: + self.__sql=self.__sql + " WHERE %s %s '%s'" % (self.__where,self.__operator(self.__wheres[0]),self.__wheres[1]) + elif len(self.__wheres) > 2: + if self.__wheres[0]=='in': + strs=str(self.__wheres[1]) + i=0 + for k in self.__wheres: + if i > 1: + strs=strs+","+str(k) + i=i+1 + self.__sql=self.__sql + " WHERE %s in (%s)" % (self.__where,strs) + else: + self.__sql=self.__sql + " WHERE %s = '%s'" % (self.__where,self.__wheres[0]) + else: + self.__sql=self.__sql + " WHERE %s" % self.__where + elif isinstance(self.__where,list): + self.__sql=self.__sql + " WHERE %s" % self.__listTrans() + else: + print("参数where类型错误",type(self.__where),self.__where) + if self.__order: + s='' + if isinstance(self.__order,list): + for strs in self.__order: + if isinstance(strs,str): + s=s+strs+"," + else: + pass + for key in strs: + s=s+key+" "+strs[key] + s=s+"," + s=s[:-1] + if isinstance(self.__order,str): + if self.__order1: + if len(self.__order1) > 1: + if self.__order1[len(self.__order1)-1] == 'desc' or self.__order1[len(self.__order1)-1] == 'asc': + i=0 + while i Date: Wed, 2 Sep 2020 22:06:10 +0800 Subject: [PATCH 46/52] kun --- utill/queues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utill/queues.py b/utill/queues.py index a2fdb84..40dd467 100644 --- a/utill/queues.py +++ b/utill/queues.py @@ -35,7 +35,7 @@ class Queues(): t.daemon=True t.start() def __messagequeue(): - time.sleep(0.01) + # time.sleep(0.01) kcwsqlite.sqlite().connect(queuesdbpath).table("model_kcweb_queues").where("code","in",2,3).delete() while True: if not Queues.__globalqueue.empty(): -- Gitee From b1dd9350d7c1c416120ac91f87a2af83bc48c6c0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 6 Sep 2020 01:16:56 +0800 Subject: [PATCH 47/52] kun --- common/request.py | 13 +++++++------ config/__init__.py | 2 +- setup.py | 2 +- utill/db/mysql.py | 13 ++++++++++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/common/request.py b/common/request.py index 3468bdf..e65ed6b 100644 --- a/common/request.py +++ b/common/request.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- from kcweb.common import globals as kcwglobals -from urllib import parse -import json +import json,urllib class args: "获取url" + def params(): + return urllib.parse.parse_qs(urllib.parse.urlparse(kcwglobals.HEADER.URL).query) def get(name): """获取键值对 @@ -11,7 +12,7 @@ class args: return 值 """ - params = parse.parse_qs(parse.urlparse(kcwglobals.HEADER.URL).query) + params = args.params() try: k=params[name][0] except: @@ -41,9 +42,9 @@ class froms: return 值 """ data=kcwglobals.HEADER.BODY_DATA - params = parse.parse_qs(parse.urlparse("?"+str(data)).query) + params = urllib.parse.parse_qs(urllib.parse.urlparse("?"+str(data)).query) try: - k=parse.unquote(params[name][0]) + k=urllib.parse.unquote(params[name][0]) except: k=None return k @@ -57,7 +58,7 @@ class froms: data={} for k in lists: ar=k.split("=") - data[ar[0]]=ar[1] + data[ar[0]]=urllib.parse.unquote(ar[1]) return data except:return None class binary: diff --git a/config/__init__.py b/config/__init__.py index 4dfa759..d71a075 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -100,7 +100,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.11.9' #项目版本 +kcweb['version']='4.12.2' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/setup.py b/setup.py index b9e9dca..1d4a1c2 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.12.1' #项目版本 +confkcw['version']='4.12.2' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="增加websocket" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 diff --git a/utill/db/mysql.py b/utill/db/mysql.py index 3df4356..bdea205 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -2,11 +2,11 @@ from .pymysql import connect,escape_string # import config.conf as config import kcweb.config as config -import time,traceback,decimal,random +import time,traceback,decimal,random,copy dbconfig=config.database class mysql: """数据库实例""" - __config=dbconfig + __config=copy.deepcopy(dbconfig) __conn={} #数据库链接对象 __connlists=[] #短连接列表 用于关闭 __cursor=None #游标对象 @@ -242,6 +242,7 @@ class mysql: else: raise Exception(e) else: + self.__config=copy.deepcopy(dbconfig) self.__errorcounts=0 def connect(self,config): @@ -776,13 +777,15 @@ class mysql: self.__field=field return self __limit=[] - def limit(self,offset, length = None): + def limit(self,offset=1, length = None): """设置查询数量 参数 offset:int 起始位置 参数 length:int 查询数量 """ + if not offset: + offset=1 offset=int(offset) if length: length=int(length) @@ -795,6 +798,10 @@ class mysql: 参数 length:int 查询数量 """ + if not pagenow: + pagenow=1 + if not length: + length=20 pagenow=int(pagenow) length=int(length) offset=(pagenow-1)*length -- Gitee From 497b3462f1f7d271a53377099fe783cbdd30f2ec Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 8 Sep 2020 00:57:59 +0800 Subject: [PATCH 48/52] k --- common/request.py | 4 ++++ utill/db/mysql.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/common/request.py b/common/request.py index e65ed6b..688cb11 100644 --- a/common/request.py +++ b/common/request.py @@ -112,6 +112,10 @@ class HEADER: return kcwglobals.HEADER.SERVER_PROTOCOL def HTTP_HOST(): return kcwglobals.HEADER.HTTP_HOST + def HTTP_COOKIE(): + return kcwglobals.HEADER.HTTP_COOKIE + def HTTP_USER_AGENT(): + return kcwglobals.HEADER.HTTP_USER_AGENT def get_data(): "获取请求参数体" return kcwglobals.HEADER.BODY_DATA diff --git a/utill/db/mysql.py b/utill/db/mysql.py index bdea205..abf0e6f 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -228,6 +228,7 @@ class mysql: print("无法链接到数据库服务器,准备第%d次重新链接:%s" % (self.__errorcounts,e)) self.__connects(typess) else: + self.__config=copy.deepcopy(dbconfig) self.__errorcounts=0 raise Exception(e) else: @@ -237,6 +238,7 @@ class mysql: print("无法链接到数据库服务器,开始重新链接") self.__connects(typess) else: + self.__config=copy.deepcopy(dbconfig) self.__errorcounts=0 raise Exception(e) else: -- Gitee From 84dff0b1d6674757a2522fa71feac1b78270aa7d Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 10 Sep 2020 02:56:12 +0800 Subject: [PATCH 49/52] kun --- common/autoload.py | 25 +++++++++++++++++++++++-- utill/db/mysql.py | 5 ++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/common/autoload.py b/common/autoload.py index 0a71c0c..c813c53 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -600,10 +600,31 @@ class response: body=f.read() f.close() kind = filetype.guess(filename) - ContentType=kind.mime + try: + ContentType=kind.mime + except: + ContentType="image/png" else: ContentType="image/png" - return body,'200 ok',{"Content-Type":ContentType,"Cache-Control":"public, max-age=60"} + return body,'200 ok',{"Content-Type":ContentType,"Cache-Control":"public, max-age=600"} + def video(body): + """输出音频 + + body 音频二进制内容或音频路径 + """ + if isinstance(body,str): + filename=body + f=open(filename,"rb") + body=f.read() + f.close() + kind = filetype.guess(filename) + try: + ContentType=kind.mime + except: + ContentType="video/mp4" + else: + ContentType="video/mp4" + return body,'200 ok',{"Content-Type":ContentType,"Cache-Control":"public, max-age=600"} def download(pathname): """下载文件 diff --git a/utill/db/mysql.py b/utill/db/mysql.py index abf0e6f..50883df 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -2,8 +2,8 @@ from .pymysql import connect,escape_string # import config.conf as config import kcweb.config as config -import time,traceback,decimal,random,copy -dbconfig=config.database +import time,traceback,decimal,random +dbconfig=copy.deepcopy(config.database) class mysql: """数据库实例""" __config=copy.deepcopy(dbconfig) @@ -244,7 +244,6 @@ class mysql: else: raise Exception(e) else: - self.__config=copy.deepcopy(dbconfig) self.__errorcounts=0 def connect(self,config): -- Gitee From 5462dcf36d6ff215e2dccdbc4882d13f16aa4fe2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 10 Sep 2020 03:06:24 +0800 Subject: [PATCH 50/52] kun --- utill/db/mysql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utill/db/mysql.py b/utill/db/mysql.py index 50883df..161db80 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -2,7 +2,7 @@ from .pymysql import connect,escape_string # import config.conf as config import kcweb.config as config -import time,traceback,decimal,random +import time,traceback,decimal,random,copy dbconfig=copy.deepcopy(config.database) class mysql: """数据库实例""" -- Gitee From 936f8faa28d3b3eb855c7c7e8d73d876a88936c0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 15 Sep 2020 01:02:35 +0800 Subject: [PATCH 51/52] kun --- utill/db/mysql.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utill/db/mysql.py b/utill/db/mysql.py index 161db80..be287a5 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -2,11 +2,11 @@ from .pymysql import connect,escape_string # import config.conf as config import kcweb.config as config -import time,traceback,decimal,random,copy -dbconfig=copy.deepcopy(config.database) +import time,traceback,decimal,random #,copy +dbconfig=config.database class mysql: """数据库实例""" - __config=copy.deepcopy(dbconfig) + __config=dbconfig __conn={} #数据库链接对象 __connlists=[] #短连接列表 用于关闭 __cursor=None #游标对象 @@ -228,7 +228,7 @@ class mysql: print("无法链接到数据库服务器,准备第%d次重新链接:%s" % (self.__errorcounts,e)) self.__connects(typess) else: - self.__config=copy.deepcopy(dbconfig) + # self.__config=copy.deepcopy(dbconfig) self.__errorcounts=0 raise Exception(e) else: @@ -238,7 +238,7 @@ class mysql: print("无法链接到数据库服务器,开始重新链接") self.__connects(typess) else: - self.__config=copy.deepcopy(dbconfig) + # self.__config=copy.deepcopy(dbconfig) self.__errorcounts=0 raise Exception(e) else: -- Gitee From 6dd0c1cf68d3d05ccb92cf2c33d00589a218f8a5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 12 Oct 2020 21:15:51 +0800 Subject: [PATCH 52/52] kun --- app.py | 88 ++++++++++------ common/autoload.py | 242 ++++++++++++++++++++++++++++++++++++------- common/request.py | 4 +- config/__init__.py | 4 +- utill/cache/cache.py | 4 +- utill/db/mysql.py | 23 +++- 6 files changed, 287 insertions(+), 78 deletions(-) diff --git a/app.py b/app.py index 65e7359..ebf10f9 100644 --- a/app.py +++ b/app.py @@ -23,23 +23,36 @@ class web: p=(config.app['staticpath']+env['RAW_URI'].replace(' ','')) status='200 ok' if os.path.isfile(p): - kind = filetype.guess(p) - if kind is None: - f=open(p,"rb") - body=f.read() - f.close() - resheader=[ - ("Cache-Control","public, max-age=43200"), - ] + resheader=[("Cache-Control","public, max-age=2592000"),] + ETag=md5(p) + try: + HTTP_IF_NONE_MATCH=env['HTTP_IF_NONE_MATCH'] + except KeyError: + HTTP_IF_NONE_MATCH=None + if HTTP_IF_NONE_MATCH: + status="304 Not Modified" + body='' else: - f=open(p,"rb") - body=f.read() - f.close() - resheader=[ - ("Content-Type",kind.mime), - ("Cache-Control","public, max-age=43200"), - ("Accept-Ranges","bytes"), - ] + kind = filetype.guess(p) + if kind is None: + f=open(p,"rb") + body=f.read() + f.close() + else: + f=open(p,"rb") + body=f.read() + f.close() + resheader=[ + ("Content-Type",kind.mime), + ("Cache-Control","public, max-age=43200"), + ("Accept-Ranges","bytes"), + ] + resheader.append(('Content-Type',kind.mime)) + resheader.append(("Accept-Ranges","bytes")) + dateArray = datetime.utcfromtimestamp(times()-86400) + otherStyleTime = dateArray.strftime('%a, %d %b %Y %H:%M:%S GMT') + resheader.append(("Last-Modified",otherStyleTime)) + resheader.append(("ETag",ETag)) else: files=None try: @@ -344,6 +357,7 @@ class web: body=data return body,status,resheader def __set_globals(self,header): + globals.HEADER.GET=header globals.HEADER.Method=header['REQUEST_METHOD'] globals.HEADER.URL=header['RAW_URI'] globals.HEADER.PATH_INFO=header['PATH_INFO'] @@ -665,23 +679,33 @@ class web: p=(config.app['staticpath']+reqheader['RAW_URI'].replace(' ','')) status='200 ok' if os.path.isfile(p): - kind = filetype.guess(p) - if kind is None: - f=open(p,"rb") - body=f.read() - f.close() - resheader=[ - ("Cache-Control","public, max-age=43200"), - ] + resheader=[("Cache-Control","public, max-age=2592000"),("Accept-Ranges","bytes")] + ETag=md5(p) + try: + HTTP_IF_NONE_MATCH=globals.HEADER.GET['HTTP_IF_NONE_MATCH'] + except: + HTTP_IF_NONE_MATCH=None + if HTTP_IF_NONE_MATCH: + status="304 Not Modified" else: - f=open(p,"rb") - body=f.read() - f.close() - resheader=[ - ("Content-Type",kind.mime), - ("Cache-Control","public, max-age=43200"), - ("Accept-Ranges","bytes"), - ] + kind = filetype.guess(p) + if kind is None: + f=open(p,"rb") + body=f.read() + f.close() + if '.css' in p[-5:]: + resheader.append(("Content-Type","text/css")) + elif '.js' in p[-5:]: + resheader.append(("Content-Type","application/javascript")) + else: + f=open(p,"rb") + body=f.read() + f.close() + resheader.append(("Content-Type",kind.mime)) + dateArray = datetime.utcfromtimestamp(times()-86400) + otherStyleTime = dateArray.strftime('%a, %d %b %Y %H:%M:%S GMT') + resheader.append(("Last-Modified",otherStyleTime)) + resheader.append(("ETag",ETag)) else: status,resheader,body=web.__routes(self,reqheader) resheader.append(('Server', "kcweb"+config.kcweb['version'])) diff --git a/common/autoload.py b/common/autoload.py index c813c53..974efdf 100644 --- a/common/autoload.py +++ b/common/autoload.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import time,hashlib,json,re,os,platform,sys,shutil,requests,importlib,traceback,pip,gzip,tarfile,zipfile,random +import time,hashlib,json,re,os,platform,sys,shutil,requests,importlib,traceback,pip,gzip,tarfile,zipfile,random,copy import datetime as core_datetime from kcweb import config from kcweb.utill.dateutil.relativedelta import relativedelta as core_relativedelta @@ -12,6 +12,7 @@ from kcweb.utill.http import Http from kcweb.utill.queues import Queues from kcweb.utill.db import model from mako.template import Template as kcwTemplate +from mako.lookup import TemplateLookup import smtplib from email.mime.text import MIMEText from email.utils import formataddr @@ -298,11 +299,16 @@ def Template(path,**context): return Templates(str(config.app['tpl_folder'])+str(path),**context) def Templates(path,**context): "模板渲染引擎函数,需要完整的模板目录文件" - body='' - with open(path, 'r',encoding='utf-8') as f: - content=f.read() - t=kcwTemplate(content) - body=t.render(**context) + lookup = TemplateLookup(directories=['']) + # body='' + # with open(path, 'r',encoding='utf-8') as f: + # contents=f.read() + # t=kcwTemplate(contents,lookup=lookup,module_directory=config.cache['path']+"/Template") + # body=t.render(**context) + + # t=kcwTemplate(filename=path,module_directory=config.cache['path']+"/Template",lookup=lookup) + t=lookup.get_template(path) + body=t.render(**context) return body def mysql(table=None,configss=None): """mysql数据库操作实例 @@ -575,8 +581,20 @@ class kcwtar: return False class response: - def tpl(path=None,status='200 ok',header={"Content-Type":"text/html; charset=utf-8"},**context): - "返回模板内容" + def tpl(path=None,status='200 ok',response_cache=False,ETag=None,header={"Content-Type":"text/html; charset=utf-8"},**context): + """返回模板内容 + + path 文件地址 + + status 响应状态码 + + response_cache 是否启用浏览器缓存 响应状态码200 ok时有效 + + ETag 缓存标识 响应状态码200 ok时有效 + + header 响应头 + """ + headers=copy.deepcopy(header) getroutecomponent=globals.VAR.component if path: if path[:1]=="/": @@ -585,46 +603,181 @@ class response: Temppath="/"+getroutecomponent[1]+"/controller/"+getroutecomponent[2]+"/tpl/"+path+".html" else: Temppath="/"+getroutecomponent[1]+"/controller/"+getroutecomponent[2]+"/tpl/"+getroutecomponent[3]+"/"+getroutecomponent[4]+".html" - return Template(Temppath,config=config,**context),status,header - def json(res=[],status='200 ok',header={"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"}): - "响应json内容" - return json_encode(res),status,header - def pic(body): + if status=='200 ok' and response_cache: + if not ETag: + ttt='' + for k in context.keys(): + ttt+=k+str(context[k]) + ETag=md5(Temppath+ttt+globals.HEADER.URL) + try: + HTTP_IF_NONE_MATCH=globals.HEADER.GET['HTTP_IF_NONE_MATCH'] + except: + HTTP_IF_NONE_MATCH=None + if HTTP_IF_NONE_MATCH and get_cache(ETag): + status="304 Not Modified" + body='' + else: + if isinstance(response_cache,int) and response_cache>1: + headers['response_cache']=str(response_cache)+" s" + set_cache(ETag,1,response_cache) + else: + headers['response_cache']="default" + set_cache(ETag,1) + body=Template(Temppath,config=config,**context) + dateArray = core_datetime.datetime.utcfromtimestamp(times()-86400) + otherStyleTime = dateArray.strftime('%a, %d %b %Y %H:%M:%S GMT') + headers['Last-Modified']=otherStyleTime + headers['ETag']=ETag + return body,status,headers + elif status: + return Template(Temppath,config=config,**context),status,headers + else: + return Template(Temppath,config=config,**context),'200 ok',headers + def json(res=[],status='200 ok',response_cache=False,ETag=None,header={"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"}): + """响应json内容 + + res body内容 + + status 响应状态码 + + response_cache 是否启用浏览器缓存 响应状态码200 ok时有效 + + ETag 缓存标识 响应状态码200 ok时有效 + + header 响应头 + """ + headers=copy.deepcopy(header) + if status=='200 ok' and response_cache: + if not ETag: + ETag=md5(globals.HEADER.URL) + try: + HTTP_IF_NONE_MATCH=globals.HEADER.GET['HTTP_IF_NONE_MATCH'] + except: + HTTP_IF_NONE_MATCH=None + if(HTTP_IF_NONE_MATCH and get_cache(ETag)): + status="304 Not Modified" + body='' + else: + if isinstance(response_cache,int) and response_cache>1: + set_cache(ETag,1,response_cache) + headers['response_cache']=str(response_cache)+" s" + else: + set_cache(ETag,1) + headers['response_cache']="default" + body=json_encode(res) + dateArray = core_datetime.datetime.utcfromtimestamp(times()-86400) + otherStyleTime = dateArray.strftime('%a, %d %b %Y %H:%M:%S GMT') + headers['Last-Modified']=otherStyleTime + headers['ETag']=ETag + + else: + body=json_encode(res) + return body,status,headers + def pic(body,response_cache=True,ETag=None): """输出图片 - body 图片二进制内容或图片路径 + body 图片二进制内容或图片路径 建议使用图片路径 + + response_cache 是否启用浏览器缓存 body使用图片路径时有效 + + ETag 缓存标识 """ + status='200 ok' + header={"Cache-Control":"public, max-age=2592000"} if isinstance(body,str): - filename=body - f=open(filename,"rb") - body=f.read() - f.close() - kind = filetype.guess(filename) - try: - ContentType=kind.mime - except: - ContentType="image/png" + if response_cache: + if not ETag: + ETag=md5(body+globals.HEADER.URL) + try: + HTTP_IF_NONE_MATCH=globals.HEADER.GET['HTTP_IF_NONE_MATCH'] + except: + HTTP_IF_NONE_MATCH=None + if(HTTP_IF_NONE_MATCH and get_cache(ETag)): + status="304 Not Modified" + body='' + else: + if isinstance(response_cache,int) and response_cache>1: + set_cache(ETag,1,response_cache) + else: + set_cache(ETag,1) + filename=body + f=open(filename,"rb") + body=f.read() + f.close() + kind = filetype.guess(filename) + try: + header['Content-Type']=kind.mime + except: + header['Content-Type']="image/png" + else: + filename=body + f=open(filename,"rb") + body=f.read() + f.close() + kind = filetype.guess(filename) + try: + header['Content-Type']=kind.mime + except: + header['Content-Type']="image/png" + dateArray = core_datetime.datetime.utcfromtimestamp(times()-86400) + otherStyleTime = dateArray.strftime('%a, %d %b %Y %H:%M:%S GMT') + header['Last-Modified']=otherStyleTime + header['ETag']=ETag else: - ContentType="image/png" - return body,'200 ok',{"Content-Type":ContentType,"Cache-Control":"public, max-age=600"} + header['Content-Type']="image/png" + return body,status,header def video(body): """输出音频 body 音频二进制内容或音频路径 """ + status='200 ok' + header={"Cache-Control":"public, max-age=2592000"} if isinstance(body,str): - filename=body - f=open(filename,"rb") - body=f.read() - f.close() - kind = filetype.guess(filename) + ETag=md5(body) try: - ContentType=kind.mime + HTTP_IF_NONE_MATCH=globals.HEADER.GET['HTTP_IF_NONE_MATCH'] except: - ContentType="video/mp4" + HTTP_IF_NONE_MATCH=None + if(HTTP_IF_NONE_MATCH and get_cache(ETag)): + status="304 Not Modified" + body='' + else: + set_cache(ETag,1,2592000) + filename=body + f=open(filename,"rb") + body=f.read() + f.close() + kind = filetype.guess(filename) + try: + header['Content-Type']=kind.mime + except: + header['Content-Type']="video/mp4" + dateArray = core_datetime.datetime.utcfromtimestamp(times()-86400) + otherStyleTime = dateArray.strftime('%a, %d %b %Y %H:%M:%S GMT') + header['Last-Modified']=otherStyleTime + header['ETag']=ETag else: - ContentType="video/mp4" - return body,'200 ok',{"Content-Type":ContentType,"Cache-Control":"public, max-age=600"} + header['Content-Type']="video/mp4" + return body,status,header + # def video(body): + # """输出音频 + + # body 音频二进制内容或音频路径 + # """ + # if isinstance(body,str): + # filename=body + # f=open(filename,"rb") + # body=f.read() + # f.close() + # kind = filetype.guess(filename) + # try: + # ContentType=kind.mime + # except: + # ContentType="video/mp4" + # else: + # ContentType="video/mp4" + # return body,'200 ok',{"Content-Type":ContentType,"Cache-Control":"public, max-age=600"} def download(pathname): """下载文件 @@ -774,12 +927,21 @@ class create: tplug="index" #默认插件 elif arr['code']==0 and arr['data']: arr=arr['data'] - r=requests.get(arr['dowurl']) - f = open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", "wb") - for chunk in r.iter_content(chunk_size=512): - if chunk: - f.write(chunk) - f.close() + tttttt=0 + while True: + if tttttt<5: + r=requests.get(arr['dowurl']) + f = open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", "wb") + for chunk in r.iter_content(chunk_size=512): + if chunk: + f.write(chunk) + f.close() + if zipfile.is_zipfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"): + break + else: + tttttt+=1 + else: + return False,plug+"插件下载失败" if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") diff --git a/common/request.py b/common/request.py index 688cb11..4a65a1d 100644 --- a/common/request.py +++ b/common/request.py @@ -16,7 +16,7 @@ class args: try: k=params[name][0] except: - k=None + k='' return k def get_json(): """获取 json get内容 @@ -102,6 +102,8 @@ class binary: else: return None class HEADER: + def GET(): + return kcwglobals.HEADER.GET def Method(): return kcwglobals.HEADER.Method def URL(): diff --git a/config/__init__.py b/config/__init__.py index d71a075..830b363 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -55,7 +55,7 @@ database['port']=[3306] #端口 [端口1,端口2,端口3...] database['user']=['root'] #用户名 [用户名1,用户名2,用户名3...] database['password']=['root'] #密码 [密码1,密码2,密码3...] database['db']=['test'] #数据库名 [数据库名1,数据库名2,数据库名3...] -database['charset']='utf8' #数据库编码默认采用utf8 +database['charset']='utf8mb4' #数据库编码默认采用utf8mb4 database['pattern']=False # True数据库长连接模式 False数据库短连接模式 注:建议web应用有效,cli应用方式下,如果长时间运行建议使用mysql().close()关闭 database['cli']=app['cli'] # 是否以cli方式运行 database['dbObjcount']=1 # 连接池数量(单个数据库地址链接数量),数据库链接实例数量 mysql长链接模式下有效 @@ -117,7 +117,7 @@ domain['kcwebfile']="https://file.kwebapp.cn" domain['kcwebstatic']="https://static.kwebapp.cn" domain['kcwebimg']="https://img.kwebapp.cn" # domain['kcwebapi']="https://kcweb.kwebapp.cn" -domain['kcwebapi']="https://www.kwebapp.cn" +domain['kcwebapi']="https://kcweb.kwebapp.cn" #其他配置 other={} diff --git a/utill/cache/cache.py b/utill/cache/cache.py index 710b854..8df20e7 100644 --- a/utill/cache/cache.py +++ b/utill/cache/cache.py @@ -235,7 +235,7 @@ class cache: try: f=open(self.__config['path']+"/"+self.__name,"r") except Exception: - return None + return "" json_str=f.read() f.close() ar=json_decode(json_str) @@ -244,7 +244,7 @@ class cache: if (times()-ar['time']) > ar['expire']: self.__delfilecache() - return None + return "" else: return ar['values'] else: diff --git a/utill/db/mysql.py b/utill/db/mysql.py index be287a5..c2598e8 100644 --- a/utill/db/mysql.py +++ b/utill/db/mysql.py @@ -634,7 +634,26 @@ class mysql: cou=int(result[0][0]) return cou - + def setinc(self,field,key=1,affair=False): + """更新字段增加 + + 参数 field 要更新的字段 + + 参数 key 字段需要加多少 + + 参数 affair 是否开启事务 True表示手动提交事务 False表示自动提交事务 + """ + data={"field":field,"key":key} + self.__setsql('setinc',data) + res=self.__execute('DML') + if affair==False and self.__startTrans==False: + if not self.__config['pattern']: + self.__conn[self.__masteridentifier].commit() + else: + self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit() + self.__cursor.close() + self.__None() + return res def update(self,data,affair=False): """数据表更新 @@ -927,6 +946,8 @@ class mysql: self.__sql="SELECT AVG(%s) FROM %s" % (self.__field,self.__table) elif types=='sum': self.__sql="SELECT SUM(%s) FROM %s" % (self.__field,self.__table) + elif types=='setinc': + self.__sql="update %s set %s=%s+%d" % (self.__table,data['field'],data['field'],data['key']) elif types=='update': strs='' for k in data: -- Gitee