Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
evm-store
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanli
evm-store
Commits
b48cbc56
Commit
b48cbc56
authored
Jul 29, 2021
by
wanliofficial
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🌈
style(): 更新缓存,删除不必要文件
parent
32df1548
Changes
80
Show whitespace changes
Inline
Side-by-side
Showing
80 changed files
with
0 additions
and
9167 deletions
+0
-9167
tools/build_out/.gitignore
tools/build_out/.gitignore
+0
-1
tools/build_out/README.md
tools/build_out/README.md
+0
-71
tools/build_out/application/__init__.py
tools/build_out/application/__init__.py
+0
-8
tools/build_out/application/app.py
tools/build_out/application/app.py
+0
-114
tools/build_out/application/config.py
tools/build_out/application/config.py
+0
-89
tools/build_out/application/signal_manager.py
tools/build_out/application/signal_manager.py
+0
-80
tools/build_out/controllers/__init__.py
tools/build_out/controllers/__init__.py
+0
-97
tools/build_out/controllers/annex.py
tools/build_out/controllers/annex.py
+0
-80
tools/build_out/controllers/api.py
tools/build_out/controllers/api.py
+0
-290
tools/build_out/controllers/app.py
tools/build_out/controllers/app.py
+0
-287
tools/build_out/controllers/area.py
tools/build_out/controllers/area.py
+0
-80
tools/build_out/controllers/device.py
tools/build_out/controllers/device.py
+0
-103
tools/build_out/controllers/file.py
tools/build_out/controllers/file.py
+0
-388
tools/build_out/controllers/login.py
tools/build_out/controllers/login.py
+0
-108
tools/build_out/controllers/menu.py
tools/build_out/controllers/menu.py
+0
-156
tools/build_out/controllers/monitor.py
tools/build_out/controllers/monitor.py
+0
-197
tools/build_out/controllers/monitorEvm.py
tools/build_out/controllers/monitorEvm.py
+0
-78
tools/build_out/controllers/monitorImage.py
tools/build_out/controllers/monitorImage.py
+0
-78
tools/build_out/controllers/monitorLvgl.py
tools/build_out/controllers/monitorLvgl.py
+0
-78
tools/build_out/controllers/monitorSystem.py
tools/build_out/controllers/monitorSystem.py
+0
-78
tools/build_out/controllers/monitorWatch.py
tools/build_out/controllers/monitorWatch.py
+0
-86
tools/build_out/controllers/package.py
tools/build_out/controllers/package.py
+0
-192
tools/build_out/controllers/upload.py
tools/build_out/controllers/upload.py
+0
-155
tools/build_out/controllers/user.py
tools/build_out/controllers/user.py
+0
-83
tools/build_out/controllers/workbench.py
tools/build_out/controllers/workbench.py
+0
-95
tools/build_out/evue_photo.png
tools/build_out/evue_photo.png
+0
-0
tools/build_out/manager.py
tools/build_out/manager.py
+0
-56
tools/build_out/models/__init__.py
tools/build_out/models/__init__.py
+0
-72
tools/build_out/models/annex.py
tools/build_out/models/annex.py
+0
-68
tools/build_out/models/app.py
tools/build_out/models/app.py
+0
-177
tools/build_out/models/area.py
tools/build_out/models/area.py
+0
-114
tools/build_out/models/base.py
tools/build_out/models/base.py
+0
-48
tools/build_out/models/device.py
tools/build_out/models/device.py
+0
-112
tools/build_out/models/login.py
tools/build_out/models/login.py
+0
-96
tools/build_out/models/menu.py
tools/build_out/models/menu.py
+0
-92
tools/build_out/models/monitorEvm.py
tools/build_out/models/monitorEvm.py
+0
-65
tools/build_out/models/monitorImage.py
tools/build_out/models/monitorImage.py
+0
-65
tools/build_out/models/monitorLvgl.py
tools/build_out/models/monitorLvgl.py
+0
-71
tools/build_out/models/monitorSystem.py
tools/build_out/models/monitorSystem.py
+0
-76
tools/build_out/models/monitorWatch.py
tools/build_out/models/monitorWatch.py
+0
-50
tools/build_out/models/package.py
tools/build_out/models/package.py
+0
-108
tools/build_out/models/user.py
tools/build_out/models/user.py
+0
-108
tools/build_out/requirements.txt
tools/build_out/requirements.txt
+0
-42
tools/build_out/result.json
tools/build_out/result.json
+0
-1
tools/build_out/start.sh
tools/build_out/start.sh
+0
-14
tools/build_out/tests/database_migration.go
tools/build_out/tests/database_migration.go
+0
-92
tools/build_out/tests/database_migration.py
tools/build_out/tests/database_migration.py
+0
-196
tools/build_out/tests/go.mod
tools/build_out/tests/go.mod
+0
-5
tools/build_out/tests/go.sum
tools/build_out/tests/go.sum
+0
-2
tools/build_out/tests/http_interval.py
tools/build_out/tests/http_interval.py
+0
-131
tools/build_out/tests/test_sqlalchemy_sqlite.py
tools/build_out/tests/test_sqlalchemy_sqlite.py
+0
-100
tools/build_out/views/__init__.py
tools/build_out/views/__init__.py
+0
-97
tools/build_out/views/annex.py
tools/build_out/views/annex.py
+0
-78
tools/build_out/views/app.py
tools/build_out/views/app.py
+0
-180
tools/build_out/views/area.py
tools/build_out/views/area.py
+0
-107
tools/build_out/views/device.py
tools/build_out/views/device.py
+0
-116
tools/build_out/views/file.py
tools/build_out/views/file.py
+0
-293
tools/build_out/views/login.py
tools/build_out/views/login.py
+0
-101
tools/build_out/views/menu.py
tools/build_out/views/menu.py
+0
-307
tools/build_out/views/monitor.py
tools/build_out/views/monitor.py
+0
-356
tools/build_out/views/monitorEvm.py
tools/build_out/views/monitorEvm.py
+0
-64
tools/build_out/views/monitorImage.py
tools/build_out/views/monitorImage.py
+0
-64
tools/build_out/views/monitorLvgl.py
tools/build_out/views/monitorLvgl.py
+0
-64
tools/build_out/views/monitorSystem.py
tools/build_out/views/monitorSystem.py
+0
-64
tools/build_out/views/monitorWatch.py
tools/build_out/views/monitorWatch.py
+0
-64
tools/build_out/views/openapi.py
tools/build_out/views/openapi.py
+0
-693
tools/build_out/views/package.py
tools/build_out/views/package.py
+0
-93
tools/build_out/views/user.py
tools/build_out/views/user.py
+0
-102
tools/build_out/webcreator/__init__.py
tools/build_out/webcreator/__init__.py
+0
-1
tools/build_out/webcreator/event.py
tools/build_out/webcreator/event.py
+0
-65
tools/build_out/webcreator/log.py
tools/build_out/webcreator/log.py
+0
-32
tools/build_out/webcreator/response.py
tools/build_out/webcreator/response.py
+0
-114
tools/build_out/webcreator/utils/__init__.py
tools/build_out/webcreator/utils/__init__.py
+0
-188
tools/build_out/webcreator/utils/ccode.py
tools/build_out/webcreator/utils/ccode.py
+0
-68
tools/build_out/webcreator/utils/epk.py
tools/build_out/webcreator/utils/epk.py
+0
-267
tools/build_out/webcreator/utils/epk_2.0.py
tools/build_out/webcreator/utils/epk_2.0.py
+0
-234
tools/build_out/webcreator/utils/lib/eheatshrink.dll
tools/build_out/webcreator/utils/lib/eheatshrink.dll
+0
-0
tools/build_out/webcreator/utils/lib/libeheatshrink.so
tools/build_out/webcreator/utils/lib/libeheatshrink.so
+0
-0
tools/build_out/webcreator/utils/tools_epk_1.0.py
tools/build_out/webcreator/utils/tools_epk_1.0.py
+0
-223
tools/build_out/webcreator/webscoket.py
tools/build_out/webcreator/webscoket.py
+0
-99
No files found.
tools/build_out/.gitignore
deleted
100644 → 0
View file @
32df1548
logs/
\ No newline at end of file
tools/build_out/README.md
deleted
100644 → 0
View file @
32df1548
# Flask-Migrate
数据库迁移工具:使用Flask-Migrate数据库迁移框架可以保证数据库结构在发生变化时,改变数据库结构不至于丢失数据库的数据。
1.
安装
```
pip install Flask-Migrate
```
2.
demo
```
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
db = SQLAlchemy(app)
migrate = Migrate(app, db)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))
```
3.
初始化
完成文件创建后就可以进行初始化了,切换到文件所在文件夹下,使用命令
```
flask db init
```
这个命令中的
**db**
是在
*manager.py*
的
*migrate = Migrate(app, db)*
这行代码中声明命令行对象名称;
init是Migrate命令,表示初始化迁移数据库,运行完成后会在当前目录下创建一个migrations文件夹,用于进行迁移的数据库脚本都放在这里。
4.
迁移数据库
可以实现数据库迁移仓库创建:
```
flask db migrate -m "Initial migration."
```
此时生成一个versions文件夹:
从数据库中能看到alembic_version表。
5.
更新数据库
```
flask db upgrade
```
6.
总结
+
一是修改app部分代码,增加与Migrate相关的Command代码;
+
二是准备好数据模型,即model.py文件中的内容;
+
三是初始化和更新迁移数据库操作,即3次命令输入。
后面models目录下任何一个数据库表文件增加或者删除了字段,通过以下两步解决:
```
python manager.py db migrate
python manager.py db upgrade
```
详情参考:https://zhuanlan.zhihu.com/p/307612189
\ No newline at end of file
tools/build_out/application/__init__.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
sys
sys
.
path
.
append
(
".."
)
from
controllers
import
initConnect
initConnect
()
\ No newline at end of file
tools/build_out/application/app.py
deleted
100644 → 0
View file @
32df1548
# -*- coding: utf-8 -*-
import
sys
import
string
import
flask_restful
from
flask
import
Flask
,
abort
,
jsonify
from
flask_jwt_extended
import
(
JWTManager
)
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_marshmallow
import
Marshmallow
from
hashids
import
Hashids
from
webcreator.response
import
ResponseCode
,
response_result
from
webcreator.log
import
logger
from
.config
import
config
# 初始化app
app
=
Flask
(
__name__
)
# 初始化sqlalchemy
app
.
config
.
from_object
(
config
)
db
=
SQLAlchemy
(
app
)
# 初始化marshmallow
ma
=
Marshmallow
(
app
)
# 增加jwt校验
jwt
=
JWTManager
(
app
)
hash_ids
=
Hashids
(
salt
=
'hvwptlmj027d5quf'
,
min_length
=
8
,
alphabet
=
string
.
ascii_lowercase
+
string
.
digits
)
# hash函数
# 保留flask原生异常处理
handle_exception
=
app
.
handle_exception
handle_user_exception
=
app
.
handle_user_exception
# 过期令牌
@
jwt
.
expired_token_loader
def
expired_token_callback
(
jwt_header
,
jwt_payload
):
logger
.
info
(
jwt_payload
)
return
jsonify
({
'code'
:
401
,
'msg'
:
'token expired'
,
'data'
:
jwt_header
})
# 无效令牌
@
jwt
.
invalid_token_loader
def
invalid_token_callback
(
error
):
# we have to keep the argument here, since it's passed in by the caller internally
return
jsonify
({
'code'
:
401
,
'msg'
:
'invalid token'
,
'data'
:
error
})
# 校验失败
@
jwt
.
unauthorized_loader
def
unauthorized_callback
(
error
):
return
jsonify
({
'code'
:
401
,
'msg'
:
'unauthorized'
,
'data'
:
error
})
def
_custom_abort
(
http_status_code
,
**
kwargs
):
"""
自定义abort 400响应数据格式
"""
logger
.
info
(
kwargs
)
# if http_status_code == 400:
# message = kwargs.get('msg')
# if isinstance(message, dict):
# param, info = list(message.items())[0]
# data = '{}:{}!'.format(param, info)
# return abort(jsonify(response_result(ResponseCode.HTTP_INVAILD_REQUEST, data=data)))
# else:
# return abort(jsonify(response_result(ResponseCode.HTTP_INVAILD_REQUEST, data=message)))
return
abort
(
jsonify
({
'code'
:
http_status_code
,
'msg'
:
kwargs
}))
# return abort(http_status_code)
def
_access_control
(
response
):
"""
解决跨域请求
"""
# response.headers['Access-Control-Allow-Origin'] = '*'
# response.headers['Access-Control-Allow-Methods'] = 'GET,HEAD,PUT,PATCH,POST,DELETE'
# response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
# response.headers['Access-Control-Max-Age'] = 86400
response
.
headers
[
'Access-Control-Allow-Origin'
]
=
'*'
response
.
headers
[
'Access-Control-Allow-Methods'
]
=
'GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS'
response
.
headers
[
'Access-Control-Allow-Headers'
]
=
'Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With, Authorization'
response
.
headers
[
'Access-Control-Expose-Headers'
]
=
'Authorization'
response
.
headers
[
'Access-Control-Max-Age'
]
=
86400
response
.
headers
[
'Access-Control-Request-Headers'
]
=
'Origin, X-Requested-With, Content-Type, Accept, Authorization'
return
response
def
create_app
(
config
):
"""
创建app
"""
# 添加配置
app
.
config
.
from_object
(
config
)
# 解决跨域
app
.
after_request
(
_access_control
)
# 自定义abort 400 响应数据格式
flask_restful
.
abort
=
_custom_abort
# 数据库初始化
# db.app = app
db
.
init_app
(
app
)
# 创建表
db
.
create_all
()
# 注册蓝图
sys
.
path
.
append
(
".."
)
from
views
import
api_v1
app
.
register_blueprint
(
api_v1
,
url_prefix
=
'/api/v1'
)
# 使用flask原生异常处理程序
app
.
handle_exception
=
handle_exception
app
.
handle_user_exception
=
handle_user_exception
return
app
tools/build_out/application/config.py
deleted
100644 → 0
View file @
32df1548
# -*- coding: utf-8 -*-
import
os
import
multiprocessing
MODE
=
'develop'
# develop: 开发模式; production: 生产模式
class
ProductionConfig
(
object
):
EPK_DIR
=
"D:
\\
projects
\\
scriptiot
\\
evm_app_store_files
\\
epks"
UPLOAD_ROOT_DIR
=
"D:
\\
projects
\\
scriptiot
\\
evm_app_store_files"
UPLOAD_ALLOWED
=
set
([
'doc'
,
'docs'
,
'csv'
,
'xls'
,
'xlsx'
])
BIND
=
'127.0.0.1:3001'
WORKERS
=
multiprocessing
.
cpu_count
()
*
2
+
1
WORKER_CONNECTIONS
=
10000
BACKLOG
=
64
TIMEOUT
=
60
LOG_LEVEL
=
'INFO'
LOG_DIR_PATH
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'logs'
)
LOG_FILE_MAX_BYTES
=
1024
*
1024
*
100
LOG_FILE_BACKUP_COUNT
=
10
PID_FILE
=
'run.pid'
REDIS_HOST
=
'127.0.0.1'
REDIS_PORT
=
6379
REDIS_PASSWORD
=
''
REDIS_MAX_CONNECTIONS
=
100
JWT_HEADER_NAME
=
'Authorization'
JWT_HEADER_TYPE
=
'Bearer'
JWT_SECRET_KEY
=
'6UdxRgs2hvWpTLmj027d5vt7dXXQX'
JWT_ACCESS_TOKEN_EXPIRES
=
7200
JWT_REFRESH_TOKEN_EXPIRES
=
1800
MYSQL_DB
=
'qianjing_iot'
MYSQL_HOST
=
'127.0.0.1'
MYSQL_PORT
=
3306
MYSQL_USER
=
'debian-sys-maint'
MYSQL_PWD
=
'XMigC2B2uugnv18y'
SQLALCHEMY_BINDS
=
{
'app-store'
:
'sqlite:///../test.db'
}
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
def
__init__
(
self
):
super
()
.
__init__
()
self
.
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
class
DevelopConfig
(
object
):
EPK_DIR
=
"D:
\\
projects
\\
scriptiot
\\
evm_app_store_files
\\
epks"
UPLOAD_ROOT_DIR
=
"D:
\\
projects
\\
scriptiot
\\
evm_app_store_files"
UPLOAD_ALLOWED
=
set
([
'doc'
,
'docs'
,
'csv'
,
'xls'
,
'xlsx'
])
BIND
=
'127.0.0.1:3001'
WORKERS
=
2
WORKER_CONNECTIONS
=
1000
BACKLOG
=
64
TIMEOUT
=
30
LOG_LEVEL
=
'DEBUG'
LOG_DIR_PATH
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'logs'
)
LOG_FILE_MAX_BYTES
=
1024
*
1024
LOG_FILE_BACKUP_COUNT
=
1
PID_FILE
=
'run.pid'
REDIS_HOST
=
'127.0.0.1'
REDIS_PORT
=
6379
REDIS_PASSWORD
=
''
REDIS_MAX_CONNECTIONS
=
100
JWT_HEADER_NAME
=
'Authorization'
JWT_HEADER_TYPE
=
'Bearer'
JWT_SECRET_KEY
=
'6UdxRgs2hvWpTLmj027d5vt7dXXQX'
JWT_ACCESS_TOKEN_EXPIRES
=
7200
JWT_REFRESH_TOKEN_EXPIRES
=
1800
MYSQL_DB
=
'qianjing_iot'
MYSQL_HOST
=
'127.0.0.1'
MYSQL_PORT
=
3306
MYSQL_USER
=
'debian-sys-maint'
MYSQL_PWD
=
'XMigC2B2uugnv18y'
SQLALCHEMY_BINDS
=
{
'app-store'
:
'sqlite:///../evue-store.db'
}
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../evue-store.db'
SQLALCHEMY_TRACK_MODIFICATIONS
=
True
SQLALCHEMY_ECHO
=
False
def
__init__
(
self
):
super
()
.
__init__
()
self
.
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../evue-store.db'
if
MODE
==
'production'
:
config
=
ProductionConfig
()
else
:
config
=
DevelopConfig
()
tools/build_out/application/signal_manager.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
webcreator.event
import
PySignal
class
SignalManager
(
object
):
actionPostArea
=
PySignal
()
actionDeleteArea
=
PySignal
()
actionGetlistArea
=
PySignal
()
actionGetArea
=
PySignal
()
actionPutArea
=
PySignal
()
actionPostApp
=
PySignal
()
actionDeleteApp
=
PySignal
()
actionGetlistApp
=
PySignal
()
actionGetApp
=
PySignal
()
actionPutApp
=
PySignal
()
actionGetlistPackage
=
PySignal
()
actionGetPackage
=
PySignal
()
actionPostUser
=
PySignal
()
actionDeleteUser
=
PySignal
()
actionGetlistUser
=
PySignal
()
actionGetUser
=
PySignal
()
actionPutUser
=
PySignal
()
actionPostLogin
=
PySignal
()
actionGetlistLogin
=
PySignal
()
actionGetLogin
=
PySignal
()
actionPostDevice
=
PySignal
()
actionDeleteDevice
=
PySignal
()
actionGetlistDevice
=
PySignal
()
actionGetDevice
=
PySignal
()
actionPutDevice
=
PySignal
()
actionDeleteAnnex
=
PySignal
()
actionGetlistAnnex
=
PySignal
()
actionGetAnnex
=
PySignal
()
actionGetlistMonitorwatch
=
PySignal
()
actionGetMonitorwatch
=
PySignal
()
actionGetlistMonitorsystem
=
PySignal
()
actionGetMonitorsystem
=
PySignal
()
actionGetlistMonitorlvgl
=
PySignal
()
actionGetMonitorlvgl
=
PySignal
()
actionGetlistMonitorimage
=
PySignal
()
actionGetMonitorimage
=
PySignal
()
actionGetlistMonitorevm
=
PySignal
()
actionGetMonitorevm
=
PySignal
()
actionTreelist
=
PySignal
()
actionTreenodes
=
PySignal
()
actionUpdatebyid
=
PySignal
()
actionMenuCreate
=
PySignal
()
actionUpdateSort
=
PySignal
()
actionMenuBatch
=
PySignal
()
# file manager api
actionGetFileInit
=
PySignal
()
actionGetFileContent
=
PySignal
()
actionGetFileTree
=
PySignal
()
actionGetFileDisk
=
PySignal
()
actionGetFileDown
=
PySignal
()
actionGetFilePreview
=
PySignal
()
actionPostFileUpdate
=
PySignal
()
actionPostFileUpload
=
PySignal
()
actionPostFileDelete
=
PySignal
()
actionPostFileCreate
=
PySignal
()
actionPostFileCreateDir
=
PySignal
()
actionPostFilePaste
=
PySignal
()
# api
actionPostAppReview
=
PySignal
()
actionGetLauncher
=
PySignal
()
actionSetLauncher
=
PySignal
()
actionGetApplication
=
PySignal
()
actionGetAppInfo
=
PySignal
()
actionGetAppList
=
PySignal
()
actionGetEpk
=
PySignal
()
actionApplicationBuild
=
PySignal
()
actionCheckVersion
=
PySignal
()
# workbench
actionWorkbench
=
PySignal
()
def
__init__
(
self
):
super
()
.
__init__
()
signalManager
=
SignalManager
()
\ No newline at end of file
tools/build_out/controllers/__init__.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-28 17:07:05
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
controllers
\
__init__.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.signal_manager
import
signalManager
from
.area
import
areaManager
from
.app
import
appManager
from
.package
import
packageManager
from
.user
import
userManager
from
.login
import
loginManager
from
.device
import
deviceManager
from
.annex
import
annexManager
from
.monitorWatch
import
monitorWatchManager
from
.monitorSystem
import
monitorSystemManager
from
.monitorLvgl
import
monitorLvglManager
from
.monitorImage
import
monitorImageManager
from
.monitorEvm
import
monitorEvmManager
from
.menu
import
menuManager
from
.api
import
appReview
,
buildAppResource
from
.file
import
fileManager
from
.workbench
import
workbenchResource
def
initConnect
():
signalManager
.
actionPostArea
.
connect
(
areaManager
.
post
)
signalManager
.
actionDeleteArea
.
connect
(
areaManager
.
delete
)
signalManager
.
actionGetlistArea
.
connect
(
areaManager
.
getList
)
signalManager
.
actionGetArea
.
connect
(
areaManager
.
get
)
signalManager
.
actionPutArea
.
connect
(
areaManager
.
put
)
signalManager
.
actionPostApp
.
connect
(
appManager
.
post
)
signalManager
.
actionDeleteApp
.
connect
(
appManager
.
delete
)
signalManager
.
actionGetlistApp
.
connect
(
appManager
.
getList
)
signalManager
.
actionGetApp
.
connect
(
appManager
.
get
)
signalManager
.
actionPutApp
.
connect
(
appManager
.
put
)
signalManager
.
actionGetlistPackage
.
connect
(
packageManager
.
getList
)
signalManager
.
actionGetPackage
.
connect
(
packageManager
.
get
)
signalManager
.
actionPostUser
.
connect
(
userManager
.
post
)
signalManager
.
actionDeleteUser
.
connect
(
userManager
.
delete
)
signalManager
.
actionGetlistUser
.
connect
(
userManager
.
getList
)
signalManager
.
actionGetUser
.
connect
(
userManager
.
get
)
signalManager
.
actionPutUser
.
connect
(
userManager
.
put
)
signalManager
.
actionPostLogin
.
connect
(
loginManager
.
post
)
signalManager
.
actionGetlistLogin
.
connect
(
loginManager
.
getList
)
signalManager
.
actionGetLogin
.
connect
(
loginManager
.
get
)
signalManager
.
actionPostDevice
.
connect
(
deviceManager
.
post
)
signalManager
.
actionDeleteDevice
.
connect
(
deviceManager
.
delete
)
signalManager
.
actionGetlistDevice
.
connect
(
deviceManager
.
getList
)
signalManager
.
actionGetDevice
.
connect
(
deviceManager
.
get
)
signalManager
.
actionPutDevice
.
connect
(
deviceManager
.
put
)
signalManager
.
actionDeleteAnnex
.
connect
(
annexManager
.
delete
)
signalManager
.
actionGetlistAnnex
.
connect
(
annexManager
.
getList
)
signalManager
.
actionGetAnnex
.
connect
(
annexManager
.
get
)
signalManager
.
actionGetlistMonitorwatch
.
connect
(
monitorWatchManager
.
getList
)
signalManager
.
actionGetMonitorwatch
.
connect
(
monitorWatchManager
.
get
)
signalManager
.
actionGetlistMonitorsystem
.
connect
(
monitorSystemManager
.
getList
)
signalManager
.
actionGetMonitorsystem
.
connect
(
monitorSystemManager
.
get
)
signalManager
.
actionGetlistMonitorlvgl
.
connect
(
monitorLvglManager
.
getList
)
signalManager
.
actionGetMonitorlvgl
.
connect
(
monitorLvglManager
.
get
)
signalManager
.
actionGetlistMonitorimage
.
connect
(
monitorImageManager
.
getList
)
signalManager
.
actionGetMonitorimage
.
connect
(
monitorImageManager
.
get
)
signalManager
.
actionGetlistMonitorevm
.
connect
(
monitorEvmManager
.
getList
)
signalManager
.
actionGetMonitorevm
.
connect
(
monitorEvmManager
.
get
)
signalManager
.
actionTreelist
.
connect
(
menuManager
.
treeList
)
signalManager
.
actionTreenodes
.
connect
(
menuManager
.
treeNodes
)
signalManager
.
actionUpdatebyid
.
connect
(
menuManager
.
updateById
)
signalManager
.
actionMenuCreate
.
connect
(
menuManager
.
create
)
signalManager
.
actionUpdateSort
.
connect
(
menuManager
.
updateSort
)
signalManager
.
actionMenuBatch
.
connect
(
menuManager
.
batch
)
# file manager api
signalManager
.
actionGetFileContent
.
connect
(
fileManager
.
content
)
signalManager
.
actionGetFileDisk
.
connect
(
fileManager
.
disk
)
signalManager
.
actionGetFileDown
.
connect
(
fileManager
.
download
)
signalManager
.
actionGetFileInit
.
connect
(
fileManager
.
initialize
)
signalManager
.
actionGetFilePreview
.
connect
(
fileManager
.
preview
)
signalManager
.
actionGetFileTree
.
connect
(
fileManager
.
tree
)
signalManager
.
actionPostFileUpdate
.
connect
(
fileManager
.
update_file
)
signalManager
.
actionPostFileUpload
.
connect
(
fileManager
.
upload
)
signalManager
.
actionPostFileDelete
.
connect
(
fileManager
.
delete
)
signalManager
.
actionPostFileCreate
.
connect
(
fileManager
.
create_file
)
signalManager
.
actionPostFileCreateDir
.
connect
(
fileManager
.
create_dir
)
signalManager
.
actionPostFilePaste
.
connect
(
fileManager
.
paste
)
# api
signalManager
.
actionPostAppReview
.
connect
(
appReview
.
post
)
signalManager
.
actionSetLauncher
.
connect
(
appReview
.
get
)
signalManager
.
actionGetLauncher
.
connect
(
appReview
.
getLauncher
)
signalManager
.
actionApplicationBuild
.
connect
(
buildAppResource
.
post
)
signalManager
.
actionGetAppList
.
connect
(
appReview
.
getAppList
)
signalManager
.
actionGetApplication
.
connect
(
appReview
.
getApp
)
signalManager
.
actionGetEpk
.
connect
(
appReview
.
getDownloadFile
)
signalManager
.
actionCheckVersion
.
connect
(
appReview
.
checkAppVersion
)
signalManager
.
actionWorkbench
.
connect
(
workbenchResource
.
get
)
tools/build_out/controllers/annex.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
models.annex
import
AnnexModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
AnnexResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
AnnexModel
.
is_delete
==
False
,
AnnexModel
.
uuid
==
uuid
]
result
=
AnnexModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[
AnnexModel
.
is_delete
==
False
]
result
=
AnnexModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AnnexModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
result
=
AnnexModel
.
query
.
filter
(
AnnexModel
.
app
==
params
.
get
(
'app'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
result
=
AnnexModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
AnnexModel
.
query
.
filter
(
AnnexModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
AnnexModel
.
query
.
filter
(
AnnexModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
annexManager
=
AnnexResource
()
\ No newline at end of file
tools/build_out/controllers/api.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-12 11:14:48
LastEditTime: 2021-07-22 18:11:13
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
controllers
\a
ppi.py
'''
import
os
import
re
import
json
import
shutil
from
pprint
import
pprint
from
pathlib
import
Path
import
urllib
from
datetime
import
datetime
from
urllib
import
parse
,
request
from
urllib.parse
import
urlparse
,
urljoin
from
application.app
import
db
,
config
from
models.device
import
DeviceModel
from
models.annex
import
AnnexModel
from
models.app
import
AppModel
from
models.user
import
UserModel
from
models.package
import
PackageModel
from
webcreator.log
import
logger
from
webcreator.utils
import
ThreadMaker
from
webcreator.utils.epk
import
EpkApp
from
webcreator.response
import
ResponseCode
@
ThreadMaker
def
update_download_information
(
ip
,
id
):
params
=
{
'ak'
:
'aZEAgYG8wKuLd6DS9BmCloGtfnGGkRMn'
,
'coor'
:
'bd09ll'
}
parameters
=
urllib
.
parse
.
urlencode
(
params
)
headers
=
{
'User-Agent'
:
'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'
}
if
ip
!=
'127.0.0.1'
:
params
.
update
({
'ip'
:
ip
})
parameters
=
urllib
.
parse
.
urlencode
(
params
)
url
=
'http://api.map.baidu.com/location/ip'
req
=
request
.
Request
(
url
=
'
%
s
%
s
%
s'
%
(
url
,
'?'
,
parameters
),
headers
=
headers
)
ret
=
request
.
urlopen
(
req
)
.
read
()
jsonData
=
json
.
loads
(
ret
)
logger
.
info
(
jsonData
)
if
(
0
!=
jsonData
[
'status'
]):
return
None
pack
=
PackageModel
.
query
.
filter
(
PackageModel
.
id
==
id
)
.
one_or_none
()
if
pack
:
pack
.
address
=
jsonData
[
'address'
]
pack
.
ip
=
ip
pack
.
remarks
=
json
.
dumps
(
jsonData
[
'content'
],
ensure_ascii
=
False
)
db
.
session
.
commit
()
class
BuildAppResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
post
(
self
,
params
,
files
=
[]):
logger
.
info
(
params
)
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
params
.
get
(
"access_key"
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
host_url
=
params
.
get
(
"host_url"
)
if
not
host_url
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
params
.
update
({
'app_icon'
:
params
.
get
(
'app_icon'
,
''
),
'create_by'
:
user
.
id
,
'create_at'
:
datetime
.
now
(),
'update_by'
:
user
.
id
,
'update_at'
:
datetime
.
now
(),
})
props
=
dict
()
for
p
in
params
:
if
hasattr
(
AppModel
,
p
):
props
[
p
]
=
params
[
p
]
# logger.info(props)
# pprint(props)
app
=
AppModel
(
**
props
)
db
.
session
.
add
(
app
)
db
.
session
.
commit
()
dir_format
=
"{}-{}-{}"
.
format
(
app
.
app_name
,
app
.
app_version
,
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
))
target_dir
=
Path
(
config
.
EPK_DIR
)
.
joinpath
(
user
.
account
)
.
joinpath
(
dir_format
)
dest_dir
=
target_dir
.
joinpath
(
"src"
)
if
not
dest_dir
.
exists
():
os
.
makedirs
(
dest_dir
.
resolve
()
.
as_posix
())
for
target_file
in
files
:
filename
=
os
.
path
.
basename
(
target_file
)
name
,
suffix
=
os
.
path
.
splitext
(
filename
)
name
=
re
.
sub
(
r"_\d{14}$"
,
""
,
name
)
dst_file
=
dest_dir
.
joinpath
(
name
+
suffix
)
shutil
.
copy
(
os
.
path
.
normpath
(
target_file
),
dst_file
.
resolve
()
.
as_posix
())
res
=
AnnexModel
(
app
=
app
.
id
,
title
=
filename
,
path
=
dst_file
.
relative_to
(
config
.
UPLOAD_ROOT_DIR
)
.
as_posix
(),
size
=
dst_file
.
stat
()
.
st_size
,
create_by
=
user
.
id
,
create_at
=
datetime
.
now
(),
update_by
=
user
.
id
,
update_at
=
datetime
.
now
())
db
.
session
.
add
(
res
)
db
.
session
.
flush
()
db
.
session
.
commit
()
# 打包成EPK文件
app_info
=
{}
params
=
{
'appName'
:
app
.
app_name
,
'appDir'
:
dest_dir
.
resolve
()
.
as_posix
(),
'appVersion'
:
app
.
app_version
,
'output'
:
target_dir
.
resolve
()
.
as_posix
()
}
if
user
.
role
==
1
:
params
[
'algorithm'
]
=
"h"
else
:
params
[
'algorithm'
]
=
"zlib"
epk
=
EpkApp
(
**
params
)
app_info
=
epk
.
pack
()
app_info
[
'md5'
]
=
str
(
app_info
[
'md5'
])
# 更新数据库对应文件路径
# 将文件拷贝过去后,需要重新更新数据库文件记录
epk_path
=
target_dir
.
joinpath
(
"{}.epk"
.
format
(
app
.
app_name
))
.
relative_to
(
config
.
UPLOAD_ROOT_DIR
)
.
as_posix
()
app
.
download_url
=
epk_path
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
app
==
app
.
id
)
.
one_or_none
()
if
result
:
result
.
algorithm
=
params
[
'algorithm'
]
result
.
app_path
=
epk_path
result
.
package_info
=
json
.
dumps
(
app_info
,
ensure_ascii
=
False
)
result
.
update_by
=
user
result
.
update_at
=
datetime
.
now
()
db
.
session
.
commit
()
else
:
result
=
PackageModel
(
app
=
app
.
id
,
file_path
=
epk_path
,
package_info
=
json
.
dumps
(
app_info
,
ensure_ascii
=
False
),
algorithm
=
params
[
'algorithm'
],
app_version
=
params
.
get
(
"app_version"
,
'1.0.0'
),
source
=
1
,
create_by
=
user
.
id
,
create_at
=
datetime
.
now
(),
update_by
=
user
.
id
,
update_at
=
datetime
.
now
())
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
target_dir
.
joinpath
(
"epk.json"
)
.
write_text
(
json
.
dumps
(
app
.
to_dict
(),
ensure_ascii
=
False
))
# with open(os.sep.join([target_dir, "epk.json"]), "w") as f:
# json.dump(app.to_dict(), f)
return
{
'app_name'
:
app
.
app_name
,
'app_file'
:
"{}.epk"
.
format
(
app
.
app_name
),
'app_url'
:
urljoin
(
host_url
,
epk_path
)
},
ResponseCode
.
HTTP_SUCCESS
buildAppResource
=
BuildAppResource
()
class
AppReview
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
params
,
jwt
=
{}):
logger
.
info
(
params
)
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
"uuid"
))
.
one_or_none
()
if
not
user
:
return
None
,
ResponseCode
.
USER_NOT_EXISTS
app
=
AppModel
.
query
.
filter
(
AppModel
.
launcher
==
"yes"
,
AppModel
.
create_by
==
user
.
id
,
AppModel
.
is_delete
==
False
)
.
one_or_none
()
if
app
:
app
.
launcher
=
"no"
db
.
session
.
commit
()
app
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
params
.
get
(
"app"
),
AppModel
.
create_by
==
user
.
id
,
AppModel
.
is_delete
==
False
)
.
one_or_none
()
if
not
app
:
return
None
,
ResponseCode
.
APPLICATION_NOT_EXISTS
app
.
launcher
=
"yes"
app
.
update_at
=
datetime
.
now
()
app
.
update_by
=
user
.
id
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
getApp
(
self
,
params
,
jwt
=
{}):
app
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
params
.
get
(
"uuid"
),
AppModel
.
is_delete
==
False
)
.
one_or_none
()
if
not
app
:
return
None
,
ResponseCode
.
APPLICATION_NOT_EXISTS
return
app
,
ResponseCode
.
HTTP_SUCCESS
def
checkAppVersion
(
self
,
params
,
jwt
=
{}):
app
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
params
.
get
(
"uuid"
),
AppModel
.
is_delete
==
False
)
.
one_or_none
()
if
not
app
:
return
None
,
ResponseCode
.
APPLICATION_NOT_EXISTS
pack
=
PackageModel
.
query
.
filter
(
PackageModel
.
app
==
app
.
id
,
PackageModel
.
is_delete
==
False
)
.
order_by
(
PackageModel
.
create_at
.
desc
())
.
one_or_none
()
if
not
pack
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
pack
!=
params
.
get
(
"app_version"
):
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_SUCCESS
def
getLauncher
(
self
,
params
,
jwt
=
{}):
device
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
imei
==
params
.
get
(
"imei"
),
DeviceModel
.
is_delete
==
False
)
.
one_or_none
()
if
not
device
:
return
None
,
ResponseCode
.
DEVICE_NOT_EXISTS
app
=
AppModel
.
query
.
filter
(
AppModel
.
launcher
==
"yes"
,
AppModel
.
create_by
==
device
.
create_by
,
AppModel
.
is_delete
==
False
)
.
one_or_none
()
if
not
app
:
return
None
,
ResponseCode
.
APPLICATION_NOT_EXISTS
# 根据app找到EPK文件,读取出二进制数据,返回
target_file
=
Path
(
config
.
UPLOAD_ROOT_DIR
)
.
joinpath
(
app
.
download_url
)
if
not
target_file
.
exists
():
return
None
,
ResponseCode
.
APPLICATION_NOT_EXISTS
return
target_file
,
ResponseCode
.
HTTP_SUCCESS
def
getAppList
(
self
,
params
,
jwt
=
{}):
filters
=
[
AppModel
.
is_delete
==
False
]
logger
.
info
(
params
)
if
params
.
get
(
"review"
):
filters
.
append
(
AppModel
.
app_review
==
params
.
get
(
"review"
))
if
params
.
get
(
"category"
):
filters
.
append
(
AppModel
.
category
==
params
.
get
(
"category"
))
apps
=
AppModel
.
query
.
filter
(
*
filters
)
.
all
()
if
not
apps
:
return
None
,
ResponseCode
.
APPLICATION_NOT_EXISTS
return
apps
,
ResponseCode
.
HTTP_SUCCESS
def
post
(
self
,
app
,
review
,
jwt
=
{}):
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
"uuid"
))
.
one_or_none
()
if
not
user
:
return
None
,
ResponseCode
.
USER_NOT_EXISTS
app
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
app
)
.
one_or_none
()
if
not
app
:
return
None
,
ResponseCode
.
APPLICATION_NOT_EXISTS
app
.
app_review
=
review
app
.
update_at
=
datetime
.
now
()
app
.
update_by
=
user
.
id
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
getDownloadFile
(
self
,
params
,
jwt
=
{}):
# 流程如下:
# 获取前端传来的应用UUID和IMEI
# 根据应用UUID查找应用信息,找不到返回失败信息
# 如果应用ID是evue_launcher,则进行如下处理
# 遍历系统所有应用,将相关应用根据4个一组拼接到一个数组里面去
# 最后将这些信息导出为一个JSON文件
# 将evue_launcher.evue和evue_dock.evue以及相关资源文件进行打包
# 以上文件全部是复制处理,最后根据格式生成文件夹,将epk文件写入到这里
# 读取这个epk文件,以encoding='utf8'格式返回字节流
# 否则就是普通应用
# 查找出这个应用路径以及依赖文件
# 将这些文件进行打包
# 读取这个epk文件,以encoding='utf8'格式返回字节流
# 此次下载将生成一次下载记录
# 当前还没有校验前端传来的IMEI是否是合法的
# 根据IMEI查找设备,根据设备查找用户,根据用户查找应用
app
=
[]
# 根据IMEI查找设备
# device = Device.select().where(imei=data.get("imei")).first()
# logger.info(data)
# if not device:
# return False, "device not found"
# if not device.create_by:
# return False, "create user is null"
if
params
.
get
(
"byId"
):
# 通过id下载应用
app
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
params
.
get
(
"uuid"
))
.
one_or_none
()
if
not
app
:
return
False
,
ResponseCode
.
APPLICATION_NOT_EXISTS
else
:
apps
=
AppModel
.
query
.
filter
(
AppModel
.
app_name
==
params
.
get
(
"name"
))
.
order_by
(
AppModel
.
create_at
.
desc
())
.
all
()
if
len
(
apps
)
>
1
:
app
=
AppModel
.
query
.
filter
(
AppModel
.
app_name
==
params
.
get
(
"name"
))
.
order_by
(
AppModel
.
create_at
.
desc
())
.
one_or_none
()
if
not
app
:
return
False
,
ResponseCode
.
APPLICATION_NOT_EXISTS
epk_path
=
Path
(
config
.
UPLOAD_ROOT_DIR
)
.
joinpath
(
app
.
download_url
)
if
not
epk_path
.
exists
():
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
# pack = PackageModel(app=app.id, app_version=app.app_version, imei=params.get("imei"))
# db.session.add(pack)
# db.session.commit()
# if pack:
# update_download_information(params.get('real_ip', '127.0.0.1'), pack.id)
return
epk_path
,
ResponseCode
.
HTTP_NOT_FOUND
appReview
=
AppReview
()
\ No newline at end of file
tools/build_out/controllers/app.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
os
import
re
import
json
import
shutil
from
pathlib
import
Path
from
datetime
import
datetime
from
sqlalchemy
import
func
,
distinct
from
application.app
import
db
from
models.package
import
PackageModel
from
models.annex
import
AnnexModel
from
models.user
import
UserModel
from
models.app
import
AppModel
from
application.config
import
config
from
webcreator
import
utils
from
webcreator.utils.epk
import
EpkApp
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
@
utils
.
ThreadMaker
def
update_information
(
ip
,
record_id
):
try
:
jsonData
=
utils
.
get_location_by_ip
(
ip
)
if
(
0
!=
jsonData
[
'status'
]):
return
None
pack
=
PackageModel
.
query
.
filter
(
PackageModel
.
id
==
record_id
)
.
first
()
pack
.
geo_location
=
json
.
dumps
(
jsonData
,
ensure_ascii
=
False
)
pack
.
ip
=
ip
db
.
session
.
commit
()
except
Exception
as
e
:
logger
.
error
(
e
)
class
AppResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
jwt
):
# handle business
filters
=
[
AppModel
.
is_delete
==
False
,
AppModel
.
uuid
==
uuid
]
app
=
AppModel
.
query
.
filter
(
*
filters
)
.
one_or_none
()
if
not
app
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
'uuid'
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# 根据app查询应用,获取应用有哪些文件
# 按格式创建文件夹,将这些文件移动到这个文件夹
# 将这些零散文件进行打包
# 更新数据库对应文件的路径
source_files
=
AnnexModel
.
query
.
filter
(
AnnexModel
.
app
==
app
.
id
)
.
all
()
if
not
source_files
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
now_str
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
)
dirname
=
"{}-{}-{}-{}"
.
format
(
app
.
app_name
,
app
.
app_version
,
app
.
category
,
now_str
)
target_dir
=
Path
(
config
.
UPLOAD_ROOT_DIR
)
.
joinpath
(
config
.
EPK_DIR
)
.
joinpath
(
dirname
)
dest_dir
=
target_dir
.
joinpath
(
"src"
)
if
not
dest_dir
.
exists
():
os
.
makedirs
(
dest_dir
.
resolve
()
.
as_posix
())
app_files
=
[]
for
sf
in
source_files
:
target_file
=
Path
(
sf
.
path
)
if
not
target_file
.
exists
():
target_file
=
Path
(
config
.
UPLOAD_ROOT_DIR
)
.
joinpath
(
sf
.
path
)
name
=
re
.
sub
(
r"_\d{14}$"
,
""
,
target_file
.
stem
)
suffix
=
target_file
.
suffix
dst_file
=
dest_dir
.
joinpath
(
name
+
suffix
)
shutil
.
copy
(
target_file
.
resolve
()
.
as_posix
(),
dst_file
.
resolve
()
.
as_posix
())
app_files
.
append
([
sf
.
id
,
dst_file
.
resolve
()
.
as_posix
()])
target_dir
.
joinpath
(
"epk.json"
)
.
write_text
(
json
.
dumps
(
app
.
to_dict
(),
ensure_ascii
=
False
),
encoding
=
"utf-8"
)
# 打包成EPK文件
app_info
=
{}
params
=
{
'appName'
:
app
.
app_name
,
'appDir'
:
dest_dir
.
resolve
()
.
as_posix
(),
'appVersion'
:
app
.
app_version
,
'output'
:
target_dir
.
resolve
()
.
as_posix
()
}
if
user
.
role
==
1
:
params
[
'algorithm'
]
=
"h"
epk
=
EpkApp
(
**
params
)
app_info
=
epk
.
pack
()
app_info
[
'md5'
]
=
str
(
app_info
[
'md5'
])
# 更新数据库对应文件路径
# 将文件拷贝过去后,需要重新更新数据库文件记录
epk_path
=
target_dir
.
joinpath
(
"{}.epk"
.
format
(
app
.
app_name
))
.
relative_to
(
config
.
UPLOAD_ROOT_DIR
)
.
as_posix
()
package
=
PackageModel
.
query
.
filter
(
PackageModel
.
app
==
app
.
id
)
.
one_or_none
()
if
package
:
package
.
app_path
=
epk_path
package
.
app_info
=
app_info
package
.
update_by
=
user
.
id
package
.
update_at
=
datetime
.
now
()
db
.
session
.
commit
()
# 新增一条AppLogs
package
=
PackageModel
(
app
=
app
.
app_name
,
app_version
=
app
.
app_version
,
file_path
=
epk_path
,
package_info
=
json
.
dumps
(
app_info
,
ensure_ascii
=
False
),
create_by
=
user
.
id
,
create_at
=
datetime
.
now
())
db
.
session
.
add
(
package
)
app
.
update_by
=
user
.
id
app
.
update_at
=
datetime
.
now
()
app
.
app_file_size
=
app_info
.
get
(
"buff_length"
,
0
)
app
.
download_url
=
epk_path
db
.
session
.
commit
()
return
{
'app_name'
:
app
.
app_name
,
'app_path'
:
epk_path
},
ResponseCode
.
HTTP_SUCCESS
def
getList
(
self
,
params
,
jwt
):
# 默认只查询资源包
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
'uuid'
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
temp
=
{
"is_delete"
:
False
}
filters
=
[
AppModel
.
is_delete
==
False
]
if
user
.
role
!=
1
:
filters
.
append
(
AppModel
.
create_by
==
user
.
id
)
temp
.
update
({
"create_by"
:
user
.
id
})
if
"scope"
in
params
and
params
.
get
(
"scope"
)
==
"list"
:
result
=
AppModel
.
query
.
filter_by
(
**
temp
)
.
order_by
(
AppModel
.
create_at
.
desc
())
temp
=
[]
for
item
in
result
:
temp
.
append
({
"uuid"
:
item
.
uuid
,
"app_name"
:
item
.
app_name
})
return
temp
,
ResponseCode
.
HTTP_SUCCESS
elif
"scope"
in
params
and
params
.
get
(
"scope"
)
==
"distinct"
:
result
=
db
.
session
.
query
(
AppModel
,
func
.
count
(
distinct
(
AppModel
.
name
)))
.
all
()
temp
=
[]
for
item
in
result
:
temp
.
append
(
item
)
return
temp
,
ResponseCode
.
HTTP_SUCCESS
for
p
in
params
:
if
hasattr
(
AppModel
,
p
)
and
params
[
p
]
!=
None
:
temp
[
p
]
=
params
[
p
]
result
=
AppModel
.
query
.
filter_by
(
**
temp
)
.
order_by
(
AppModel
.
create_at
.
desc
())
.
paginate
(
params
.
get
(
"page"
,
1
),
params
.
get
(
"pageSize"
,
15
),
error_out
=
False
)
# result = AppModel.query.filter(*filters).order_by(AppModel.create_at.desc()).paginate(params.get('page', 1), params.get('pageSize', 15), error_out=False)
if
result
.
total
and
len
(
result
.
items
):
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
# 应用打包
# 插入一条打包记录
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
'uuid'
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# 判断下app是否存在
# result = Apps.select(app_name=data.get("app_name"), is_delete=False).count()
# if result < 1:
# return False, "app_name has been exists."
algorithm
=
params
.
get
(
'algorithm'
)
if
algorithm
:
params
.
pop
(
"algorithm"
)
params
.
update
({
'app_icon'
:
params
[
"app_icon"
]
.
replace
(
config
.
UPLOAD_ROOT_DIR
,
""
),
'create_by'
:
user
.
id
,
'create_at'
:
datetime
.
now
(),
'update_by'
:
user
.
id
,
'update_at'
:
datetime
.
now
(),
})
app_files
=
[]
epk_path
=
Path
(
""
)
if
params
.
get
(
"fileList"
):
app_files
=
params
.
get
(
"fileList"
)
params
.
pop
(
"fileList"
)
epk_path
=
params
.
get
(
"epk_path"
)
params
.
pop
(
"epk_path"
)
if
params
.
get
(
"logo"
):
params
.
pop
(
"logo"
)
real_ip
=
params
.
get
(
"real_ip"
,
None
)
if
real_ip
:
params
.
pop
(
"real_ip"
)
app
=
AppModel
(
**
params
)
db
.
session
.
add
(
app
)
db
.
session
.
commit
()
logger
.
info
(
params
)
# 在EPK目录下生成JSON文件
epk_path
.
joinpath
(
"epk.json"
)
.
write_text
(
json
.
dumps
(
app
.
to_dict
(),
ensure_ascii
=
False
),
encoding
=
"utf-8"
)
# with open(os.sep.join([os.path.dirname(epk_path), "epk.json"]), "w") as f:
# json.dump(app.to_dict(), f)
for
a
in
app_files
:
t
=
Path
(
config
.
UPLOAD_ROOT_DIR
)
.
joinpath
(
a
)
res
=
AnnexModel
(
app
=
app
.
id
,
title
=
t
.
name
,
path
=
a
,
size
=
t
.
stat
()
.
st_size
,
create_by
=
user
.
id
,
create_at
=
datetime
.
now
(),
update_by
=
user
.
id
,
update_at
=
datetime
.
now
())
db
.
session
.
add
(
res
)
db
.
session
.
flush
()
db
.
session
.
commit
()
app_info
=
{}
params
=
{
'appName'
:
app
.
app_name
,
'appDir'
:
epk_path
.
resolve
()
.
as_posix
(),
'appVersion'
:
app
.
app_version
,
'output'
:
epk_path
.
parent
.
resolve
()
.
as_posix
()
}
if
user
.
role
==
1
:
params
[
'algorithm'
]
=
"h"
if
algorithm
:
params
[
'algorithm'
]
=
algorithm
epk
=
EpkApp
(
**
params
)
app_info
=
epk
.
pack
()
epk_filename
=
epk_path
.
parent
.
relative_to
(
config
.
UPLOAD_ROOT_DIR
)
.
joinpath
(
"{}.epk"
.
format
(
app
.
app_name
))
.
as_posix
()
if
app_info
:
app_info
[
'md5'
]
=
str
(
app_info
[
'md5'
])
app
.
app_file_size
=
app_info
.
get
(
"buff_length"
)
app
.
download_url
=
epk_filename
db
.
session
.
commit
()
package
=
PackageModel
(
app
=
app
.
id
,
file_path
=
epk_filename
,
app_version
=
params
.
get
(
"appVersion"
),
package_info
=
json
.
dumps
(
app_info
,
ensure_ascii
=
False
),
source
=
1
,
create_by
=
user
.
id
,
create_at
=
datetime
.
now
(),
update_by
=
user
.
id
,
update_at
=
datetime
.
now
(),
remarks
=
json
.
dumps
(
params
,
ensure_ascii
=
False
))
db
.
session
.
add
(
package
)
db
.
session
.
commit
()
update_information
(
real_ip
,
package
.
id
)
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
'uuid'
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# handle business
app
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
uuid
)
.
first
()
if
not
app
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
# 更新文件
if
params
.
get
(
"app_files"
):
for
a
in
params
.
get
(
"app_files"
):
res
=
AnnexModel
(
app
=
app
.
id
,
title
=
a
.
get
(
"filename"
),
path
=
a
.
get
(
"filepath"
),
size
=
a
.
get
(
"filesize"
),
create_by
=
user
.
id
,
create_at
=
datetime
.
now
(),
update_by
=
user
.
id
,
update_at
=
datetime
.
now
())
db
.
session
.
add
(
res
)
db
.
session
.
flush
()
db
.
session
.
commit
()
params
.
pop
(
"app_files"
)
# 更新icon
if
params
.
get
(
"app_icon"
)
and
isinstance
(
params
.
get
(
"app_icon"
),
dict
):
condition
=
{
'update_by'
:
user
.
id
,
'update_at'
:
datetime
.
now
()
}
if
params
.
get
(
"app_icon"
)
.
get
(
"filename"
):
condition
.
update
({
"title"
:
params
.
get
(
"app_icon"
)
.
get
(
"filename"
)})
if
params
.
get
(
"app_icon"
)
.
get
(
"filepath"
):
condition
.
update
({
"path"
:
params
.
get
(
"app_icon"
)
.
get
(
"filepath"
)})
if
params
.
get
(
"app_icon"
)
.
get
(
"filesize"
):
condition
.
update
({
"size"
:
params
.
get
(
"app_icon"
)
.
get
(
"filesize"
)})
params
.
pop
(
"app_icon"
)
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
app
,
key
,
value
)
app
.
update_by
=
user
.
id
app
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
appManager
=
AppResource
()
\ No newline at end of file
tools/build_out/controllers/area.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
models.area
import
AreaModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
AreaResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
AreaModel
.
is_delete
==
False
,
AreaModel
.
uuid
==
uuid
]
result
=
AreaModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[
AreaModel
.
is_delete
==
False
]
result
=
AreaModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AreaModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
areaCode
==
params
.
get
(
'areaCode'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
result
=
AreaModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
areaManager
=
AreaResource
()
\ No newline at end of file
tools/build_out/controllers/device.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-22 10:35:53
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
controllers
\
device.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
models.user
import
UserModel
from
models.device
import
DeviceModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
DeviceResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
DeviceModel
.
is_delete
==
False
,
DeviceModel
.
uuid
==
uuid
]
result
=
DeviceModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
,
jwt
=
{}):
# handle business
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
"uuid"
),
UserModel
.
is_delete
==
False
)
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
filters
=
[
DeviceModel
.
is_delete
==
False
,
DeviceModel
.
create_by
==
user
.
id
]
if
params
.
get
(
"type"
):
filters
.
append
(
DeviceModel
.
type
==
params
.
get
(
"type"
))
if
params
.
get
(
"name"
):
filters
.
append
(
DeviceModel
.
name
==
params
.
get
(
"name"
))
if
params
.
get
(
"imei"
):
filters
.
append
(
DeviceModel
.
imei
==
params
.
get
(
"imei"
))
result
=
DeviceModel
.
query
.
filter
(
*
filters
)
.
order_by
(
DeviceModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
result
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
imei
==
params
.
get
(
'imei'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
IMEI_EXISTS
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
"uuid"
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
params
.
update
({
'create_at'
:
datetime
.
now
(),
'create_by'
:
user
.
id
,
'update_at'
:
datetime
.
now
(),
'update_by'
:
user
.
id
})
result
=
DeviceModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
deviceManager
=
DeviceResource
()
\ No newline at end of file
tools/build_out/controllers/file.py
deleted
100644 → 0
View file @
32df1548
import
pprint
import
base64
import
shutil
from
pathlib
import
Path
import
json
import
mimetypes
from
models.user
import
UserModel
from
webcreator.log
import
logger
from
application.config
import
config
from
webcreator.response
import
ResponseCode
disk_root
=
config
.
UPLOAD_ROOT_DIR
class
FileManager
(
object
):
def
__init__
(
self
)
->
None
:
pass
'''
@description: 根据前端传递的路径参数,获取该路径的目录以及文件信息,文件类别,可以看做是一个盘符
@param {*} self
@return {*}
'''
def
initialize
(
self
,
path
,
jwt
):
'''
disks: {
files: {driver: "local"},
images: {driver: "local"}
}
lang: "en"
leftDisk: null
rightDisk: null
windowsConfig: 2
'''
result
=
{
"disks"
:
{},
"lang"
:
"zh"
,
"leftDisk"
:
None
,
"rightDisk"
:
None
,
"windowsConfig"
:
1
}
# 这里需要过滤,有些目录只能管理员才能查看
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
"uuid"
))
.
one_or_none
()
if
user
.
role
==
1
:
p
=
Path
(
disk_root
)
for
child
in
p
.
iterdir
():
if
child
.
is_dir
():
result
[
"disks"
]
.
update
({
child
.
name
:
{
"driver"
:
"local"
}
})
else
:
result
[
"disks"
]
.
update
({
"epks"
:
{
"driver"
:
"local"
}
})
return
result
,
ResponseCode
.
HTTP_SUCCESS
'''
@description: 获取当前类别的目录信息
@param {*} self
@return {*}
'''
def
content
(
self
,
disk
,
target_path
=
'.'
,
root
=
"."
):
'''
目录信息结构体:
{
basename: "docs"
dirname: ""
path: "docs"
timestamp: 1556821372
type: "dir"
},
{
basename: "cars"
dirname: "wallpapers"
path: "wallpapers/cars"
timestamp: 1544277291
type: "dir"
}
文件信息结构体:
{
basename: "alfa.sql"
dirname: "code"
extension: "sql"
filename: "alfa"
path: "code/alfa.sql"
size: 3208
timestamp: 1544277274
type: "file"
}
'''
result
=
{
"directories"
:
[],
"files"
:
[]
}
if
target_path
!=
None
and
target_path
.
find
(
disk
)
>
-
1
:
disk_path
=
Path
(
disk_root
)
else
:
disk_path
=
Path
(
disk_root
)
.
joinpath
(
disk
)
if
not
disk_path
.
exists
():
logger
.
info
(
disk_path
)
return
None
,
ResponseCode
.
DIRECTORY_NOT_EXISTS
if
target_path
==
None
:
target_path
=
''
target_path
=
Path
(
target_path
)
target_path
=
disk_path
.
joinpath
(
target_path
)
if
not
target_path
.
exists
():
logger
.
info
(
target_path
)
return
None
,
ResponseCode
.
DIRECTORY_NOT_EXISTS
for
child
in
target_path
.
iterdir
():
if
child
.
resolve
()
.
as_posix
()
.
find
(
root
)
<
0
:
continue
if
child
.
is_dir
():
result
[
"directories"
]
.
append
({
"basename"
:
child
.
name
,
"dirname"
:
child
.
parent
.
relative_to
(
disk_path
)
.
as_posix
(),
"path"
:
child
.
resolve
()
.
relative_to
(
disk_path
)
.
as_posix
(),
"timestamp"
:
int
(
child
.
stat
()
.
st_mtime
),
"type"
:
"dir"
})
else
:
result
[
"files"
]
.
append
({
"basename"
:
child
.
name
,
"dirname"
:
child
.
parent
.
relative_to
(
disk_path
)
.
as_posix
(),
"extension"
:
child
.
suffix
[
1
:],
"filename"
:
child
.
stem
,
"path"
:
child
.
resolve
()
.
relative_to
(
disk_path
)
.
as_posix
(),
"size"
:
child
.
stat
()
.
st_size
,
"timestamp"
:
int
(
child
.
stat
()
.
st_mtime
),
"type"
:
"file"
})
with
open
(
"result.json"
,
"w"
)
as
f
:
json
.
dump
(
result
,
f
)
f
.
seek
(
0
)
f
.
truncate
()
f
.
write
(
json
.
dumps
(
result
,
ensure_ascii
=
True
))
# pprint.pprint(result)
if
len
(
result
[
"directories"
])
or
len
(
result
[
"files"
]):
return
result
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
None
,
ResponseCode
.
HTTP_NO_DATA
'''
@description: 获取目录结构树
@param {*} self
@return {*}
'''
def
tree
(
self
,
disk
,
target_path
=
"."
,
root
=
"."
):
'''
{
basename: "trees"
dirname: "wallpapers/nature"
path: "wallpapers/nature/trees"
props: {
hasSubdirectories: false
}
timestamp: 1544277291
type: "dir"
}
'''
if
target_path
==
None
:
target_path
=
''
target_path
=
Path
(
target_path
)
result
=
[]
rp
=
Path
(
disk_root
)
disk_path
=
rp
/
disk
if
not
disk_path
.
exists
():
return
result
,
ResponseCode
.
DIRECTORY_NOT_EXISTS
temp_path
=
disk_path
.
joinpath
(
target_path
)
if
not
temp_path
.
exists
():
temp_path
=
Path
(
disk_root
)
.
joinpath
(
target_path
)
if
not
temp_path
.
exists
():
return
result
,
ResponseCode
.
DIRECTORY_NOT_EXISTS
# p = Path(disk_path)
for
child
in
temp_path
.
iterdir
():
if
child
.
is_dir
()
and
child
.
resolve
()
.
name
.
find
(
root
)
>
-
1
:
result
.
append
({
"basename"
:
child
.
name
,
"dirname"
:
child
.
parent
.
relative_to
(
rp
)
.
as_posix
(),
"path"
:
child
.
relative_to
(
rp
)
.
as_posix
(),
"props"
:
{
"hasSubdirectories"
:
True
if
child
.
iterdir
()
else
False
},
"timestamp"
:
int
(
child
.
stat
()
.
st_mtime
),
"type"
:
"dir"
})
# pprint.pprint(result)
# logger.info(result)
return
result
,
ResponseCode
.
HTTP_SUCCESS
def
disk
(
self
,
disk
):
# select-disks
print
(
disk
)
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
update_file
(
self
,
disk
,
path
,
file
):
# update file
# 判断文件是否存在
target_dir
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
path
)
if
not
target_dir
.
is_dir
():
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
if
not
target_dir
.
exists
():
target_dir
.
mkdir
()
target_file
=
target_dir
.
joinpath
(
file
.
filename
)
if
target_file
.
exists
():
if
not
target_file
.
is_file
():
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
target_file
.
unlink
()
file
.
save
(
target_file
.
resolve
()
.
as_posix
())
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
upload
(
self
,
disk
,
path
,
overwrite
,
fileList
):
# upload
target_dir
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
path
)
if
not
target_dir
.
exists
():
target_dir
.
mkdir
()
for
file
in
fileList
:
target_file
=
target_dir
.
joinpath
(
file
.
filename
)
if
target_file
.
exists
()
and
overwrite
==
0
:
target_file
.
unlink
()
elif
target_file
.
exists
():
continue
file
.
save
(
target_file
.
resolve
()
.
as_posix
())
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
create_dir
(
self
,
disk
,
path
,
name
):
# create directory
print
(
disk
,
path
,
name
)
target_dir
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
path
)
.
joinpath
(
name
)
if
not
target_dir
.
exists
():
target_dir
.
mkdir
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
create_file
(
self
,
disk
,
path
,
name
):
# create file
print
(
disk
,
disk
,
path
,
name
)
target_dir
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
path
)
if
not
target_dir
.
exists
():
target_dir
.
mkdir
()
target_file
=
target_dir
.
joinpath
(
name
)
if
target_file
.
exists
():
return
False
,
ResponseCode
.
FILE_EXISTS
target_file
.
touch
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
delete
(
self
,
disk
,
items
):
# delete file
print
(
disk
,
items
,
type
(
items
))
for
item
in
items
:
target
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
item
.
get
(
"path"
))
if
not
target
.
exists
():
return
False
,
ResponseCode
.
APPLICATION_NOT_EXISTS
if
target
.
is_dir
():
target
.
mkdir
()
elif
target
.
is_file
():
target
.
unlink
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
copy
(
self
,
disk
):
# copy file
# 无动作,前端缓存相关变量值
print
(
disk
)
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
cut
(
self
,
disk
):
# cut file
# 复制源文件路径
# 无动作,前端缓存相关变量值
print
(
disk
)
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
paste
(
self
,
disk
,
path
,
clipboard
):
# paste file
'''
directories: []
disk: "files"
files: ["code/config.ini"]
type: "copy"
directories: []
disk: "files"
files: ["code/alfa.sql"]
type: "cut"
'''
# 粘贴到当前目录,然后删除源文件
# 需要区分是复制操作还是剪贴操作
print
(
disk
,
path
,
clipboard
)
target_dir
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
path
)
for
dir
in
clipboard
.
get
(
"directories"
,
[]):
source_dir
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
dir
)
if
not
source_dir
.
exists
():
continue
if
target_dir
.
joinpath
(
dir
)
.
exists
():
continue
shutil
.
copytree
(
source_dir
.
resolve
()
.
as_posix
(),
target_dir
.
resolve
()
.
as_posix
())
if
clipboard
.
get
(
"type"
)
==
"cut"
:
source_dir
.
rmdir
()
for
file
in
clipboard
.
get
(
"files"
,
[]):
source_file
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
file
)
if
not
source_file
.
exists
():
continue
if
target_dir
.
joinpath
(
file
)
.
exists
():
continue
shutil
.
copyfile
(
source_file
.
resolve
()
.
as_posix
(),
target_dir
.
resolve
()
.
as_posix
())
if
clipboard
.
get
(
"type"
)
==
"cut"
:
source_dir
.
unlink
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
download
(
self
,
disk
,
target_file
):
# 获取文件内容
if
not
target_file
:
target_file
=
Path
(
'result.json'
)
else
:
target_file
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
target_file
)
if
not
target_file
.
exists
():
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
# with open(target_file.resolve().as_posix(), "r", encoding="utf-8") as f:
# data = f.read()
# print(data)
mime
=
mimetypes
.
guess_type
(
target_file
.
resolve
()
.
as_posix
())[
0
]
content
=
target_file
.
read_text
(
encoding
=
"utf-8"
)
if
mime
==
"application/json"
:
content
=
json
.
dumps
(
content
)
return
(
content
,
mime
),
ResponseCode
.
HTTP_SUCCESS
def
preview
(
self
,
disk
,
target_file
):
# 预览图片
if
not
target_file
:
target_file
=
Path
(
'evue_photo.png'
)
else
:
target_file
=
Path
(
disk_root
)
.
joinpath
(
disk
)
.
joinpath
(
target_file
)
if
not
target_file
.
exists
():
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
mime
=
mimetypes
.
guess_type
(
target_file
.
resolve
()
.
as_posix
())[
0
]
# mime = MimeTypes.guess_type(target_file.resolve().as_posix())
img_stream
=
target_file
.
read_bytes
()
# with open(target_file, 'rb') as img_f:
# img_stream = img_f.read()
# img_stream = base64.b64encode(img_stream).decode()
return
(
img_stream
,
mime
),
ResponseCode
.
HTTP_SUCCESS
fileManager
=
FileManager
()
if
__name__
==
"__main__"
:
'''
python -m memory_profiler example.py
'''
# from memory_profiler import profile
# @profile
# def test():
# pass
result
=
fileManager
.
initialize
()
print
(
"----->"
,
result
)
result
=
fileManager
.
content
(
"uploads"
,
"evueapps/evm"
)
print
(
">>>>>>"
,
result
)
result
=
fileManager
.
tree
(
"uploads"
,
"evueapps/evm"
)
print
(
"=====>"
,
result
)
result
=
fileManager
.
preview
(
"uploads"
,
"evueapps/evm"
)
print
(
"$$$$$>"
,
result
)
tools/build_out/controllers/login.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
json
import
pprint
from
datetime
import
datetime
from
flask_jwt_extended
import
(
create_access_token
,)
from
application.app
import
db
from
models.login
import
LoginModel
from
models.user
import
UserModel
from
webcreator.log
import
logger
from
webcreator
import
utils
from
webcreator.response
import
ResponseCode
@
utils
.
ThreadMaker
def
update_login_information
(
ip
,
log_id
):
try
:
jsonData
=
utils
.
get_location_by_ip
(
ip
)
if
(
0
!=
jsonData
[
'status'
]):
return
None
record
=
LoginModel
.
query
.
filter
(
LoginModel
.
id
==
log_id
)
.
first
()
record
.
geo_location
=
json
.
dumps
(
jsonData
,
ensure_ascii
=
False
)
db
.
session
.
commit
()
except
Exception
as
e
:
logger
.
error
(
e
)
class
LoginResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
LoginModel
.
is_delete
==
False
,
LoginModel
.
uuid
==
uuid
]
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[
LoginModel
.
is_delete
==
False
]
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
order_by
(
LoginModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
user
=
UserModel
.
query
.
filter
(
UserModel
.
account
==
params
.
get
(
"account"
))
.
first
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
logger
.
info
(
params
)
if
user
.
password
!=
utils
.
md5_encryption
(
params
.
get
(
"password"
)):
return
False
,
ResponseCode
.
USER_PASSWORD_ERROR
# 插入一条登录记录
obj
=
{
'user'
:
user
.
id
,
'user_agent'
:
params
.
get
(
"user_agent"
),
'ip'
:
params
.
get
(
"ip"
),
'geo_location'
:
''
,
'operator'
:
''
,
'login_at'
:
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
}
result
=
LoginModel
(
**
obj
)
result
.
operator
=
""
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
# 获取当前登录IP地理位置信息
update_login_information
(
params
.
get
(
"ip"
),
result
.
id
)
# 生成一个token,返回给前端
result
=
{
'uuid'
:
str
(
user
.
uuid
),
'name'
:
user
.
username
,
'token'
:
create_access_token
(
identity
=
{
'uuid'
:
str
(
user
.
uuid
),
'name'
:
user
.
username
}),
}
pprint
.
pprint
(
result
)
return
result
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
loginManager
=
LoginResource
()
tools/build_out/controllers/menu.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-27 16:19:06
LastEditTime: 2021-07-28 09:28:49
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
controllers
\
menu.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
pprint
import
pprint
from
datetime
import
datetime
from
application.app
import
db
from
models.user
import
UserModel
from
models.menu
import
MenuModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
MenuResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
print_tree
(
self
,
group_name
,
tab
=
1
):
"""
:param str group_name:要查找的树的根的名称
:param int tab: 格式化用的-数量
"""
group
=
db
.
session
.
query
(
MenuModel
)
.
filter_by
(
name
=
group_name
)
.
one_or_none
()
if
not
group
:
return
# group found - print name and find children
print
(
'- '
*
tab
+
group
.
name
)
for
child_group
in
group
.
children
:
# type: TreeGroup
# new tabulation value for child record
self
.
print_tree
(
child_group
.
name
,
tab
*
2
)
def
batch
(
self
,
params
=
{},
jwt
=
{}):
# 如果id里面包含无法转换为数字的字符,那么该接口将会报错
ids
=
list
(
map
(
lambda
x
:
int
(
x
),
params
.
get
(
"ids"
)
.
split
(
","
)))
result
=
db
.
session
.
query
(
MenuModel
)
.
filter
(
MenuModel
.
id
in
ids
)
.
delete
()
db
.
session
.
commit
()
# 这是批量删除模式
logger
.
info
(
result
)
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
updateSort
(
self
,
params
=
{},
jwt
=
{}):
user
=
db
.
session
.
query
(
UserModel
)
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
"uuid"
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# 接口字段可能和数据库字段不一致
result
=
db
.
session
.
query
(
MenuModel
)
.
filter
(
MenuModel
.
id
==
params
.
get
(
"id"
))
.
one_or_none
()
if
result
:
sort
=
1
if
params
.
get
(
"direction"
)
==
"bottom"
:
sort
=
-
1
result
.
update_at
=
datetime
.
now
()
result
.
update_by
=
user
.
id
result
.
sort
=
result
.
sort
+
sort
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
def
create
(
self
,
params
=
{},
jwt
=
{}):
user
=
db
.
session
.
query
(
UserModel
)
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
"uuid"
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# 接口字段可能和数据库字段不一致
extends
=
MenuModel
.
fields_mapping
()
data
=
dict
(
is_delete
=
False
,
sort
=
0
,
remarks
=
""
)
data
.
update
({
'create_by'
:
user
.
id
,
'create_at'
:
datetime
.
niw
(),
'update_by'
:
user
.
id
,
'update_at'
:
datetime
.
now
()
})
for
k
in
params
.
keys
():
if
k
in
extends
:
k
[
extends
[
k
]]
=
params
[
k
]
continue
if
hasattr
(
MenuModel
,
k
):
data
[
k
]
=
params
[
k
]
if
data
.
get
(
"sort"
)
==
0
:
data
.
sort
=
db
.
session
.
query
(
MenuModel
)
.
filter
()
.
count
()
+
1
# 默认设置sort等于表内记录个数
logger
.
info
(
data
.
sort
)
result
=
MenuModel
(
**
data
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
treeList
(
self
,
params
=
{},
jwt
=
{}):
filters
=
[
MenuModel
.
is_delete
==
False
]
result
=
db
.
session
.
query
(
MenuModel
)
.
filter
(
*
filters
)
.
order_by
(
MenuModel
.
sort
)
.
order_by
(
MenuModel
.
update_at
.
desc
())
.
all
()
data
=
[]
if
result
:
print
(
result
)
tab
=
1
for
item
in
result
:
tmp
=
item
.
get_tree
(
session
=
db
.
session
)
# print(tmp, tmp.get("node"))
for
tt
in
tmp
:
logger
.
info
(
tt
)
logger
.
info
(
tt
.
get
(
"node"
))
# pprint(item.get_tree(session=db.session, json=True))
pprint
(
item
.
get_children
(
session
=
db
.
session
))
# for child_group in i.children: # type: TreeGroup
# # new tabulation value for child record
# self.print_tree(child_group.name, tab * 2)
# for item in result:
# t = item.dict()
# data.append(t)
# return result, ResponseCode.HTTP_SUCCESS
return
data
,
ResponseCode
.
HTTP_NOT_FOUND
def
treeNodes
(
self
,
params
=
{},
jwt
=
{}):
filters
=
[
MenuModel
.
is_delete
==
False
,
MenuModel
.
parent_id
==
0
]
result
=
db
.
session
.
query
(
MenuModel
)
.
filter
(
*
filters
)
.
order_by
(
MenuModel
.
sort
)
.
order_by
(
MenuModel
.
update_at
.
desc
())
.
all
()
logger
.
info
(
result
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
updateById
(
self
,
params
=
{},
jwt
=
{}):
user
=
db
.
session
.
query
(
UserModel
)
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
"uuid"
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# 接口字段可能和数据库字段不一致
extends
=
MenuModel
.
fields_mapping
()
data
=
dict
(
is_delete
=
False
)
data
.
update
({
'update_at'
:
datetime
.
now
(),
'update_by'
:
user
.
id
})
for
k
in
params
.
keys
():
if
k
in
extends
:
k
[
extends
[
k
]]
=
params
[
k
]
continue
if
hasattr
(
MenuModel
,
k
):
data
[
k
]
=
params
[
k
]
logger
.
info
(
data
)
# filters = [MenuModel.is_delete==False]
# result = MenuModel.query.filter(*filters).first()
result
=
MenuModel
.
query
.
filter
(
MenuModel
.
id
==
params
.
get
(
"id"
))
.
update
(
data
,
synchronize_session
=
False
)
db
.
session
.
commit
()
logger
.
info
(
result
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
menuManager
=
MenuResource
()
\ No newline at end of file
tools/build_out/controllers/monitor.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-06-29 19:24:32
LastEditTime: 2021-07-21 18:37:59
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\b
ackend
\
controller
\
monitor.py
'''
from
application.app
import
db
from
models.device
import
DeviceModel
from
models.monitorEvm
import
MonitorEvmModel
from
models.monitorImage
import
MonitorImageModel
from
models.monitorLvgl
import
MonitorLvglModel
from
models.monitorSystem
import
MonitorSystemModel
from
webcreator.log
import
logger
class
SystemResource
(
object
):
def
get
(
self
):
return
MonitorSystemModel
.
query
.
all
()
def
post
(
self
,
params
):
data
=
dict
()
for
k
in
params
:
if
hasattr
(
MonitorSystemModel
,
k
):
data
[
k
]
=
params
[
k
]
result
=
MonitorSystemModel
(
**
data
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
class
LvglResource
(
object
):
def
get
(
self
):
return
MonitorLvglModel
.
query
.
all
()
def
post
(
self
,
params
):
data
=
dict
()
for
k
in
params
:
if
hasattr
(
MonitorLvglModel
,
k
):
data
[
k
]
=
params
[
k
]
result
=
MonitorLvglModel
(
**
data
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
class
EvmResource
(
object
):
def
get
(
self
):
return
MonitorEvmModel
.
query
.
all
()
def
post
(
self
,
params
):
result
=
MonitorEvmModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
class
ImageResource
(
object
):
def
get
(
self
):
return
MonitorImageModel
.
query
.
all
()
def
post
(
self
,
params
):
data
=
dict
()
for
k
in
params
:
if
hasattr
(
MonitorImageModel
,
k
):
data
[
k
]
=
params
[
k
]
result
=
MonitorImageModel
(
**
data
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
def
post_array
(
self
,
array
,
watch
):
t
=
[]
for
a
in
array
:
data
=
dict
()
for
k
in
a
:
if
hasattr
(
MonitorImageModel
,
k
):
data
[
k
]
=
a
[
k
]
data
.
update
({
"watch"
:
watch
})
t
.
append
(
data
)
db
.
session
.
execute
(
MonitorImageModel
.
__table__
.
insert
(),
t
)
db
.
session
.
commit
()
return
True
systemResource
=
SystemResource
()
lvglResource
=
LvglResource
()
evmResource
=
EvmResource
()
imageResource
=
ImageResource
()
def
insert_data
(
msg
):
# 先判断手表imei是否存在,不存在则先注册手表IMEI
device_id
=
-
1
if
not
msg
.
get
(
"imei"
):
return
None
result
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
imei
==
msg
.
get
(
"imei"
))
.
one_or_none
()
if
not
result
:
return
None
device_id
=
result
.
id
if
msg
.
get
(
"system"
)
or
msg
.
get
(
"request"
):
msg
.
get
(
"system"
,
{})
.
update
({
"watch"
:
device_id
})
msg
.
get
(
"system"
)
.
update
(
msg
.
get
(
"request"
,
{}))
systemResource
.
post
(
msg
.
get
(
"system"
))
if
msg
.
get
(
"lvgl"
):
msg
.
get
(
"lvgl"
)
.
update
({
"watch"
:
device_id
})
lvglResource
.
post
(
msg
.
get
(
"lvgl"
))
if
msg
.
get
(
"evm"
):
msg
.
get
(
"evm"
)
.
update
({
"watch"
:
device_id
})
evmResource
.
post
(
msg
.
get
(
"evm"
))
if
msg
.
get
(
"image"
):
imageResource
.
post_array
(
msg
.
get
(
"image"
),
device_id
)
return
True
def
get_watch_list
():
result
=
DeviceModel
.
query
.
all
()
tmp
=
[]
for
item
in
result
:
tmp
.
append
({
'id'
:
item
.
id
,
'imei'
:
item
.
imei
})
return
tmp
def
evm_data
(
watch
,
start
,
end
):
filters
=
[
MonitorEvmModel
.
watch
==
watch
]
if
start
:
filters
.
append
(
MonitorEvmModel
.
timestamp
>=
start
)
if
end
:
filters
.
append
(
MonitorEvmModel
.
timestamp
<=
end
)
result
=
MonitorEvmModel
.
query
.
filter
(
*
filters
)
.
order_by
(
MonitorEvmModel
.
timestamp
)
.
all
()
temp
=
[]
for
item
in
result
:
t
=
item
.
to_dict
()
if
t
.
get
(
"timestamp"
):
t
.
update
({
'timestamp'
:
t
.
get
(
"timestamp"
)
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
})
temp
.
append
(
t
)
return
temp
def
lvgl_data
(
watch
,
start
,
end
):
filters
=
[
MonitorLvglModel
.
watch
==
watch
]
if
start
:
filters
.
append
(
MonitorLvglModel
.
timestamp
>=
start
)
if
end
:
filters
.
append
(
MonitorLvglModel
.
timestamp
<=
end
)
result
=
MonitorLvglModel
.
query
.
filter
(
*
filters
)
.
order_by
(
MonitorLvglModel
.
timestamp
)
.
all
()
temp
=
[]
for
item
in
result
:
t
=
item
.
to_dict
()
if
t
.
get
(
"timestamp"
):
t
.
update
({
'timestamp'
:
t
.
get
(
"timestamp"
)
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
})
temp
.
append
(
t
)
return
temp
def
image_data
(
watch
,
start
,
end
):
filters
=
[
MonitorImageModel
.
watch
==
watch
]
if
start
:
filters
.
append
(
MonitorImageModel
.
timestamp
>=
start
)
if
end
:
filters
.
append
(
MonitorImageModel
.
timestamp
<=
end
)
result
=
MonitorImageModel
.
query
.
filter
(
*
filters
)
.
order_by
(
MonitorImageModel
.
timestamp
)
.
all
()
temp
=
[]
for
item
in
result
:
t
=
item
.
to_dict
()
if
t
.
get
(
"timestamp"
):
t
.
update
({
'timestamp'
:
t
.
get
(
"timestamp"
)
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
})
temp
.
append
(
t
)
return
temp
def
get_monitor_list
(
watch
,
category
,
start
,
end
):
# 判断watch是否存在
w
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
id
==
watch
)
.
first
()
if
not
w
:
return
[]
if
category
==
"system"
:
return
[]
elif
category
==
"image"
:
return
image_data
(
watch
,
start
,
end
)
elif
category
==
"lvgl"
:
return
lvgl_data
(
watch
,
start
,
end
)
elif
category
==
"evm"
:
return
evm_data
(
watch
,
start
,
end
)
else
:
return
{
'evm'
:
evm_data
(
watch
,
start
,
end
),
'lvgl'
:
lvgl_data
(
watch
,
start
,
end
),
'image'
:
image_data
(
watch
,
start
,
end
)
}
tools/build_out/controllers/monitorEvm.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
models.monitorEvm
import
MonitorEvmModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
MonitorEvmResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
MonitorEvmModel
.
is_delete
==
False
,
MonitorEvmModel
.
uuid
==
uuid
]
result
=
MonitorEvmModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[
MonitorEvmModel
.
is_delete
==
False
]
result
=
MonitorEvmModel
.
query
.
filter
(
*
filters
)
.
order_by
(
MonitorEvmModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
result
=
MonitorEvmModel
.
query
.
filter
(
MonitorEvmModel
.
watch
==
params
.
get
(
'watch'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
result
=
MonitorEvmModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
MonitorEvmModel
.
query
.
filter
(
MonitorEvmModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
MonitorEvmModel
.
query
.
filter
(
MonitorEvmModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
monitorEvmManager
=
MonitorEvmResource
()
\ No newline at end of file
tools/build_out/controllers/monitorImage.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
models.monitorImage
import
MonitorImageModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
MonitorImageResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
MonitorImageModel
.
is_delete
==
False
,
MonitorImageModel
.
uuid
==
uuid
]
result
=
MonitorImageModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[
MonitorImageModel
.
is_delete
==
False
]
result
=
MonitorImageModel
.
query
.
filter
(
*
filters
)
.
order_by
(
MonitorImageModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
result
=
MonitorImageModel
.
query
.
filter
(
MonitorImageModel
.
watch
==
params
.
get
(
'watch'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
result
=
MonitorImageModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
MonitorImageModel
.
query
.
filter
(
MonitorImageModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
MonitorImageModel
.
query
.
filter
(
MonitorImageModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
monitorImageManager
=
MonitorImageResource
()
\ No newline at end of file
tools/build_out/controllers/monitorLvgl.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
models.monitorLvgl
import
MonitorLvglModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
MonitorLvglResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
MonitorLvglModel
.
is_delete
==
False
,
MonitorLvglModel
.
uuid
==
uuid
]
result
=
MonitorLvglModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[
MonitorLvglModel
.
is_delete
==
False
]
result
=
MonitorLvglModel
.
query
.
filter
(
*
filters
)
.
order_by
(
MonitorLvglModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
result
=
MonitorLvglModel
.
query
.
filter
(
MonitorLvglModel
.
watch
==
params
.
get
(
'watch'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
result
=
MonitorLvglModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
MonitorLvglModel
.
query
.
filter
(
MonitorLvglModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
MonitorLvglModel
.
query
.
filter
(
MonitorLvglModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
monitorLvglManager
=
MonitorLvglResource
()
\ No newline at end of file
tools/build_out/controllers/monitorSystem.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
models.monitorSystem
import
MonitorSystemModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
MonitorSystemResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
MonitorSystemModel
.
is_delete
==
False
,
MonitorSystemModel
.
uuid
==
uuid
]
result
=
MonitorSystemModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[
MonitorSystemModel
.
is_delete
==
False
]
result
=
MonitorSystemModel
.
query
.
filter
(
*
filters
)
.
order_by
(
MonitorSystemModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
result
=
MonitorSystemModel
.
query
.
filter
(
MonitorSystemModel
.
watch
==
params
.
get
(
'watch'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
result
=
MonitorSystemModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
MonitorSystemModel
.
query
.
filter
(
MonitorSystemModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
MonitorSystemModel
.
query
.
filter
(
MonitorSystemModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
monitorSystemManager
=
MonitorSystemResource
()
\ No newline at end of file
tools/build_out/controllers/monitorWatch.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-20 01:18:27
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
controllers
\
monitorWatch.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
models.device
import
DeviceModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
MonitorWatchResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
DeviceModel
.
is_delete
==
False
,
DeviceModel
.
uuid
==
uuid
]
result
=
DeviceModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[
DeviceModel
.
is_delete
==
False
]
result
=
DeviceModel
.
query
.
filter
(
*
filters
)
.
order_by
(
DeviceModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
result
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
imei
==
params
.
get
(
'imei'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
result
=
DeviceModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
monitorWatchManager
=
MonitorWatchResource
()
\ No newline at end of file
tools/build_out/controllers/package.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-06-30 18:03:41
LastEditTime: 2021-07-22 16:09:28
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
controllers
\
package.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
os
import
re
import
shutil
from
pathlib
import
Path
from
datetime
import
datetime
from
application.app
import
db
,
config
from
models.annex
import
AnnexModel
from
models.app
import
AppModel
from
models.user
import
UserModel
from
models.package
import
PackageModel
from
webcreator.utils.epk
import
EpkApp
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
PackageResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
jwt
):
# handle business
filters
=
[
PackageModel
.
is_delete
==
False
,
PackageModel
.
uuid
==
uuid
]
result
=
PackageModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
,
jwt
):
# handle business
logger
.
warn
(
params
)
# filters = [PackageModel.is_delete==False]
# result = PackageModel.query.filter(*filters).order_by(PackageModel.create_at).paginate(params.get('page', 1), params.get('pageSize', 10), error_out=False)
# if result:
# return result, ResponseCode.HTTP_SUCCESS
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
'uuid'
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
temp
=
{}
if
user
.
role
==
1
:
temp
.
update
({
"is_delete"
:
False
})
else
:
temp
.
update
({
"create_by"
:
user
.
id
,
"is_delete"
:
False
})
if
"scope"
in
params
and
params
.
get
(
"scope"
)
==
"list"
:
result
=
PackageModel
.
query
.
filter_by
(
**
temp
)
.
order_by
(
PackageModel
.
create_at
.
desc
())
temp
=
[]
for
item
in
result
:
temp
.
append
({
"name"
:
item
.
app
.
app_name
,
"uuid"
:
str
(
item
.
uuid
)
})
if
len
(
temp
):
return
temp
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
temp
=
[
PackageModel
.
is_delete
==
False
,
PackageModel
.
create_by
==
user
.
id
]
if
params
.
get
(
"app"
)
and
isinstance
(
params
.
get
(
"app"
),
str
):
app
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
params
.
get
(
"app"
))
.
one_or_none
()
if
app
:
params
.
update
({
"app"
:
app
.
id
})
temp
.
append
(
PackageModel
.
app
==
app
.
id
)
else
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
.
get
(
"app_version"
):
temp
.
append
(
PackageModel
.
app_version
==
params
.
get
(
"app_version"
))
if
params
.
get
(
"algorithm"
):
temp
.
append
(
PackageModel
.
algorithm
==
params
.
get
(
"algorithm"
))
if
params
.
get
(
"source"
):
temp
.
append
(
PackageModel
.
source
==
params
.
get
(
"source"
))
# for p in params:
# if hasattr(PackageModel, p) and params[p] != None:
# logger.info(p)
# temp[p] = params[p]
result
=
db
.
session
.
query
(
PackageModel
)
.
join
(
AppModel
,
PackageModel
.
app
==
AppModel
.
id
)
.
filter
(
*
temp
)
.
order_by
(
PackageModel
.
create_at
.
desc
())
.
add_entity
(
AppModel
)
.
paginate
(
params
.
get
(
"page"
,
1
),
params
.
get
(
"pageSize"
,
15
),
error_out
=
False
)
if
result
.
total
and
len
(
result
.
items
):
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
result
,
ResponseCode
.
HTTP_NO_DATA
def
post
(
self
,
params
,
jwt
=
{}):
# 判断用户是否存在
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
'uuid'
))
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# 判断app是否存在
app
=
AppModel
.
query
.
filter
(
AppModel
.
id
==
params
.
get
(
"app"
))
if
not
app
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
# 根据应用查找有哪些源文件
source_files
=
AnnexModel
.
query
.
filter
(
AnnexModel
.
app
==
app
.
id
)
.
all
()
if
not
source_files
:
return
None
,
ResponseCode
.
HTTP_NO_DATA
dir_format
=
"{}-{}-{}"
.
format
(
app
.
app_name
,
app
.
app_version
,
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
))
upload_dir
=
Path
(
config
.
UPLOAD_ROOT_DIR
)
.
joinpath
(
"uploads"
)
.
joinpath
(
"evueapps"
)
# upload_dir = os.sep.join([config.UPLOAD_ROOT_DIR, "uploads", "evueapps"])
target_dir
=
upload_dir
.
joinpath
(
user
.
account
)
.
joinpath
(
dir_format
)
# target_dir = os.sep.join([upload_dir, user.account, dir_format])
dest_dir
=
target_dir
.
joinpath
(
"src"
)
# dest_dir = os.sep.join([target_dir, "src"])
if
not
dest_dir
.
exists
():
os
.
makedirs
(
dest_dir
.
resolve
()
.
as_posix
())
app_files
=
[]
for
sf
in
source_files
:
target_file
=
Path
(
config
.
UPLOAD_ROOT_DIR
)
.
joinpath
(
sf
.
path
)
name
=
re
.
sub
(
r"_\d{14}$"
,
""
,
target_file
.
stem
)
suffix
=
target_file
.
suffix
dst_file
=
dest_dir
.
joinpath
(
name
+
suffix
)
shutil
.
move
(
target_file
.
resolve
()
.
as_posix
(),
dst_file
.
resolve
()
.
as_posix
())
app_files
.
append
([
sf
.
id
,
dst_file
.
resolve
()
.
as_posix
()])
# 打包成EPK文件
app_info
=
{}
params
=
{
'appName'
:
app
.
app_name
,
'appDir'
:
dest_dir
,
'appVersion'
:
app
.
app_version
,
'output'
:
target_dir
.
resolve
()
.
as_posix
()
}
if
user
.
role
==
1
:
params
[
'algorithm'
]
=
"h"
epk
=
EpkApp
(
**
params
)
app_info
=
epk
.
pack
()
if
app_info
:
app_info
[
'md5'
]
=
str
(
app_info
[
'md5'
])
# 更新数据库对应文件路径
# for sf in source_files:
# for af in app_files:
# if sf.id == af[0]:
# t = os.path.normpath(af[1].replace(config.UPLOAD_ROOT_DIR, "")).replace('\\', '/')
# sf.set(path=t)
# db.session.flush()
# db.session.commit()
epk_path
=
target_dir
.
relative_to
(
config
.
UPLOAD_ROOT_DIR
)
.
joinpath
(
"{}.epk"
.
format
(
app
.
app_name
))
.
resolve
()
.
as_posix
()
# handle business
# result = PackageModel.query.filter(PackageModel.app == params.get('app')).first()
# if result and result.is_delete:
# result.is_delete = False
# result.update_by = jwt.get("id", "")
# result.update_date = datetime.now()
# db.session.commit()
# return True, ResponseCode.HTTP_SUCCESS
# elif result and result.is_delete == False:
# return False, ResponseCode.HTTP_INVAILD_REQUEST
result
=
PackageModel
(
app
=
app
.
id
,
file_path
=
epk_path
,
package_info
=
app_info
,
app_version
=
params
.
get
(
"app_version"
),
create_by
=
user
.
id
,
create_at
=
datetime
.
now
(),
update_by
=
user
.
id
,
update_at
=
datetime
.
now
())
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
packageManager
=
PackageResource
()
\ No newline at end of file
tools/build_out/controllers/upload.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
os
import
json
import
traceback
import
tempfile
import
base64
from
hashlib
import
md5
from
application.config
import
config
from
webcreator.log
import
logger
# 判断目录是否存在,不存在则创建
# if not os.path.exists(os.path.join(config.UPLOAD_ROOT_DIR, config.get("UPLOAD_DIR"))):
# os.makedirs(os.path.join(config.UPLOAD_ROOT_DIR, config.get("UPLOAD_DIR")))
def
checkAccess
(
path
):
realpath
=
os
.
path
.
realpath
(
path
)
if
not
realpath
.
startswith
(
config
.
UPLOAD_ROOT_DIR
):
return
False
return
True
def
checkPath
(
path
):
if
not
path
:
return
False
,
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"[
%
s] arg missed!"
%
path
}
fpath
=
os
.
path
.
abspath
(
os
.
sep
.
join
(
[
os
.
path
.
abspath
(
config
.
UPLOAD_ROOT_DIR
),
path
]))
if
not
checkAccess
(
fpath
):
return
False
,
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"You have no access to [
%
s]!"
%
fpath
}
if
not
os
.
path
.
exists
(
fpath
):
return
False
,
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"[
%
s] is not existed!"
%
fpath
}
return
True
,
os
.
path
.
abspath
(
fpath
)
def
saveToFile
(
saveFile
,
content
):
try
:
tfn
=
tempfile
.
mktemp
()
tf
=
open
(
tfn
,
'w+b'
)
tf
.
write
(
content
)
tf
.
close
()
os
.
rename
(
tfn
,
saveFile
)
return
True
except
Exception
as
e
:
traceback
.
print_exc
()
logger
.
error
(
str
(
e
))
return
False
def
getFileInfo
(
infofile
):
info
=
dict
()
info
.
update
({
"isfile"
:
os
.
path
.
isfile
(
infofile
),
"isdir"
:
os
.
path
.
isdir
(
infofile
),
"size"
:
os
.
path
.
getsize
(
infofile
),
"atime"
:
os
.
path
.
getatime
(
infofile
),
"mtime"
:
os
.
path
.
getmtime
(
infofile
),
"ctime"
:
os
.
path
.
getctime
(
infofile
),
"name"
:
os
.
path
.
basename
(
infofile
)
})
return
info
class
UploadResource
(
object
):
def
__init__
(
self
):
super
(
UploadResource
,
self
)
.
__init__
()
def
download
(
self
,
data
):
obj
=
json
.
loads
(
data
)
isAccessed
,
path
=
checkPath
(
obj
[
"path"
])
if
not
isAccessed
:
return
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"invaild access"
}
if
not
os
.
path
.
isfile
(
path
):
return
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"Path [
%
s] is not a valid file!"
%
path
}
try
:
with
open
(
path
,
"rb"
)
as
f
:
content
=
base64
.
b64encode
(
f
.
read
())
md5code
=
md5
(
content
)
.
hexdigest
()
return
{
"data"
:
{
"content"
:
content
,
"md5"
:
md5code
,
"filename"
:
os
.
path
.
basename
(
path
)
},
"code"
:
0
,
"message"
:
"download file [
%
s] successfully!"
%
obj
[
'path'
]
}
except
Exception
as
e
:
traceback
.
print_exc
()
logger
.
error
(
str
(
e
))
return
{
"data"
:
None
,
"code"
:
-
1
,
"message"
:
"upload file [
%
s] failed!
\n
%
s"
%
(
obj
[
'path'
],
repr
(
e
))
}
def
delete
(
self
,
data
):
try
:
isAccessed
,
path
=
checkPath
(
data
[
"path"
])
if
not
isAccessed
:
return
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"invaild access"
}
if
os
.
path
.
isfile
(
path
):
os
.
remove
(
path
)
return
{
"code"
:
0
,
"data"
:
None
,
"message"
:
"delete file [
%
s] successfully!"
%
path
}
elif
os
.
path
.
isdir
(
path
):
os
.
rmdir
(
path
)
return
{
"code"
:
0
,
"data"
:
None
,
"message"
:
"delete dir [
%
s] successfully!"
%
path
}
else
:
return
{
"code"
:
0
,
"data"
:
None
,
"message"
:
"Path [
%
s] is not a valid file or path!"
%
path
}
except
Exception
as
e
:
traceback
.
print_exc
()
logger
.
error
(
str
(
e
))
return
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
repr
(
e
)}
def
dirlist
(
self
,
data
):
obj
=
json
.
loads
(
data
)
isAccessed
,
path
=
checkPath
(
obj
[
"path"
])
if
not
isAccessed
:
return
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"invaild access"
}
result
=
[]
for
p
in
os
.
listdir
(
path
):
result
.
append
(
getFileInfo
(
os
.
path
.
join
(
config
.
UPLOAD_ROOT_DIR
,
p
)))
return
{
"code"
:
0
,
"result"
:
result
,
"message"
:
"Get [
%
s] successfully!"
%
path
}
def
filemd5
(
self
,
data
):
obj
=
json
.
loads
(
data
)
isAccessed
,
path
=
checkPath
(
obj
[
"path"
])
if
not
isAccessed
:
return
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"invaild access"
}
if
not
os
.
path
.
isfile
(
path
):
return
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"Path [
%
s] is not a valid file!"
%
path
}
with
open
(
path
,
"rb"
)
as
f
:
filemd5
=
md5
(
f
.
read
())
.
hexdigest
()
return
{
"code"
:
0
,
"result"
:
filemd5
,
"message"
:
"Get md5 of [
%
s] successfully!"
%
path
}
def
fileinfo
(
self
,
data
):
obj
=
json
.
loads
(
data
)
isAccessed
,
path
=
checkPath
(
obj
[
"path"
])
if
not
isAccessed
:
return
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"invaild access"
}
if
not
os
.
path
.
isfile
(
path
):
return
{
"code"
:
-
1
,
"data"
:
None
,
"message"
:
"Path [
%
s] is not a valid file!"
%
path
}
return
{
"code"
:
0
,
"result"
:
getFileInfo
(
path
),
"message"
:
"Get md5 of [
%
s] successfully!"
%
path
}
uploadResource
=
UploadResource
()
tools/build_out/controllers/user.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
models.user
import
UserModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
class
UserResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
UserModel
.
is_delete
==
False
,
UserModel
.
uuid
==
uuid
]
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[
UserModel
.
is_delete
==
False
]
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
order_by
(
UserModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
result
=
UserModel
.
query
.
filter
(
UserModel
.
account
==
params
.
get
(
'account'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
USER_EXISTS
# 密码使用md5加密,可以使用元编程模式劫持,不用手动一个个修改了
# params.update({ "password": utils.md5_encryption(params.get("password")) })
result
=
UserModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
logger
.
info
(
uuid
)
logger
.
info
(
params
)
# handle business
result
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
if
params
:
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
userManager
=
UserResource
()
tools/build_out/controllers/workbench.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-22 04:03:24
LastEditTime: 2021-07-23 00:51:58
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
controllers
\
workbench.py
'''
import
datetime
from
models.user
import
UserModel
from
models.device
import
DeviceModel
from
models.app
import
AppModel
from
models.package
import
PackageModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
# 今日上传应用数 、历史应用总数
# 今日打包次数、历史打包总数
# 今日新增设备数,绑定设备数
# 今日新增开发者,开发者总数
'''
time_now = datetime.now()
#最近30天数据
result = UserModel.query.filter(UserModel.create_time >= time_now - timedelta(days=30)).all()
#最近一周数据
result = UserModel.query.filter(UserModel.create_time >= time_now - timedelta(days=7)).all()
#最近1天数据
result = UserModel.query.filter(UserModel.create_time >= time_now - timedelta(days=1)).all()
#最近12小时
result = UserModel.query.filter(UserModel.create_time >= time_now - timedelta(hours=12)).all()
#最近半小时
result = UserModel.query.filter(UserModel.create_time >= time_now - timedelta(seconds=30)).all()
'''
class
WorkbenchResource
(
object
):
def
__init__
(
self
):
super
()
.
__init__
()
def
get
(
self
,
jwt
=
{}):
if
not
jwt
:
return
None
,
ResponseCode
.
HTTP_INVAILD_REQUEST
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
jwt
.
get
(
"uuid"
))
.
one_or_none
()
if
not
user
:
return
None
,
ResponseCode
.
USER_NOT_EXISTS
today
=
datetime
.
date
.
today
()
tomorrow
=
today
+
datetime
.
timedelta
(
days
=
1
)
logger
.
info
(
user
.
role
)
if
user
.
role
==
1
:
total_user
=
UserModel
.
query
.
filter
()
.
count
()
today_user
=
UserModel
.
query
.
filter
(
UserModel
.
create_at
>=
today
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
),
UserModel
.
create_at
<=
tomorrow
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
))
.
count
()
total_device
=
DeviceModel
.
query
.
filter
()
.
count
()
today_device
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
create_at
>=
today
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
),
DeviceModel
.
create_at
<=
tomorrow
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
))
.
count
()
total_app
=
AppModel
.
query
.
filter
()
.
count
()
today_app
=
AppModel
.
query
.
filter
(
AppModel
.
create_at
>=
today
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
),
AppModel
.
create_at
<=
tomorrow
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
))
.
count
()
total_package
=
PackageModel
.
query
.
filter
()
.
count
()
today_package
=
PackageModel
.
query
.
filter
(
PackageModel
.
create_at
>=
today
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
),
PackageModel
.
create_at
<=
tomorrow
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
))
.
count
()
else
:
total_user
=
UserModel
.
query
.
filter
(
UserModel
.
create_by
==
user
.
id
)
.
count
()
today_user
=
UserModel
.
query
.
filter
(
UserModel
.
create_by
==
user
.
id
,
UserModel
.
create_at
>=
today
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
),
UserModel
.
create_at
<=
tomorrow
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
))
.
count
()
total_device
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
create_by
==
user
.
id
)
.
count
()
today_device
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
create_by
==
user
.
id
,
DeviceModel
.
create_at
>=
today
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
),
DeviceModel
.
create_at
<=
tomorrow
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
))
.
count
()
total_app
=
AppModel
.
query
.
filter
(
AppModel
.
create_by
==
user
.
id
)
.
count
()
today_app
=
AppModel
.
query
.
filter
(
AppModel
.
create_by
==
user
.
id
,
AppModel
.
create_at
>=
today
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
),
AppModel
.
create_at
<=
tomorrow
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
))
.
count
()
total_package
=
PackageModel
.
query
.
filter
(
PackageModel
.
create_by
==
user
.
id
)
.
count
()
today_package
=
PackageModel
.
query
.
filter
(
PackageModel
.
create_by
==
user
.
id
,
PackageModel
.
create_at
>=
today
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
),
PackageModel
.
create_at
<=
tomorrow
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
))
.
count
()
result
=
{
'total_user'
:
total_user
,
'today_user'
:
today_user
,
'total_device'
:
total_device
,
'today_device'
:
today_device
,
'total_app'
:
total_app
,
'today_app'
:
today_app
,
'total_package'
:
total_package
,
'today_package'
:
today_package
}
logger
.
info
(
result
)
return
result
,
ResponseCode
.
HTTP_SUCCESS
workbenchResource
=
WorkbenchResource
()
\ No newline at end of file
tools/build_out/evue_photo.png
deleted
100644 → 0
View file @
32df1548
4.19 KB
tools/build_out/manager.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-28 19:56:22
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
manager.py
'''
'''
Author: your name
Date: 2021-06-15 17:40:09
LastEditTime: 2021-06-30 18:09:51
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\r
esources
\
manager.py
'''
# -*- coding: utf-8 -*-
from
tornado.wsgi
import
WSGIContainer
from
tornado.httpserver
import
HTTPServer
from
tornado.ioloop
import
IOLoop
from
flask_script
import
Manager
from
flask_migrate
import
Migrate
from
application.app
import
create_app
,
db
from
application.config
import
config
# 根据配置初始化app
app
=
create_app
(
config
)
migrate
=
Migrate
(
app
,
db
)
manager
=
Manager
(
app
)
host
,
port
=
tuple
(
config
.
BIND
.
split
(
":"
))
print
(
"===============>"
,
host
,
port
)
@
manager
.
command
def
run
():
"""
生产模式启动命令函数
To use: python3 manager.py run
"""
# app.logger.setLevel(app.config.get('LOG_LEVEL', logging.INFO))
http_server
=
HTTPServer
(
WSGIContainer
(
app
))
http_server
.
listen
(
int
(
port
),
address
=
host
)
IOLoop
.
instance
()
.
start
()
@
manager
.
command
def
debug
():
"""
debug模式启动命令函数
To use: python3 manager.py debug
"""
# app.logger.setLevel(logging.DEBUG)
app
.
run
(
debug
=
True
,
port
=
int
(
port
),
host
=
host
)
if
__name__
==
'__main__'
:
manager
.
run
()
tools/build_out/models/__init__.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-28 15:29:13
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
models
\
__init__.py
'''
'''
Author: your name
Date: 2021-04-22 18:04:10
LastEditTime: 2021-07-27 20:04:43
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\r
esources
\
models
\
__init__.py
'''
# -*- coding: utf-8 -*-
from
sqlalchemy
import
create_engine
from
sqlalchemy
import
Column
,
Integer
,
String
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.ext.declarative
import
declared_attr
,
declarative_base
from
application.app
import
config
class
BaseModelMixin
(
object
):
@
declared_attr
def
__tablename__
(
self
):
return
self
.
__name__
.
lower
()
# __table_args__ = {'mysql_engine': 'InnoDB'}
__mapper_args__
=
{
'always_refresh'
:
True
}
id
=
Column
(
Integer
,
primary_key
=
True
)
BaseModel
=
declarative_base
(
cls
=
BaseModelMixin
)
class
MyModel
(
BaseModel
,
BaseModelMixin
):
__tablename__
=
'evm_store_app_logs'
app_name
=
Column
(
String
(
20
))
app_path
=
Column
(
String
(
32
))
app_version
=
Column
(
String
(
32
))
app_info
=
Column
(
String
(
32
))
create_at
=
Column
(
String
(
32
))
create_by
=
Column
(
Integer
())
class
MyModel2
(
BaseModel
,
BaseModelMixin
):
__tablename__
=
'monitor_request'
host
=
Column
(
String
(
32
))
path
=
Column
(
String
(
32
))
protocol
=
Column
(
String
(
32
))
create_at
=
Column
(
String
(
32
))
# if __name__ == "__main__":
engine
=
create_engine
(
config
.
SQLALCHEMY_DATABASE_URI
)
BaseModel
.
metadata
.
create_all
(
engine
,
checkfirst
=
True
)
Session
=
sessionmaker
(
bind
=
engine
)
session
=
Session
()
# ed_user = MyModel(name='ed', fullname='Ed Jones', password='edspassword')
# session.add(ed_user)
# session.add_all(
# [
# MyModel(name='wendy', fullname='Wendy Williams', password='foobar'),
# MyModel(name='mary', fullname='Mary Contrary', password='xxg527'),
# MyModel(name='fred', fullname='Fred Flinstone', password='blah')
# ]
# )
# session.commit()
# our_user = session.query(MyModel).filter_by(name='ed').first()
# print(our_user)
tools/build_out/models/annex.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
AnnexModel
(
PrimaryModel
):
__tablename__
=
'evm_annex'
app
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
title
=
db
.
Column
(
db
.
String
(
100
),
index
=
True
,
nullable
=
False
,
default
=
''
)
path
=
db
.
Column
(
db
.
String
(
256
),
index
=
True
,
nullable
=
False
,
default
=
''
)
size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
app
,
title
=
''
,
path
=
''
,
size
=
0
):
self
.
app
=
app
self
.
title
=
title
self
.
path
=
path
self
.
size
=
size
def
__repr__
(
self
):
return
'<AnnexModel
%
r>'
%
(
self
.
app
)
def
to_dict
(
self
):
return
{
'app'
:
self
.
app
,
'title'
:
self
.
title
,
'path'
:
self
.
path
,
'size'
:
self
.
size
,
}
class
DeleteAnnexSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AnnexModel
deleteAnnexSchema
=
DeleteAnnexSchema
()
class
GetlistAnnexSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AnnexModel
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
title
=
ma
.
auto_field
()
app
=
ma
.
auto_field
()
getListAnnexSchema
=
GetlistAnnexSchema
()
getListAnnexsSchema
=
GetlistAnnexSchema
(
many
=
True
)
class
GetAnnexSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AnnexModel
app
=
ma
.
auto_field
()
getAnnexSchema
=
GetAnnexSchema
()
tools/build_out/models/app.py
deleted
100644 → 0
View file @
32df1548
# -*- coding: utf-8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
AppModel
(
PrimaryModel
):
__tablename__
=
'evm_app'
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
app_icon
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
category
=
db
.
Column
(
db
.
String
(
50
),
nullable
=
False
)
launcher
=
db
.
Column
(
db
.
String
(
50
),
nullable
=
False
)
developer
=
db
.
Column
(
db
.
String
(
50
),
nullable
=
False
)
download_url
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
,
default
=
''
)
app_file_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_screen_size
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
app_arch
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
,
default
=
''
)
app_review
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
meta_data
=
db
.
Column
(
db
.
String
(
256
),
nullable
=
True
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
app_name
,
app_icon
,
app_version
,
category
=
''
,
launcher
=
''
,
developer
=
0
,
download_url
=
''
,
meta_data
=
''
,
app_file_size
=
0
,
app_screen_size
=
''
,
app_arch
=
''
,
app_review
=
0
,
create_by
=
None
,
create_at
=
None
,
update_by
=
None
,
update_at
=
None
,
remarks
=
""
):
self
.
app_name
=
app_name
self
.
app_icon
=
app_icon
self
.
app_version
=
app_version
self
.
category
=
category
self
.
launcher
=
launcher
self
.
developer
=
developer
self
.
download_url
=
download_url
self
.
app_file_size
=
app_file_size
self
.
app_screen_size
=
app_screen_size
self
.
app_arch
=
app_arch
self
.
app_review
=
app_review
self
.
meta_data
=
meta_data
self
.
create_by
=
create_by
self
.
create_at
=
create_at
self
.
update_by
=
update_by
self
.
update_at
=
update_at
self
.
remarks
=
remarks
def
__repr__
(
self
):
return
'<AppModel
%
r>'
%
(
self
.
app_name
)
def
to_dict
(
self
):
return
{
'uuid'
:
self
.
uuid
,
'app_name'
:
self
.
app_name
,
'app_icon'
:
self
.
app_icon
,
'app_version'
:
self
.
app_version
,
'category'
:
self
.
category
,
'launcher'
:
self
.
launcher
,
'developer'
:
self
.
developer
,
'download_url'
:
self
.
download_url
,
'app_file_size'
:
self
.
app_file_size
,
'app_screen_size'
:
self
.
app_screen_size
,
'app_arch'
:
self
.
app_arch
,
'meta_data'
:
self
.
meta_data
,
'app_review'
:
self
.
app_review
,
'remarks'
:
self
.
remarks
,
"create_by"
:
self
.
create_by
,
"update_by"
:
self
.
update_by
,
"create_at"
:
self
.
create_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
self
.
create_at
else
None
,
"update_at"
:
self
.
update_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
self
.
update_at
else
None
,
}
class
PostAppSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AppModel
meta_data
=
fields
.
String
(
required
=
False
)
app_name
=
ma
.
auto_field
()
app_icon
=
fields
.
String
(
required
=
False
)
app_version
=
ma
.
auto_field
()
category
=
ma
.
auto_field
()
launcher
=
fields
.
String
(
required
=
False
)
developer
=
fields
.
String
(
required
=
False
)
app_screen_size
=
ma
.
auto_field
()
app_arch
=
ma
.
auto_field
()
app_review
=
ma
.
auto_field
(
required
=
False
)
remarks
=
fields
.
String
(
required
=
False
)
logo
=
fields
.
Raw
(
required
=
False
)
fileList
=
fields
.
Raw
(
required
=
False
)
postAppSchema
=
PostAppSchema
()
class
DeleteAppSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AppModel
deleteAppSchema
=
DeleteAppSchema
()
class
GetListAppSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AppModel
uuid
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
page
=
fields
.
Integer
(
required
=
False
,
default
=
1
,
nullable
=
True
)
pageSize
=
fields
.
Integer
(
required
=
False
,
default
=
15
,
nullable
=
True
)
scope
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_name
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_icon
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_version
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
algorithm
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
category
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
launcher
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_arch
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
meta_data
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
download_url
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_file_size
=
fields
.
Integer
(
required
=
False
,
nullable
=
True
)
app_screen_size
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_review
=
fields
.
Integer
(
required
=
False
,
nullable
=
True
)
create_at
=
fields
.
DateTime
(
required
=
False
,
nullable
=
True
)
update_at
=
fields
.
DateTime
(
required
=
False
,
nullable
=
True
)
remarks
=
fields
.
String
(
required
=
False
)
getListAppSchema
=
GetListAppSchema
()
getListAppsSchema
=
GetListAppSchema
(
many
=
True
)
class
GetAppSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AppModel
id
=
fields
.
Integer
(
required
=
False
,
nullable
=
True
)
uuid
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_name
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_icon
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_version
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
algorithm
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
category
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
launcher
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_arch
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
meta_data
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
download_url
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_file_size
=
fields
.
Integer
(
required
=
False
,
nullable
=
True
)
app_screen_size
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_review
=
fields
.
Integer
(
required
=
False
,
nullable
=
True
)
create_at
=
fields
.
DateTime
(
required
=
False
,
nullable
=
True
)
update_at
=
fields
.
DateTime
(
required
=
False
,
nullable
=
True
)
remarks
=
fields
.
String
(
required
=
False
)
getAppSchema
=
GetAppSchema
()
class
PutAppSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AppModel
app_name
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_icon
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_version
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
category
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
launcher
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_arch
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
download_url
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_file_size
=
fields
.
Integer
(
required
=
False
,
nullable
=
True
)
app_screen_size
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
meta_data
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
app_review
=
fields
.
Integer
(
required
=
False
,
nullable
=
True
)
remarks
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
putAppSchema
=
PutAppSchema
()
tools/build_out/models/area.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
AreaModel
(
PrimaryModel
):
__tablename__
=
'evm_area'
areaCode
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
areaName
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
level
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
1
)
cityCode
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
center
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
parentId
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
True
,
default
=
''
)
hasChildren
=
db
.
Column
(
db
.
Boolean
,
nullable
=
True
,
default
=
False
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
areaCode
=
''
,
areaName
=
''
,
level
=
1
,
cityCode
=
0
,
center
=
''
,
parentId
=
''
,
hasChildren
=
False
):
self
.
areaCode
=
areaCode
self
.
areaName
=
areaName
self
.
level
=
level
self
.
cityCode
=
cityCode
self
.
center
=
center
self
.
parentId
=
parentId
self
.
hasChildren
=
hasChildren
def
__repr__
(
self
):
return
'<AreaModel
%
r>'
%
(
self
.
areaCode
)
def
to_dict
(
self
):
return
{
'areaCode'
:
self
.
areaCode
,
'areaName'
:
self
.
areaName
,
'level'
:
self
.
level
,
'cityCode'
:
self
.
cityCode
,
'center'
:
self
.
center
,
'parentId'
:
self
.
parentId
,
'hasChildren'
:
self
.
hasChildren
,
}
class
PostAreaSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AreaModel
areaCode
=
ma
.
auto_field
()
areaName
=
ma
.
auto_field
()
level
=
ma
.
auto_field
()
parentId
=
ma
.
auto_field
()
hasChildren
=
ma
.
auto_field
()
cityCode
=
ma
.
auto_field
()
center
=
ma
.
auto_field
()
postAreaSchema
=
PostAreaSchema
()
class
DeleteAreaSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AreaModel
deleteAreaSchema
=
DeleteAreaSchema
()
class
GetlistAreaSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AreaModel
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
areaName
=
ma
.
auto_field
()
level
=
ma
.
auto_field
()
parentId
=
ma
.
auto_field
()
hasChildren
=
ma
.
auto_field
()
field
=
fields
.
String
(
required
=
False
,
length
=
None
)
getListAreaSchema
=
GetlistAreaSchema
()
getListAreasSchema
=
GetlistAreaSchema
(
many
=
True
)
class
GetAreaSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AreaModel
areaName
=
ma
.
auto_field
()
level
=
ma
.
auto_field
()
parentId
=
ma
.
auto_field
()
hasChildren
=
ma
.
auto_field
()
field
=
fields
.
String
(
required
=
False
,
length
=
None
)
getAreaSchema
=
GetAreaSchema
()
class
PutAreaSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
AreaModel
areaName
=
fields
.
String
(
required
=
False
,
length
=
None
)
level
=
fields
.
Integer
(
required
=
False
)
parentId
=
fields
.
String
(
required
=
False
,
length
=
None
)
hasChildren
=
fields
.
Boolean
(
required
=
False
)
field
=
fields
.
String
(
required
=
False
,
length
=
None
)
putAreaSchema
=
PutAreaSchema
()
tools/build_out/models/base.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-28 09:38:58
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
models
\b
ase.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
uuid
from
datetime
import
datetime
from
application.app
import
db
def
generate_uuid
():
return
uuid
.
uuid1
()
.
hex
class
BaseModel
(
db
.
Model
):
# Flask-SQLAlchemy创建table时,如何声明基类(这个类不会创建表,可以被继承)
# 方法就是把__abstract__这个属性设置为True,这个类为基类,不会被创建为表!
__abstract__
=
True
create_at
=
db
.
Column
(
db
.
DateTime
,
default
=
datetime
.
now
)
create_by
=
db
.
Column
(
db
.
String
(
64
))
update_at
=
db
.
Column
(
db
.
DateTime
,
default
=
datetime
.
now
)
update_by
=
db
.
Column
(
db
.
String
(
64
))
remarks
=
db
.
Column
(
db
.
String
(
255
),
default
=
""
)
is_delete
=
db
.
Column
(
db
.
BOOLEAN
,
default
=
0
)
class
PrimaryModel
(
BaseModel
):
__abstract__
=
True
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
uuid
=
db
.
Column
(
db
.
String
(
64
),
primary_key
=
False
,
default
=
generate_uuid
)
sort
=
db
.
Column
(
db
.
Integer
,
default
=
0
)
class
AutoBaseModel
(
BaseModel
):
__abstract__
=
True
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
sort
=
db
.
Column
(
db
.
Integer
,
default
=
0
)
class
UuidBaseModel
(
BaseModel
):
__abstract__
=
True
id
=
db
.
Column
(
db
.
String
(
64
),
primary_key
=
True
,
default
=
generate_uuid
)
sort
=
db
.
Column
(
db
.
Integer
,
default
=
0
)
class
SortBaseModel
(
BaseModel
):
__abstract__
=
True
sort
=
db
.
Column
(
db
.
Integer
,
default
=
0
)
\ No newline at end of file
tools/build_out/models/device.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
DeviceModel
(
PrimaryModel
):
__tablename__
=
'evm_device'
imei
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
)
name
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
type
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
,
default
=
''
)
desc
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
imei
,
name
=
''
,
type
=
''
,
desc
=
''
,
create_by
=
None
,
create_at
=
None
,
update_by
=
None
,
update_at
=
None
,
remarks
=
""
):
self
.
imei
=
imei
self
.
name
=
name
self
.
type
=
type
self
.
desc
=
desc
self
.
create_by
=
create_by
self
.
create_at
=
create_at
self
.
update_by
=
update_by
self
.
update_at
=
update_at
self
.
remarks
=
remarks
def
__repr__
(
self
):
return
'<DeviceModel
%
r>'
%
(
self
.
imei
)
def
to_dict
(
self
):
return
{
'uuid'
:
self
.
uuid
,
'imei'
:
self
.
imei
,
'name'
:
self
.
name
,
'type'
:
self
.
type
,
'desc'
:
self
.
desc
,
"create_by"
:
self
.
create_by
,
"update_by"
:
self
.
update_by
,
"create_at"
:
self
.
create_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
self
.
create_at
else
None
,
"update_at"
:
self
.
update_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
self
.
update_at
else
None
,
}
class
PostDeviceSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
DeviceModel
imei
=
ma
.
auto_field
()
name
=
ma
.
auto_field
()
type
=
ma
.
auto_field
()
desc
=
ma
.
auto_field
()
postDeviceSchema
=
PostDeviceSchema
()
class
DeleteDeviceSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
DeviceModel
deleteDeviceSchema
=
DeleteDeviceSchema
()
class
GetListDeviceSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
DeviceModel
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
uuid
=
ma
.
auto_field
()
imei
=
ma
.
auto_field
()
name
=
ma
.
auto_field
()
type
=
ma
.
auto_field
()
desc
=
ma
.
auto_field
()
create_at
=
ma
.
auto_field
()
update_at
=
ma
.
auto_field
()
getListDeviceSchema
=
GetListDeviceSchema
()
getListDevicesSchema
=
GetListDeviceSchema
(
many
=
True
)
class
GetDeviceSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
DeviceModel
imei
=
ma
.
auto_field
()
name
=
ma
.
auto_field
()
type
=
ma
.
auto_field
()
getDeviceSchema
=
GetDeviceSchema
()
class
PutDeviceSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
DeviceModel
imei
=
fields
.
String
(
required
=
False
,
length
=
None
)
name
=
fields
.
String
(
required
=
False
,
length
=
None
)
type
=
fields
.
String
(
required
=
False
,
length
=
None
)
desc
=
fields
.
String
(
required
=
False
,
length
=
None
)
putDeviceSchema
=
PutDeviceSchema
()
tools/build_out/models/login.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
json
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
from
webcreator.log
import
logger
class
LoginModel
(
PrimaryModel
):
__tablename__
=
'evm_login'
user
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
login_at
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
user_agent
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
ip
=
db
.
Column
(
db
.
String
(
128
),
nullable
=
False
)
geo_location
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
operator
=
db
.
Column
(
db
.
String
(
50
),
nullable
=
False
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
user
,
login_at
,
user_agent
,
ip
,
geo_location
,
operator
):
self
.
user
=
user
self
.
login_at
=
login_at
self
.
user_agent
=
user_agent
self
.
ip
=
ip
self
.
geo_location
=
geo_location
self
.
operator
=
operator
# def __getattr__(self, key):
# return self.__dict__[key]
# def __getitem__(self, key):
# return self.get(key)
# def __getattribute__(self, value):
# return value
def
__repr__
(
self
):
return
'<LoginModel
%
r>'
%
(
self
.
user
)
def
to_dict
(
self
):
return
{
'login_at'
:
self
.
login_at
,
'user_agent'
:
self
.
user_agent
,
'ip'
:
self
.
ip
,
'geo_location'
:
self
.
geo_location
,
'operator'
:
self
.
operator
,
}
class
PostLoginSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
LoginModel
account
=
fields
.
String
(
required
=
True
,
length
=
64
)
password
=
fields
.
String
(
required
=
True
,
length
=
64
)
postLoginSchema
=
PostLoginSchema
()
class
GetListLoginSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
LoginModel
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
user
=
fields
.
Integer
(
required
=
False
)
login_at
=
fields
.
String
(
required
=
False
)
user_agent
=
fields
.
String
(
required
=
False
)
ip
=
fields
.
String
(
required
=
False
)
geo_location
=
fields
.
String
(
required
=
False
)
operator
=
fields
.
String
(
required
=
False
)
getListLoginSchema
=
GetListLoginSchema
()
getListLoginsSchema
=
GetListLoginSchema
(
many
=
True
)
class
GetLoginSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
LoginModel
user
=
fields
.
Integer
(
required
=
False
)
login_at
=
fields
.
String
(
required
=
False
)
user_agent
=
fields
.
String
(
required
=
False
)
ip
=
fields
.
String
(
required
=
False
)
geo_location
=
fields
.
String
(
required
=
False
)
operator
=
fields
.
String
(
required
=
False
)
getLoginSchema
=
GetLoginSchema
()
tools/build_out/models/menu.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-27 16:19:06
LastEditTime: 2021-07-28 09:23:23
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
models
\
menu.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
application.app
import
db
from
.base
import
PrimaryModel
# from sqlalchemy.orm import relationship
from
sqlalchemy_mptt.mixins
import
BaseNestedSets
class
MenuModel
(
PrimaryModel
,
BaseNestedSets
):
__tablename__
=
'evm_menu'
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
visible
=
db
.
Column
(
db
.
Boolean
)
name
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
True
)
# parent_id = db.Column(db.Integer, db.ForeignKey("evm_menu.id"), default=0, nullable = True) # 这句话会由mptt自动插入进去
path
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
True
)
disabled
=
db
.
Column
(
db
.
Boolean
,
nullable
=
True
,
default
=
False
)
fixed
=
db
.
Column
(
db
.
Boolean
,
nullable
=
False
,
default
=
False
)
has_children
=
db
.
Column
(
db
.
Boolean
,
nullable
=
True
,
default
=
False
)
icon
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
True
,
default
=
''
)
# create_at = db.Column(db.DateTime, default=datetime.now) # 下面这些被注释的字段,都已经从PrimaryModel继承过来了,无需重写
# create_by = db.Column(db.String(64))
# update_at = db.Column(db.DateTime, default=datetime.now)
# update_by = db.Column(db.String(64))
# remarks = db.Column(db.String(255), default="")
# sort = db.Column(db.Integer, default=0)
# is_delete = db.Column(db.BOOLEAN, default=0)
# parent = db.Column(db.Integer, db.ForeignKey('evm_menu.id'), index=True)
# 这句话的含义请百度sqlalchemy表自关联,https://www.jianshu.com/p/fa611ab55dd2
parent
=
db
.
relationship
(
"MenuModel"
,
remote_side
=
[
id
],
backref
=
"ppp"
)
# sqlalchemy_mptt 调优
# sqlalchemy_mptt 在混入ORM对象时,只对rgt, lft, level 设置了索引,导致每次 CRUD操作都需要从头到尾查找。
# 经测试,添加tree_id索引大约能快4倍,添加parent_id大约快100倍,加起来就能够满足快速插入的需求了
# https://www.cnblogs.com/estragon/p/12298128.html
__table_args__
=
(
db
.
Index
(
'right_idx'
,
'rgt'
),
db
.
Index
(
'left_idx'
,
'lft'
),
db
.
Index
(
'level_idx'
,
'level'
),
db
.
Index
(
'treeid_idx'
,
'tree_id'
),
db
.
Index
(
'parent_idx'
,
'parent_id'
),
)
def
__init__
(
self
,
name
=
None
,
parentId
=
None
,
path
=
""
,
disabled
=
False
,
fixed
=
False
,
hasChildren
=
False
,
icon
=
''
,
is_delete
=
False
,
sort
=
0
,
remarks
=
""
):
self
.
name
=
name
self
.
parent_id
=
parentId
self
.
path
=
path
self
.
disabled
=
disabled
self
.
fixed
=
fixed
self
.
has_children
=
hasChildren
self
.
icon
=
icon
self
.
is_delete
=
is_delete
self
.
sort
=
sort
self
.
remarks
=
remarks
def
__repr__
(
self
):
return
'<MenuModel
%
r>'
%
(
self
.
id
)
@
classmethod
def
fields_mapping
(
self
):
return
{
'parendId'
:
'parent_id'
,
'hasChildren'
:
'has_children'
}
def
to_dict
(
self
):
return
{
'id'
:
self
.
id
,
'name'
:
self
.
name
,
'parentId'
:
self
.
parent_id
,
'path'
:
self
.
path
,
'disabled'
:
self
.
disabled
,
'fixed'
:
self
.
fixed
,
'hasChildren'
:
self
.
has_children
,
'icon'
:
self
.
icon
,
'sort'
:
self
.
sort
,
'remark'
:
self
.
remark
,
'deleted'
:
self
.
is_delete
,
'createUser'
:
self
.
create_by
,
'updateUser'
:
self
.
update_by
,
'createTime'
:
self
.
create_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
self
.
create_at
else
None
,
"updateTime"
:
self
.
update_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
self
.
update_at
else
None
,
}
\ No newline at end of file
tools/build_out/models/monitorEvm.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
MonitorEvmModel
(
PrimaryModel
):
__tablename__
=
'evm_monitor_evm'
watch
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
heap_map_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
heap_total_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
heap_used_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
stack_total_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
stack_used_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
watch
,
heap_map_size
=
0
,
heap_total_size
=
0
,
heap_used_size
=
0
,
stack_total_size
=
0
,
stack_used_size
=
0
):
self
.
watch
=
watch
self
.
heap_map_size
=
heap_map_size
self
.
heap_total_size
=
heap_total_size
self
.
heap_used_size
=
heap_used_size
self
.
stack_total_size
=
stack_total_size
self
.
stack_used_size
=
stack_used_size
def
__repr__
(
self
):
return
'<MonitorEvmModel
%
r>'
%
(
self
.
watch
)
def
to_dict
(
self
):
return
{
'watch'
:
self
.
watch
,
'heap_map_size'
:
self
.
heap_map_size
,
'heap_total_size'
:
self
.
heap_total_size
,
'heap_used_size'
:
self
.
heap_used_size
,
'stack_total_size'
:
self
.
stack_total_size
,
'stack_used_size'
:
self
.
stack_used_size
,
}
class
GetListMonitorEvmSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorEvmModel
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
watch
=
ma
.
auto_field
()
getListMonitorEvmSchema
=
GetListMonitorEvmSchema
()
getListMonitorEvmsSchema
=
GetListMonitorEvmSchema
(
many
=
True
)
class
GetMonitorEvmSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorEvmModel
watch
=
ma
.
auto_field
()
getMonitorEvmSchema
=
GetMonitorEvmSchema
()
tools/build_out/models/monitorImage.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
MonitorImageModel
(
PrimaryModel
):
__tablename__
=
'evm_monitor_image'
watch
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
length
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
png_uncompressed_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
png_total_count
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
png_file_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
uri
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
watch
,
length
=
0
,
png_uncompressed_size
=
0
,
png_total_count
=
0
,
png_file_size
=
0
,
uri
=
''
):
self
.
watch
=
watch
self
.
length
=
length
self
.
png_uncompressed_size
=
png_uncompressed_size
self
.
png_total_count
=
png_total_count
self
.
png_file_size
=
png_file_size
self
.
uri
=
uri
def
__repr__
(
self
):
return
'<MonitorImageModel
%
r>'
%
(
self
.
watch
)
def
to_dict
(
self
):
return
{
'watch'
:
self
.
watch
,
'length'
:
self
.
length
,
'png_uncompressed_size'
:
self
.
png_uncompressed_size
,
'png_total_count'
:
self
.
png_total_count
,
'png_file_size'
:
self
.
png_file_size
,
'uri'
:
self
.
uri
,
}
class
GetListMonitorImageSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorImageModel
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
watch
=
ma
.
auto_field
()
getListMonitorImageSchema
=
GetListMonitorImageSchema
()
getListMonitorImagesSchema
=
GetListMonitorImageSchema
(
many
=
True
)
class
GetMonitorImageSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorImageModel
watch
=
ma
.
auto_field
()
getMonitorImageSchema
=
GetMonitorImageSchema
()
tools/build_out/models/monitorLvgl.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
MonitorLvglModel
(
PrimaryModel
):
__tablename__
=
'evm_monitor_lvgl'
watch
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
total_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
free_cnt
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
free_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
free_biggest_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
used_cnt
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
used_pct
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
frag_pct
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
watch
,
total_size
=
0
,
free_cnt
=
0
,
free_size
=
0
,
free_biggest_size
=
0
,
used_cnt
=
0
,
used_pct
=
0
,
frag_pct
=
0
):
self
.
watch
=
watch
self
.
total_size
=
total_size
self
.
free_cnt
=
free_cnt
self
.
free_size
=
free_size
self
.
free_biggest_size
=
free_biggest_size
self
.
used_cnt
=
used_cnt
self
.
used_pct
=
used_pct
self
.
frag_pct
=
frag_pct
def
__repr__
(
self
):
return
'<MonitorLvglModel
%
r>'
%
(
self
.
watch
)
def
to_dict
(
self
):
return
{
'watch'
:
self
.
watch
,
'total_size'
:
self
.
total_size
,
'free_cnt'
:
self
.
free_cnt
,
'free_size'
:
self
.
free_size
,
'free_biggest_size'
:
self
.
free_biggest_size
,
'used_cnt'
:
self
.
used_cnt
,
'used_pct'
:
self
.
used_pct
,
'frag_pct'
:
self
.
frag_pct
,
}
class
GetListMonitorLvglSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorLvglModel
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
watch
=
ma
.
auto_field
()
getListMonitorLvglSchema
=
GetListMonitorLvglSchema
()
getListMonitorLvglsSchema
=
GetListMonitorLvglSchema
(
many
=
True
)
class
GetMonitorLvglSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorLvglModel
watch
=
ma
.
auto_field
()
getMonitorLvglSchema
=
GetMonitorLvglSchema
()
tools/build_out/models/monitorSystem.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-21 18:39:45
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
models
\
monitorSystem.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
MonitorSystemModel
(
PrimaryModel
):
__tablename__
=
'evm_monitor_system'
watch
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
free_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
free_space_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
used_space_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
,
default
=
0
)
host
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
path
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
protocol
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
watch
,
free_size
=
0
,
free_space_size
=
0
,
used_space_size
=
0
,
host
=
''
,
path
=
''
,
protocol
=
''
):
self
.
watch
=
watch
self
.
free_size
=
free_size
self
.
free_space_size
=
free_space_size
self
.
used_space_size
=
used_space_size
self
.
host
=
host
self
.
path
=
path
self
.
protocol
=
protocol
def
__repr__
(
self
):
return
'<MonitorSystemModel
%
r>'
%
(
self
.
watch
)
def
to_dict
(
self
):
return
{
'watch'
:
self
.
watch
,
'free_size'
:
self
.
free_size
,
'free_space_size'
:
self
.
free_space_size
,
'used_space_size'
:
self
.
used_space_size
,
'host'
:
self
.
host
,
'path'
:
self
.
path
,
'protocol'
:
self
.
protocol
,
}
class
GetListMonitorSystemSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorSystemModel
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
watch
=
ma
.
auto_field
()
getListMonitorSystemSchema
=
GetListMonitorSystemSchema
()
getListMonitorSystemsSchema
=
GetListMonitorSystemSchema
(
many
=
True
)
class
GetMonitorSystemSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorSystemModel
watch
=
ma
.
auto_field
()
getMonitorSystemSchema
=
GetMonitorSystemSchema
()
tools/build_out/models/monitorWatch.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
MonitorWatchModel
(
PrimaryModel
):
__tablename__
=
'evm_monitor_watch'
imei
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
,
default
=
''
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
imei
=
''
):
self
.
imei
=
imei
def
__repr__
(
self
):
return
'<MonitorWatchModel
%
r>'
%
(
self
.
imei
)
def
to_dict
(
self
):
return
{
'imei'
:
self
.
imei
,
}
class
GetListMonitorWatchSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorWatchModel
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
imei
=
ma
.
auto_field
()
getListMonitorWatchSchema
=
GetListMonitorWatchSchema
()
getListMonitorWatchsSchema
=
GetListMonitorWatchSchema
(
many
=
True
)
class
GetMonitorWatchSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
MonitorWatchModel
imei
=
ma
.
auto_field
()
getMonitorWatchSchema
=
GetMonitorWatchSchema
()
tools/build_out/models/package.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
class
PackageModel
(
PrimaryModel
):
__tablename__
=
'evm_package'
app
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
package_info
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
algorithm
=
db
.
Column
(
db
.
String
(
50
),
nullable
=
False
,
default
=
'zlib'
)
file_path
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
,
default
=
''
)
source
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
user_agent
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
,
default
=
''
)
download_url
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
,
default
=
''
)
ip
=
db
.
Column
(
db
.
String
(
128
),
nullable
=
False
,
default
=
'127.0.0.1'
)
geo_location
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
,
default
=
''
)
operator
=
db
.
Column
(
db
.
String
(
50
),
nullable
=
False
,
default
=
''
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
app
,
app_version
,
package_info
,
algorithm
=
'zlib'
,
file_path
=
''
,
source
=
0
,
user_agent
=
''
,
download_url
=
''
,
ip
=
'127.0.0.1'
,
geo_location
=
''
,
operator
=
''
,
create_by
=
None
,
create_at
=
None
,
update_by
=
None
,
update_at
=
None
,
remarks
=
""
):
self
.
app
=
app
self
.
app_version
=
app_version
self
.
package_info
=
package_info
self
.
algorithm
=
algorithm
self
.
file_path
=
file_path
self
.
source
=
source
self
.
user_agent
=
user_agent
self
.
download_url
=
download_url
self
.
ip
=
ip
self
.
geo_location
=
geo_location
self
.
operator
=
operator
self
.
create_by
=
create_by
self
.
create_at
=
create_at
self
.
update_by
=
update_by
self
.
update_at
=
update_at
self
.
remarks
=
remarks
def
__repr__
(
self
):
return
'<PackageModel
%
r>'
%
(
self
.
app
)
def
to_dict
(
self
):
return
{
'uuid'
:
self
.
uuid
,
'app_version'
:
self
.
app_version
,
'package_info'
:
self
.
package_info
,
'algorithm'
:
self
.
algorithm
,
'file_path'
:
self
.
file_path
,
'source'
:
self
.
source
,
'user_agent'
:
self
.
user_agent
,
'download_url'
:
self
.
download_url
,
'ip'
:
self
.
ip
,
'geo_location'
:
self
.
geo_location
,
'operator'
:
self
.
operator
,
'remarks'
:
self
.
remarks
,
"create_at"
:
self
.
create_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
self
.
create_at
else
None
,
"update_at"
:
self
.
update_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
self
.
update_at
else
None
,
}
class
GetListPackageSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
PackageModel
id
=
fields
.
Integer
(
required
=
False
,
nullable
=
True
)
uuid
=
fields
.
String
(
required
=
False
,
nullable
=
True
)
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
app
=
fields
.
String
(
required
=
False
)
app_version
=
ma
.
auto_field
()
package_info
=
fields
.
String
(
required
=
False
)
file_path
=
ma
.
auto_field
()
source
=
ma
.
auto_field
()
user_agent
=
ma
.
auto_field
()
download_url
=
ma
.
auto_field
()
ip
=
ma
.
auto_field
()
geo_location
=
fields
.
String
(
required
=
False
)
operator
=
ma
.
auto_field
()
getListPackageSchema
=
GetListPackageSchema
()
getListPackagesSchema
=
GetListPackageSchema
(
many
=
True
)
class
GetPackageSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
PackageModel
app
=
ma
.
auto_field
()
app_version
=
ma
.
auto_field
()
package_info
=
ma
.
auto_field
()
file_path
=
ma
.
auto_field
()
source
=
ma
.
auto_field
()
user_agent
=
ma
.
auto_field
()
download_url
=
ma
.
auto_field
()
ip
=
ma
.
auto_field
()
geo_location
=
ma
.
auto_field
()
operator
=
ma
.
auto_field
()
getPackageSchema
=
GetPackageSchema
()
tools/build_out/models/user.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
from
webcreator
import
utils
from
webcreator.log
import
logger
class
UserModel
(
PrimaryModel
):
__tablename__
=
'evm_user'
username
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
account
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
password
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
role
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
email
=
db
.
Column
(
db
.
String
,
nullable
=
False
,
default
=
''
)
phone
=
db
.
Column
(
db
.
String
,
nullable
=
False
,
default
=
''
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
username
,
account
,
password
,
role
=
0
,
email
=
''
,
phone
=
''
):
self
.
username
=
username
self
.
account
=
account
self
.
password
=
password
self
.
role
=
role
self
.
email
=
email
self
.
phone
=
phone
def
__setattr__
(
self
,
key
,
value
):
# logger.info(f"execute __setattr__:key={key}, value={value}")
if
key
==
'password'
:
self
.
__dict__
[
key
]
=
utils
.
md5_encryption
(
value
)
else
:
self
.
__dict__
[
key
]
=
value
def
__repr__
(
self
):
return
'<UserModel
%
r>'
%
(
self
.
username
)
def
to_dict
(
self
):
return
{
'username'
:
self
.
username
,
'account'
:
self
.
account
,
'password'
:
self
.
password
,
'role'
:
self
.
role
,
'email'
:
self
.
email
,
'phone'
:
self
.
phone
,
}
class
PostUserSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
username
=
ma
.
auto_field
()
account
=
ma
.
auto_field
()
password
=
ma
.
auto_field
()
postUserSchema
=
PostUserSchema
()
class
DeleteUserSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
deleteUserSchema
=
DeleteUserSchema
()
class
GetListUserSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
uuid
=
ma
.
auto_field
()
username
=
ma
.
auto_field
()
account
=
ma
.
auto_field
()
getListUserSchema
=
GetListUserSchema
()
getListUsersSchema
=
GetListUserSchema
(
many
=
True
)
class
GetUserSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
username
=
ma
.
auto_field
()
account
=
ma
.
auto_field
()
getUserSchema
=
GetUserSchema
()
class
PutUserSchema
(
ma
.
SQLAlchemySchema
):
class
Meta
:
# unknown = INCLUDE # 未知字段默认包含
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
account
=
fields
.
String
(
required
=
False
,
allow_none
=
True
)
username
=
fields
.
String
(
required
=
False
,
allow_none
=
True
)
password
=
fields
.
String
(
required
=
False
,
allow_none
=
True
)
putUserSchema
=
PutUserSchema
()
tools/build_out/requirements.txt
deleted
100644 → 0
View file @
32df1548
alembic==1.6.5
aniso8601==9.0.1
appdirs==1.4.4
asgiref==3.3.4
cffi==1.14.5
click==8.0.1
colorama==0.4.4
Flask==2.0.1
Flask-JWT-Extended==4.2.1
flask-marshmallow==0.14.0
Flask-Migrate==3.0.1
Flask-RESTful==0.3.9
Flask-Script==2.0.6
Flask-SQLAlchemy==2.5.1
fs==2.4.13
gevent==21.1.2
greenlet==1.1.0
gunicorn==20.1.0
h11==0.12.0
hashids==1.3.1
importlib-metadata==4.6.1
itsdangerous==2.0.1
Jinja2==3.0.1
Mako==1.1.4
MarkupSafe==2.0.1
marshmallow==3.12.1
marshmallow-sqlalchemy==0.26.1
pycparser==2.20
PyJWT==2.1.0
python-dateutil==2.8.1
python-editor==1.0.4
pytz==2021.1
six==1.16.0
SQLAlchemy==1.4.17
sqlalchemy-mptt==0.2.5
tornado==6.1
typing-extensions==3.10.0.0
uvicorn==0.14.0
Werkzeug==2.0.1
zipp==3.5.0
zope.event==4.5.0
zope.interface==5.4.0
tools/build_out/result.json
deleted
100644 → 0
View file @
32df1548
{
"directories"
:
[],
"files"
:
[{
"basename"
:
"details.md5"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"md5"
,
"filename"
:
"details"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/details.md5"
,
"size"
:
16
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"didi.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"didi"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/didi.png"
,
"size"
:
6417
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"evue_appstore.md5"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"md5"
,
"filename"
:
"evue_appstore"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/evue_appstore.md5"
,
"size"
:
16
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"download.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"download"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/download.png"
,
"size"
:
356
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"aiqiyi.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"aiqiyi"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/aiqiyi.png"
,
"size"
:
4999
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"alipay.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"alipay"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/alipay.png"
,
"size"
:
3545
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"evue_appstore.evue"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"evue"
,
"filename"
:
"evue_appstore"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/evue_appstore.evue"
,
"size"
:
1128
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"application_method.js"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"js"
,
"filename"
:
"application_method"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/application_method.js"
,
"size"
:
5041
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"qq.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"qq"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/qq.png"
,
"size"
:
5702
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"evm_store_64_64.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"evm_store_64_64"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/evm_store_64_64.png"
,
"size"
:
1189
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"evue_launcher.md5"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"md5"
,
"filename"
:
"evue_launcher"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/evue_launcher.md5"
,
"size"
:
16
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"enter.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"enter"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/enter.png"
,
"size"
:
700
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"call.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"call"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/call.png"
,
"size"
:
1266
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"camera.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"camera"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/camera.png"
,
"size"
:
3853
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"memory_management.js"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"js"
,
"filename"
:
"memory_management"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/memory_management.js"
,
"size"
:
4019
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"find_watch.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"find_watch"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/find_watch.png"
,
"size"
:
6352
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"yy.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"yy"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/yy.png"
,
"size"
:
5690
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"index.evue"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"evue"
,
"filename"
:
"index"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/index.evue"
,
"size"
:
14268
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"aliqua.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"aliqua"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/aliqua.png"
,
"size"
:
3120
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"ai-assistant.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"ai-assistant"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/ai-assistant.png"
,
"size"
:
5068
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"call2.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"call2"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/call2.png"
,
"size"
:
977
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"baidutieba.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"baidutieba"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/baidutieba.png"
,
"size"
:
3456
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"evue_launcher.evue"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"evue"
,
"filename"
:
"evue_launcher"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/evue_launcher.evue"
,
"size"
:
12816
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"installed.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"installed"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/installed.png"
,
"size"
:
1038
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"movie.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"movie"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/movie.png"
,
"size"
:
3816
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"like.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"like"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/like.png"
,
"size"
:
357
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"qq_music.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"qq_music"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/qq_music.png"
,
"size"
:
4030
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"details.evue"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"evue"
,
"filename"
:
"details"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/details.evue"
,
"size"
:
12448
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"backspace.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"backspace"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/backspace.png"
,
"size"
:
556
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"blueteeth.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"blueteeth"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/blueteeth.png"
,
"size"
:
868
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"appstore_application.json"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"json"
,
"filename"
:
"appstore_application"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/appstore_application.json"
,
"size"
:
213
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"epk.json"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"json"
,
"filename"
:
"epk"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/epk.json"
,
"size"
:
505
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"tool.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"tool"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/tool.png"
,
"size"
:
2531
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"360.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"360"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/360.png"
,
"size"
:
4038
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"call3.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"call3"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/call3.png"
,
"size"
:
756
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"gaode.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"gaode"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/gaode.png"
,
"size"
:
3923
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"voice.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"voice"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/voice.png"
,
"size"
:
3787
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"close.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"close"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/close.png"
,
"size"
:
971
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"music.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"music"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/music.png"
,
"size"
:
2880
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"index.md5"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"md5"
,
"filename"
:
"index"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/index.md5"
,
"size"
:
16
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"360kids.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"360kids"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/360kids.png"
,
"size"
:
5168
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"
\u
542f
\u
52a8
\u
5668.json"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"json"
,
"filename"
:
"
\u
542f
\u
52a8
\u
5668"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/
\u
542f
\u
52a8
\u
5668.json"
,
"size"
:
4708
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"back.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"back"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/back.png"
,
"size"
:
399
,
"timestamp"
:
1626938854
,
"type"
:
"file"
},
{
"basename"
:
"setup.png"
,
"dirname"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src"
,
"extension"
:
"png"
,
"filename"
:
"setup"
,
"path"
:
"
\u
542f
\u
52a8
\u
5668-1.0.1-2-20210722152734/src/setup.png"
,
"size"
:
937
,
"timestamp"
:
1626938854
,
"type"
:
"file"
}]}
\ No newline at end of file
tools/build_out/start.sh
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env bash
###
# @Author: your name
# @Date: 2021-07-15 09:33:39
# @LastEditTime: 2021-07-23 00:55:33
# @LastEditors: Please set LastEditors
# @Description: In User Settings Edit
# @FilePath: \evm-store\backend\start.sh
###
Cur_Dir
=
$(
pwd
)
source
venv/bin/activate
nohup
${
Cur_Dir
}
/venv/bin/python3
${
Cur_Dir
}
/manager.py run
>
running.log 2>&1 &
tools/build_out/tests/database_migration.go
deleted
100644 → 0
View file @
32df1548
/*
* @Author: your name
* @Date: 2021-07-21 13:02:17
* @LastEditTime: 2021-07-21 13:09:34
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \evm-store\tools\database_migration.go
*/
package
main
import
(
"database/sql"
"fmt"
_
"github.com/mattn/go-sqlite3"
)
func
main
()
{
fmt
.
Println
(
"打开数据"
)
db
,
err
:=
sql
.
Open
(
"sqlite3"
,
"./evue_store.db"
)
checkErr
(
err
)
fmt
.
Println
(
"生成数据表"
)
sql_table
:=
`
CREATE TABLE IF NOT EXISTS "userinfo" (
"uid" INTEGER PRIMARY KEY AUTOINCREMENT,
"username" VARCHAR(64) NULL,
"departname" VARCHAR(64) NULL,
"created" TIMESTAMP default (datetime('now', 'localtime'))
);
CREATE TABLE IF NOT EXISTS "userdeatail" (
"uid" INT(10) NULL,
"intro" TEXT NULL,
"profile" TEXT NULL,
PRIMARY KEY (uid)
);
`
db
.
Exec
(
sql_table
)
//插入数据
fmt
.
Print
(
"插入数据, ID="
)
stmt
,
err
:=
db
.
Prepare
(
"INSERT INTO userinfo(username, departname) values(?, ?)"
)
checkErr
(
err
)
res
,
err
:=
stmt
.
Exec
(
"astaxie"
,
"研发部门"
)
checkErr
(
err
)
id
,
err
:=
res
.
LastInsertId
()
checkErr
(
err
)
fmt
.
Println
(
id
)
//更新数据
fmt
.
Print
(
"更新数据 "
)
stmt
,
err
=
db
.
Prepare
(
"update userinfo set username=? where uid=?"
)
checkErr
(
err
)
res
,
err
=
stmt
.
Exec
(
"astaxieupdate"
,
id
)
checkErr
(
err
)
affect
,
err
:=
res
.
RowsAffected
()
checkErr
(
err
)
fmt
.
Println
(
affect
)
//查询数据
fmt
.
Println
(
"查询数据"
)
rows
,
err
:=
db
.
Query
(
"SELECT * FROM userinfo"
)
checkErr
(
err
)
for
rows
.
Next
()
{
var
uid
int
var
username
string
var
department
string
var
created
string
err
=
rows
.
Scan
(
&
uid
,
&
username
,
&
department
,
&
created
)
checkErr
(
err
)
fmt
.
Println
(
uid
,
username
,
department
,
created
)
}
/*
//删除数据
fmt.Println("删除数据")
stmt, err = db.Prepare("delete from userinfo where uid=?")
checkErr(err)
res, err = stmt.Exec(id)
checkErr(err)
affect, err = res.RowsAffected()
checkErr(err)
fmt.Println(affect)
*/
db
.
Close
()
}
func
checkErr
(
err
error
)
{
if
err
!=
nil
{
panic
(
err
)
}
}
tools/build_out/tests/database_migration.py
deleted
100644 → 0
View file @
32df1548
# -*- coding: utf-8 -*-
'''
Author: your name
Date: 2021-07-20 19:04:27
LastEditTime: 2021-07-21 20:01:56
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\
database_migration.py
'''
import
os
import
sqlite3
import
uuid
from
datetime
import
datetime
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
print
(
"####>>>"
,
BASE_DIR
)
start
=
datetime
.
now
()
print
(
"start at:"
,
start
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
))
source_conn
=
sqlite3
.
connect
(
os
.
path
.
join
(
BASE_DIR
,
"app-store.db"
))
source_cur
=
source_conn
.
cursor
()
target_db
=
os
.
path
.
join
(
BASE_DIR
,
"evue-store.db"
)
target_conn
=
sqlite3
.
connect
(
target_db
)
target_cur
=
source_conn
.
cursor
()
with
open
(
"database_migration.sql"
,
"w+"
)
as
fd
:
# 更新user表
opts
=
[
[
2
,
39
],
[
3
,
40
],
[
4
,
41
]
]
sqls
=
[
"update evm_store_apps set create_by = {a} where create_by = {b};"
,
"update evm_store_apps set update_by = {a} where update_by = {b};"
,
"update evm_store_annex set create_by = {a} where create_by = {b};"
,
"update evm_store_annex set update_by = {a} where update_by = {b};"
,
"update evm_store_app_logs set create_by = {a} where create_by = {b};"
,
"update evm_store_build_logs set create_by = {a} where create_by = {b};"
,
"update evm_store_build_logs set update_by = {a} where update_by = {b};"
,
"update evm_store_device set create_by = {a} where create_by = {b};"
,
"update evm_store_device set update_by = {a} where update_by = {b};"
,
"update evm_store_login_logs set create_by = {a} where create_by = {b};"
,
]
for
s
in
sqls
:
for
o
in
opts
:
sql_str
=
s
.
format
(
a
=
o
[
0
],
b
=
o
[
1
])
source_cur
.
execute
(
sql_str
)
source_conn
.
commit
()
# 更新app logs 表
sql_str
=
"select create_at from evm_store_app_logs"
source_cur
.
execute
(
sql_str
)
res
=
source_cur
.
fetchall
()
for
line
in
res
:
sql_str
=
"select id from evm_store_apps where strftime('
%
s', evm_store_apps.create_at) - strftime('
%
s', '{b}') < 2"
.
format
(
b
=
line
[
0
])
source_cur
.
execute
(
sql_str
)
tmp
=
source_cur
.
fetchone
()
if
tmp
:
sql_str
=
"UPDATE evm_store_app_logs SET remarks = {a};"
.
format
(
a
=
tmp
[
0
])
source_cur
.
execute
(
sql_str
)
source_conn
.
commit
()
# 先插入user表
source_cur
.
execute
(
'SELECT account, username, password, email, phone, create_at, create_by, update_at, update_by FROM evm_store_user'
)
sql
=
"insert into evm_user (id, uuid, account, username, password, email, phone, create_at, create_by, update_at, update_by, is_delete, role) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', {i}, '{j}', {k}, 0, 0);"
res
=
source_cur
.
fetchall
()
i
=
0
for
line
in
res
:
i
+=
1
sql_str
=
sql
.
format
(
a
=
i
,
b
=
uuid
.
uuid1
()
.
hex
,
c
=
line
[
0
],
d
=
line
[
1
],
e
=
line
[
2
],
f
=
line
[
3
],
g
=
line
[
4
],
h
=
line
[
5
],
i
=
line
[
6
],
j
=
line
[
7
],
k
=
line
[
8
])
print
(
"sql:"
,
sql_str
)
# target_cur.execute(sql_str)
fd
.
write
(
sql_str
+
"
\n
"
)
target_conn
.
commit
()
# login logs
source_cur
.
execute
(
'SELECT id, username, ip, address, create_at, create_by, remarks FROM evm_store_login_logs'
)
res
=
source_cur
.
fetchall
()
sql
=
"insert into evm_login (uuid, user, login_at, user_agent, ip, geo_location, operator, create_at, create_by, update_at, update_by, is_delete) values ('{b}', {c}, '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', {j}, '{k}', {l}, 0);"
for
line
in
res
:
sql_str
=
sql
.
format
(
b
=
uuid
.
uuid1
()
.
hex
,
c
=
line
[
5
],
d
=
line
[
6
],
e
=
""
,
f
=
line
[
2
],
g
=
line
[
3
],
h
=
""
,
i
=
line
[
4
],
j
=
line
[
5
],
k
=
line
[
4
],
l
=
line
[
5
])
# target_cur.execute(sql_str)
fd
.
write
(
sql_str
+
"
\n
"
)
target_conn
.
commit
()
# 更新app_url字段
sql
=
"select app, app_path from evm_store_build_logs"
source_cur
.
execute
(
sql
)
res
=
source_cur
.
fetchall
()
for
line
in
res
:
sql_str
=
string
=
"update evm_store_apps set app_url = '{u}' where id = {a}"
.
format
(
u
=
line
[
1
],
a
=
line
[
0
])
source_cur
.
execute
(
sql_str
)
# fd.write(sql_str + "\n")
target_conn
.
commit
()
# annex
source_cur
.
execute
(
'SELECT id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete FROM evm_store_annex'
)
res
=
source_cur
.
fetchall
()
sql
=
"insert into evm_annex (id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', {c}, '{d}', '{e}', {f}, '{g}', {h}, '{i}', {j}, 0);"
for
line
in
res
:
if
not
line
[
2
]:
continue
sql_str
=
sql
.
format
(
a
=
line
[
0
],
b
=
uuid
.
uuid1
()
.
hex
,
c
=
line
[
2
],
d
=
line
[
3
],
e
=
line
[
4
]
or
""
,
f
=
line
[
5
],
g
=
line
[
6
],
h
=
line
[
7
],
i
=
line
[
8
],
j
=
line
[
9
])
# target_cur.execute(sql_str)
fd
.
write
(
sql_str
+
"
\n
"
)
target_conn
.
commit
()
# app
source_cur
.
execute
(
'SELECT id, app_name, app_icon, app_version, category, app_url, app_desc, create_at, create_by ,update_at, update_by, is_delete FROM evm_store_apps'
)
res
=
source_cur
.
fetchall
()
sql
=
"insert into evm_app (id, uuid, app_name, app_icon, app_version, category, download_url, app_screen_size, app_arch, app_review, meta_data, remarks, create_at, create_by, update_at, update_by, is_delete, launcher, developer, app_file_size) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', '{j}', '{k}', '{l}', '{m}', {n}, '{o}', {p}, 0, `""`, `""`, 0);"
for
line
in
res
:
sql_str
=
sql
.
format
(
a
=
line
[
0
],
b
=
uuid
.
uuid1
()
.
hex
,
c
=
line
[
1
],
d
=
line
[
2
],
e
=
line
[
3
],
f
=
line
[
4
],
g
=
line
[
5
],
h
=
"240 * 240"
,
i
=
"ASR3601"
,
j
=
0
,
k
=
'{}'
,
l
=
line
[
6
],
m
=
line
[
7
],
n
=
line
[
8
],
o
=
line
[
9
],
p
=
line
[
10
])
# target_cur.execute(sql_str)
fd
.
write
(
sql_str
+
"
\n
"
)
target_conn
.
commit
()
# device
source_cur
.
execute
(
'SELECT id, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete FROM evm_store_device'
)
res
=
source_cur
.
fetchall
()
sql
=
"insert into evm_device (id, uuid, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', {h}, '{i}', {j}, {k});"
for
line
in
res
:
sql_str
=
sql
.
format
(
a
=
line
[
0
],
b
=
uuid
.
uuid1
()
.
hex
,
c
=
line
[
1
],
d
=
line
[
2
],
e
=
line
[
3
],
f
=
line
[
4
],
g
=
line
[
5
],
h
=
line
[
6
],
i
=
line
[
7
],
j
=
line
[
8
],
k
=
line
[
9
])
# target_cur.execute(sql_str)
fd
.
write
(
sql_str
+
"
\n
"
)
target_conn
.
commit
()
# app log & build log
# 先插入app log
source_cur
.
execute
(
'SELECT id, uuid, app_name, app_path, app_version, app_info, create_at, create_by, remarks FROM evm_store_app_logs'
)
res
=
source_cur
.
fetchall
()
sql
=
"insert into evm_package (id, uuid, app, app_path, app_version, app_info, create_at, create_by, update_at, update_by, is_delete, source) values ({a}, '{b}', '{c}', '{d}', '{e}', `'{f}'`, '{g}', {h}, '{i}', {j}, {k}, {l});"
for
line
in
res
:
# 根据时间查找app
print
(
">>>>>>>>>>>>"
,
line
[
6
],
line
[
8
])
if
not
line
[
8
]
or
(
isinstance
(
line
[
8
],
str
)
and
len
(
line
[
8
])
==
0
):
print
(
"remarks is none"
)
continue
sql_str
=
"select id from evm_store_apps where id = {a}"
.
format
(
a
=
int
(
line
[
8
]))
source_cur
.
execute
(
sql_str
)
tmp
=
source_cur
.
fetchone
()
if
not
tmp
:
print
(
"app not found"
)
continue
s
=
1
if
line
[
5
]
and
isinstance
(
line
[
5
],
str
)
and
line
[
5
]
.
find
(
"evueapps"
)
>
-
1
else
0
sql_str
=
sql
.
format
(
a
=
line
[
0
],
b
=
uuid
.
uuid1
()
.
hex
,
c
=
tmp
[
0
],
d
=
line
[
3
],
e
=
line
[
4
],
f
=
line
[
5
],
g
=
line
[
6
],
h
=
line
[
7
],
i
=
line
[
6
],
j
=
line
[
7
],
k
=
0
,
l
=
s
)
# target_cur.execute(sql_str)
fd
.
write
(
sql_str
+
"
\n
"
)
target_conn
.
commit
()
# 然后查询出所有build log记录,遍历这些记录
# 在循环里,查询这一条记录是否已经存在(根据app_path),不存在则插入
source_cur
.
execute
(
'SELECT id, uuid, app, app_path, app_info, source, create_at, create_by, update_at, update_by, is_delete FROM evm_store_build_logs'
)
res
=
source_cur
.
fetchall
()
sql
=
"insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, source, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', {g}, '{h}', {i}, '{j}', {k}, {l});"
for
line
in
res
:
sql_str
=
"select id, uuid, app_path from evm_store_app_logs where app_path = '{}'"
.
format
(
line
[
3
])
source_cur
.
execute
(
sql_str
)
tmp
=
source_cur
.
fetchone
()
print
(
"=======>"
,
line
[
0
])
if
tmp
:
print
(
"app_path not equal"
)
continue
print
(
"===========>"
,
line
)
sql_str
=
"select app_name, app_version from evm_store_apps where id == {id}"
.
format
(
id
=
line
[
2
])
source_cur
.
execute
(
sql_str
)
app
=
source_cur
.
fetchone
()
print
(
"app:"
,
app
)
if
app
:
s
=
1
if
line
[
5
]
and
isinstance
(
line
[
5
],
str
)
and
line
[
5
]
.
find
(
"evueapps"
)
>
-
1
else
0
sql_str
=
sql
.
format
(
a
=
line
[
0
],
b
=
uuid
.
uuid1
()
.
hex
,
c
=
app
[
0
],
d
=
line
[
3
],
e
=
app
[
1
],
f
=
line
[
4
],
g
=
s
,
h
=
line
[
6
],
i
=
line
[
7
],
j
=
line
[
8
],
k
=
line
[
9
],
l
=
line
[
10
])
# target_cur.execute(sql_str)
fd
.
write
(
sql_str
+
"
\n
"
)
target_conn
.
commit
()
print
(
"next >>>>>>>>>>>"
)
print
(
"finished!!!"
)
target_conn
.
commit
()
target_conn
.
close
()
source_conn
.
commit
()
source_conn
.
close
()
print
(
"spend time:"
,
datetime
.
now
()
-
start
)
\ No newline at end of file
tools/build_out/tests/go.mod
deleted
100644 → 0
View file @
32df1548
module tool
go 1.16
require github.com/mattn/go-sqlite3 v1.14.8
tools/build_out/tests/go.sum
deleted
100644 → 0
View file @
32df1548
github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU=
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
tools/build_out/tests/http_interval.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-22 19:01:41
LastEditTime: 2021-07-26 17:41:15
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\t
ests
\
http_interval.py
'''
import
json
import
time
import
random
import
requests
from
threading
import
Timer
,
Thread
def
send_request
(
imei
):
payload
=
{
"system"
:
{
"free_size"
:
1769792
,
"free_space_size"
:
5156864
,
"used_space_size"
:
1134592
},
"lvgl"
:
{
"total_size"
:
100
,
"free_cnt"
:
50
,
"free_size"
:
23
,
"free_biggest_size"
:
53
,
"used_cnt"
:
78
,
"used_pct"
:
43
,
"frag_pct"
:
0
},
"evm"
:
{
"heap_total_size"
:
2097152
,
"heap_used_size"
:
575072
,
"heap_map_size"
:
8192
,
"stack_total_size"
:
102400
,
"stack_used_size"
:
1312
},
"image"
:
[
{
"uri"
:
"evue_launcher"
,
"length"
:
13515
,
"png_total_count"
:
0
,
"png_uncompressed_size"
:
0
,
"png_file_size"
:
0
},
{
"uri"
:
"kdgs_1_startup"
,
"length"
:
3666
,
"png_total_count"
:
0
,
"png_uncompressed_size"
:
0
,
"png_file_size"
:
0
},
{
"uri"
:
"kdgs_1_index"
,
"length"
:
5482
,
"png_total_count"
:
0
,
"png_uncompressed_size"
:
0
,
"png_file_size"
:
0
},
{
"uri"
:
"kdgs_1_story"
,
"length"
:
5509
,
"png_total_count"
:
0
,
"png_uncompressed_size"
:
0
,
"png_file_size"
:
0
},
{
"uri"
:
"kdgs_1_storyList"
,
"length"
:
9196
,
"png_total_count"
:
0
,
"png_uncompressed_size"
:
0
,
"png_file_size"
:
0
},
{
"uri"
:
"kdgs_1_storyPlay"
,
"length"
:
25791
,
"png_total_count"
:
6
,
"png_uncompressed_size"
:
319376
,
"png_file_size"
:
10770
,
"png_detail"
:
[
{
"uri"
:
"C:/../../test/watch_appstore/kdgs_1_playBackground.png"
,
"filesize"
:
7774
,
"uncompressed_size"
:
259200
,
"ratio"
:
33.341908
},
{
"uri"
:
"C:/../../test/watch_appstore/kdgs_1_playLb.png"
,
"filesize"
:
482
,
"uncompressed_size"
:
12544
,
"ratio"
:
26.024897
},
{
"uri"
:
"C:/../../test/watch_appstore/kdgs_1_playNLike.png"
,
"filesize"
:
1094
,
"uncompressed_size"
:
12544
,
"ratio"
:
11.466179
},
{
"uri"
:
"C:/../../test/watch_appstore/kdgs_1_playYl.png"
,
"filesize"
:
745
,
"uncompressed_size"
:
12544
,
"ratio"
:
16.837584
},
{
"uri"
:
"C:/../../test/watch_appstore/kdgs_1_playNext.png"
,
"filesize"
:
484
,
"uncompressed_size"
:
12544
,
"ratio"
:
25.917355
},
{
"uri"
:
"C:/../../test/watch_appstore/kdgs_1_play_bs.png"
,
"filesize"
:
191
,
"uncompressed_size"
:
10000
,
"ratio"
:
52.356022
}
]}
],
"imei"
:
imei
,
"datetime"
:
{
"second"
:
55
,
"minute"
:
48
,
"hour"
:
15
,
"day"
:
21
,
"month"
:
7
,
"year"
:
2021
,
"weekday"
:
3
}
}
while
True
:
for
item
in
payload
.
get
(
"image"
):
item
.
update
({
'length'
:
0
,
'png_total_count'
:
0
,
'png_uncompressed_size'
:
0
,
'png_file_size'
:
0
})
rand_index
=
random
.
randint
(
0
,
len
(
payload
.
get
(
"image"
)))
if
rand_index
<
len
(
payload
.
get
(
"image"
)):
print
(
"------------------------------>"
)
else
:
rand_index
=
rand_index
-
1
print
(
"rand_index ==>"
,
rand_index
)
payload
.
get
(
"image"
)[
rand_index
]
.
update
({
'length'
:
random
.
randint
(
0
,
10000
),
'png_total_count'
:
random
.
randint
(
0
,
10000
),
'png_uncompressed_size'
:
random
.
randint
(
100
,
100000
),
'png_file_size'
:
random
.
randint
(
0
,
10000
)
})
r
=
requests
.
post
(
"http://localhost:3000/api/v1/evm_store/monitor"
,
data
=
json
.
dumps
(
payload
))
print
(
r
.
status_code
)
print
(
r
.
json
())
time
.
sleep
(
3
)
class
myThread
(
Thread
):
def
__init__
(
self
,
threadID
,
name
,
counter
,
imei
):
Thread
.
__init__
(
self
)
self
.
threadID
=
threadID
self
.
name
=
name
self
.
counter
=
counter
self
.
imei
=
imei
def
run
(
self
):
print
(
"开始线程:"
+
self
.
name
)
print
(
self
.
counter
,
self
.
imei
)
send_request
(
self
.
imei
)
print
(
"退出线程:"
+
self
.
name
)
if
__name__
==
"__main__"
:
# send_request()
# 创建新线程
thread1
=
myThread
(
1
,
"Thread-1"
,
1
,
"352099001761481"
)
thread2
=
myThread
(
2
,
"Thread-2"
,
2
,
"866866040000447"
)
# 开启新线程
thread1
.
start
()
thread2
.
start
()
thread1
.
join
()
thread2
.
join
()
print
(
"退出主线程"
)
tools/build_out/tests/test_sqlalchemy_sqlite.py
deleted
100644 → 0
View file @
32df1548
import
sqlalchemy
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy
import
Column
,
Integer
,
String
Base
=
declarative_base
()
print
(
sqlalchemy
.
__version__
)
# where <path> is relative:
engine
=
create_engine
(
'sqlite:///test.db'
)
# Unix/Mac - 4 initial slashes in total
# engine = create_engine('sqlite:////absolute/path/to/foo.db')
# # Windows
# engine = create_engine('sqlite:///C:\\path\\to\\foo.db')
# # Windows alternative using raw string
# engine = create_engine(r'sqlite:///C:\path\to\foo.db')
# 定义映射类User,其继承上一步创建的Base
class
User
(
Base
):
# 指定本类映射到users表
__tablename__
=
'users'
# 如果有多个类指向同一张表,那么在后边的类需要把extend_existing设为True,表示在已有列基础上进行扩展
# 或者换句话说,sqlalchemy允许类是表的字集
# __table_args__ = {'extend_existing': True}
# 如果表在同一个数据库服务(datebase)的不同数据库中(schema),可使用schema参数进一步指定数据库
# __table_args__ = {'schema': 'test_database'}
# 各变量名一定要与表的各字段名一样,因为相同的名字是他们之间的唯一关联关系
# 从语法上说,各变量类型和表的类型可以不完全一致,如表字段是String(64),但我就定义成String(32)
# 但为了避免造成不必要的错误,变量的类型和其对应的表的字段的类型还是要相一致
# sqlalchemy强制要求必须要有主键字段不然会报错,如果要映射一张已存在且没有主键的表,那么可行的做法是将所有字段都设为primary_key=True
# 不要看随便将一个非主键字段设为primary_key,然后似乎就没报错就能使用了,sqlalchemy在接收到查询结果后还会自己根据主键进行一次去重
# 指定id映射到id字段; id字段为整型,为主键,自动增长(其实整型主键默认就自动增长)
id
=
Column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
# 指定name映射到name字段; name字段为字符串类形,
name
=
Column
(
String
(
20
))
fullname
=
Column
(
String
(
32
))
password
=
Column
(
String
(
32
))
# __repr__方法用于输出该类的对象被print()时输出的字符串,如果不想写可以不写
def
__repr__
(
self
):
return
"<User(name='
%
s', fullname='
%
s', password='
%
s')>"
%
(
self
.
name
,
self
.
fullname
,
self
.
password
)
def
get_dynamic_table_name_class
(
table_name
):
# 定义一个内部类
class
TestModel
(
Base
):
# 给表名赋值
__tablename__
=
table_name
__table_args__
=
{
'extend_existing'
:
True
}
username
=
Column
(
String
(
32
),
primary_key
=
True
)
password
=
Column
(
String
(
32
))
# 把动态设置表名的类返回去
return
TestModel
# 查看映射对应的表
print
(
User
.
__table__
)
# 创建数据表。一方面通过engine来连接数据库,另一方面根据哪些类继承了Base来决定创建哪些表
# checkfirst=True,表示创建表前先检查该表是否存在,如同名表已存在则不再创建。其实默认就是True
Base
.
metadata
.
create_all
(
engine
,
checkfirst
=
True
)
# 上边的写法会在engine对应的数据库中创建所有继承Base的类对应的表,但很多时候很多只是用来则试的或是其他库的
# 此时可以通过tables参数指定方式,指示仅创建哪些表
# Base.metadata.create_all(engine,tables=[Base.metadata.tables['users']],checkfirst=True)
# 在项目中由于model经常在别的文件定义,没主动加载时上边的写法可能写导致报错,可使用下边这种更明确的写法
# User.__table__.create(engine, checkfirst=True)
# 另外我们说这一步的作用是创建表,当我们已经确定表已经在数据库中存在时,我完可以跳过这一步
# 针对已存放有关键数据的表,或大家共用的表,直接不写这创建代码更让人心里踏实
# engine是2.2中创建的连接
Session
=
sessionmaker
(
bind
=
engine
)
# 创建Session类实例
session
=
Session
()
if
__name__
==
"__main__"
:
# 创建User类实例
ed_user
=
User
(
name
=
'ed'
,
fullname
=
'Ed Jones'
,
password
=
'edspassword'
)
# 将该实例插入到users表
session
.
add
(
ed_user
)
# 一次插入多条记录形式
session
.
add_all
(
[
User
(
name
=
'wendy'
,
fullname
=
'Wendy Williams'
,
password
=
'foobar'
),
User
(
name
=
'mary'
,
fullname
=
'Mary Contrary'
,
password
=
'xxg527'
),
User
(
name
=
'fred'
,
fullname
=
'Fred Flinstone'
,
password
=
'blah'
)
]
)
# 当前更改只是在session中,需要使用commit确认更改才会写入数据库
session
.
commit
()
our_user
=
session
.
query
(
User
)
.
filter_by
(
name
=
'ed'
)
.
first
()
print
(
our_user
)
\ No newline at end of file
tools/build_out/views/__init__.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-27 19:08:58
LastEditTime: 2021-07-28 16:15:39
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\v
iews
\
__init__.py
'''
# -*- coding: utf-8 -*-
from
flask
import
Blueprint
from
flask_restful
import
Api
from
.
import
area
from
.
import
app
from
.
import
package
from
.
import
user
from
.
import
login
from
.
import
device
from
.
import
annex
from
.
import
monitorWatch
from
.
import
monitorSystem
from
.
import
monitorLvgl
from
.
import
monitorImage
from
.
import
monitorEvm
from
.
import
menu
from
.
import
file
from
.
import
openapi
api_v1
=
Blueprint
(
'api_v1'
,
__name__
)
api
=
Api
(
api_v1
)
api
.
add_resource
(
area
.
AreaResource
,
'/area/<string:uuid>'
)
api
.
add_resource
(
area
.
AreaResourceList
,
'/area'
)
api
.
add_resource
(
app
.
AppResource
,
'/app/<string:uuid>'
)
api
.
add_resource
(
app
.
AppResourceList
,
'/app'
)
api
.
add_resource
(
package
.
PackageResource
,
'/package/<string:uuid>'
)
api
.
add_resource
(
package
.
PackageResourceList
,
'/package'
)
api
.
add_resource
(
user
.
UserResource
,
'/user/<string:uuid>'
)
api
.
add_resource
(
user
.
UserResourceList
,
'/user'
)
api
.
add_resource
(
login
.
LoginResource
,
'/login/<string:uuid>'
)
api
.
add_resource
(
login
.
LoginResourceList
,
'/login'
)
api
.
add_resource
(
device
.
DeviceResource
,
'/device/<string:uuid>'
)
api
.
add_resource
(
device
.
DeviceResourceList
,
'/device'
)
api
.
add_resource
(
annex
.
AnnexResource
,
'/annex/<string:uuid>'
)
api
.
add_resource
(
annex
.
AnnexResourceList
,
'/annex'
)
api
.
add_resource
(
monitorWatch
.
MonitorWatchResource
,
'/monitorWatch/<string:uuid>'
)
api
.
add_resource
(
monitorWatch
.
MonitorWatchResourceList
,
'/monitorWatch'
)
api
.
add_resource
(
monitorSystem
.
MonitorSystemResource
,
'/monitorSystem/<string:uuid>'
)
api
.
add_resource
(
monitorSystem
.
MonitorSystemResourceList
,
'/monitorSystem'
)
api
.
add_resource
(
monitorLvgl
.
MonitorLvglResource
,
'/monitorLvgl/<string:uuid>'
)
api
.
add_resource
(
monitorLvgl
.
MonitorLvglResourceList
,
'/monitorLvgl'
)
api
.
add_resource
(
monitorImage
.
MonitorImageResource
,
'/monitorImage/<string:uuid>'
)
api
.
add_resource
(
monitorImage
.
MonitorImageResourceList
,
'/monitorImage'
)
api
.
add_resource
(
monitorEvm
.
MonitorEvmResource
,
'/monitorEvm/<string:uuid>'
)
api
.
add_resource
(
monitorEvm
.
MonitorEvmResourceList
,
'/monitorEvm'
)
api
.
add_resource
(
menu
.
MenuList
,
'/menu'
)
api
.
add_resource
(
menu
.
Batch
,
'/menu/delete/batch'
)
api
.
add_resource
(
menu
.
Create
,
'/menu/create'
)
api
.
add_resource
(
menu
.
Treelist
,
'/menu/treeList'
)
api
.
add_resource
(
menu
.
Treenodes
,
'/menu/treeNodes'
)
api
.
add_resource
(
menu
.
Updatebyid
,
'/menu/updateById'
)
api
.
add_resource
(
menu
.
UpdateSort
,
'/menu/updateSort'
)
api
.
add_resource
(
openapi
.
AppReviewResource
,
'/api/app-review'
)
api
.
add_resource
(
openapi
.
CStringToolResource
,
'/api/convert-to-c-string'
)
api
.
add_resource
(
openapi
.
BuildAppResource
,
'/evm_store/application/build'
)
api
.
add_resource
(
openapi
.
Workbench
,
'/api/workbench'
)
api
.
add_resource
(
openapi
.
App
,
'/api/app'
)
api
.
add_resource
(
openapi
.
AppInfo
,
'/api/app-info'
)
api
.
add_resource
(
openapi
.
LauncherResource
,
'/api/app-launcher'
)
api
.
add_resource
(
openapi
.
AppListResource
,
'/api/app-list'
)
api
.
add_resource
(
openapi
.
DownloadEpk
,
'/api/download-epk'
)
api
.
add_resource
(
file
.
FileInit
,
"/file-manager/initialize"
)
api
.
add_resource
(
file
.
FileContent
,
"/file-manager/content"
)
api
.
add_resource
(
file
.
FileDisk
,
"/file-manager/select-disk"
)
api
.
add_resource
(
file
.
FileTree
,
"/file-manager/tree"
)
api
.
add_resource
(
file
.
FileUpdate
,
"/file-manager/update-file"
)
api
.
add_resource
(
file
.
FileUpload
,
"/file-manager/upload"
)
api
.
add_resource
(
file
.
FileDownload
,
"/file-manager/download"
)
api
.
add_resource
(
file
.
FilePrview
,
"/file-manager/preview"
)
api
.
add_resource
(
file
.
FileCreateDir
,
"/file-manager/create-directory"
)
api
.
add_resource
(
file
.
FileCreate
,
"/file-manager/create-file"
)
api
.
add_resource
(
file
.
FilePaste
,
"/file-manager/paste"
)
api
.
add_resource
(
file
.
FileDelete
,
"/file-manager/delete"
)
tools/build_out/views/annex.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.annex
import
deleteAnnexSchema
,
getListAnnexSchema
,
getListAnnexsSchema
,
getAnnexSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
AnnexResourceList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListAnnexSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetlistAnnex
.
emit
(
data
)
json_dumps
=
getListAnnexSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListAnnexsSchema
.
dump
(
result
.
items
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
AnnexResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getAnnexSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetAnnex
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getAnnexSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
delete
(
self
,
uuid
):
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
# data = deleteAnnexSchema.load(json_payload)
result
,
message
=
signalManager
.
actionDeleteAnnex
.
emit
(
uuid
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/app.py
deleted
100644 → 0
View file @
32df1548
import
os
import
traceback
from
pathlib
import
Path
from
datetime
import
datetime
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
werkzeug.datastructures
import
FileStorage
from
werkzeug.utils
import
secure_filename
from
application.config
import
config
from
application.signal_manager
import
signalManager
from
models.app
import
postAppSchema
,
deleteAppSchema
,
getListAppSchema
,
getListAppsSchema
,
getAppSchema
,
putAppSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
AppResourceList
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
'User-Agent'
,
location
=
'headers'
)
self
.
parser
.
add_argument
(
"app"
,
type
=
str
,
location
=
"args"
,
nullable
=
True
,
required
=
False
)
self
.
parser
.
add_argument
(
"scope"
,
type
=
str
,
location
=
"args"
,
nullable
=
True
,
required
=
False
)
self
.
parser
.
add_argument
(
"app_name"
,
type
=
str
,
location
=
"args"
,
nullable
=
True
,
required
=
False
)
self
.
parser
.
add_argument
(
"app_version"
,
type
=
str
,
location
=
"args"
,
nullable
=
True
,
required
=
False
)
self
.
parser
.
add_argument
(
"category"
,
type
=
str
,
location
=
"args"
,
nullable
=
True
,
required
=
False
)
self
.
parser
.
add_argument
(
"app_screen_size"
,
type
=
str
,
location
=
"args"
,
nullable
=
True
,
required
=
False
)
self
.
parser
.
add_argument
(
"app_arch"
,
type
=
str
,
location
=
"args"
,
nullable
=
True
,
required
=
False
)
self
.
parser
.
add_argument
(
"page"
,
type
=
int
,
location
=
"args"
,
default
=
1
)
self
.
parser
.
add_argument
(
"pageSize"
,
type
=
int
,
location
=
"args"
,
default
=
15
)
args
=
self
.
parser
.
parse_args
()
try
:
jwt
=
get_jwt_identity
()
# data = getListAppSchema.load(args)
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
result
,
message
=
signalManager
.
actionGetlistApp
.
emit
(
data
,
jwt
)
json_dumps
=
getListAppSchema
.
dump
(
result
)
if
result
:
if
isinstance
(
result
,
list
):
json_dumps
=
result
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
json_dumps
)
else
:
json_dumps
=
getListAppsSchema
.
dump
(
result
.
items
)
for
item
in
json_dumps
:
item
[
'file_dir'
]
=
os
.
path
.
dirname
(
item
[
'download_url'
])
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
json_dumps
,
total
=
result
.
total
,
pageSize
=
args
.
pageSize
)
return
response_result
(
message
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
post
(
self
):
self
.
parser
.
add_argument
(
'User-Agent'
,
location
=
'headers'
)
self
.
parser
.
add_argument
(
"meta_data"
,
type
=
str
,
location
=
"form"
,
default
=
"{}"
,
required
=
False
)
self
.
parser
.
add_argument
(
"app_name"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"app_version"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"category"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"app_screen_size"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"app_arch"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"algorithm"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"remarks"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"logo"
,
type
=
FileStorage
,
location
=
"files"
,
required
=
True
)
self
.
parser
.
add_argument
(
"fileList"
,
type
=
FileStorage
,
location
=
"files"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
jwt
=
get_jwt_identity
()
# 获取request.files参数
# json_payload = request.json
params
=
postAppSchema
.
load
(
args
)
now_str
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
)
# 获取相对路径
dirname
=
"{}-{}-{}-{}"
.
format
(
params
[
"app_name"
],
params
[
"app_version"
],
params
[
"category"
],
now_str
)
relative_path
=
Path
(
config
.
UPLOAD_ROOT_DIR
)
# 获取最终存储的绝对路径
upload_path
=
Path
(
config
.
EPK_DIR
)
.
joinpath
(
dirname
)
if
not
upload_path
.
exists
():
os
.
makedirs
(
upload_path
.
resolve
()
.
as_posix
())
files
=
[]
# 应用logo
logo
=
request
.
files
.
get
(
"logo"
)
# args.get('picture')
if
logo
:
filename
=
secure_filename
(
logo
.
filename
)
file_path
=
upload_path
.
joinpath
(
filename
)
logo
.
save
(
file_path
)
params
.
update
({
"app_icon"
:
file_path
.
relative_to
(
relative_path
)
.
as_posix
()
})
# 应用源文件
fileList
=
request
.
files
.
getlist
(
'fileList'
)
if
fileList
:
upload_path
=
upload_path
.
joinpath
(
"src"
)
if
not
upload_path
.
exists
():
os
.
mkdir
(
upload_path
.
resolve
()
.
as_posix
())
for
f
in
fileList
:
filename
=
secure_filename
(
f
.
filename
)
file_path
=
upload_path
.
joinpath
(
filename
)
f
.
save
(
file_path
.
resolve
()
.
as_posix
())
files
.
append
(
file_path
.
relative_to
(
relative_path
)
.
as_posix
())
params
.
update
({
"fileList"
:
files
,
"epk_path"
:
upload_path
,
'real_ip'
:
request
.
headers
.
get
(
'X-Forwarded-For'
,
'127.0.0.1'
)
})
result
,
message
=
signalManager
.
actionPostApp
.
emit
(
params
,
jwt
)
if
result
:
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
result
)
return
response_result
(
message
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
AppResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
jwt
=
get_jwt_identity
()
result
,
message
=
signalManager
.
actionGetApp
.
emit
(
uuid
,
jwt
)
if
result
:
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
result
)
return
response_result
(
message
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
put
(
self
,
uuid
):
try
:
jwt
=
get_jwt_identity
()
json_payload
=
request
.
json
data
=
putAppSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPutApp
.
emit
(
uuid
,
data
,
jwt
)
if
result
:
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
result
)
return
response_result
(
message
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
delete
(
self
,
uuid
):
try
:
json_payload
=
request
.
json
# data = deleteAppSchema.load(json_payload)
print
(
"========>"
,
uuid
,
json_payload
)
result
,
message
=
signalManager
.
actionDeleteApp
.
emit
(
uuid
)
if
result
:
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
result
)
return
response_result
(
message
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/area.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.area
import
postAreaSchema
,
deleteAreaSchema
,
getListAreaSchema
,
getListAreasSchema
,
getAreaSchema
,
putAreaSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
AreaResourceList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListAreaSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetlistArea
.
emit
(
data
)
json_dumps
=
getListAreaSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListAreasSchema
.
dump
(
result
.
items
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
post
(
self
):
try
:
json_payload
=
request
.
json
data
=
postAreaSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPostArea
.
emit
(
data
)
logger
.
info
(
result
)
logger
.
warn
(
message
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
AreaResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getAreaSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetArea
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getAreaSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
put
(
self
,
uuid
):
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
putAreaSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPutArea
.
emit
(
uuid
,
data
)
logger
.
info
(
result
)
logger
.
info
(
message
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
delete
(
self
,
uuid
):
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
# data = deleteAreaSchema.load(json_payload)
result
,
message
=
signalManager
.
actionDeleteArea
.
emit
(
uuid
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/device.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
traceback
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.device
import
postDeviceSchema
,
deleteDeviceSchema
,
getListDeviceSchema
,
getListDevicesSchema
,
getDeviceSchema
,
putDeviceSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
DeviceResourceList
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"name"
,
type
=
str
,
location
=
"args"
,
required
=
False
)
self
.
parser
.
add_argument
(
"imei"
,
type
=
str
,
location
=
"args"
,
required
=
False
)
self
.
parser
.
add_argument
(
"page"
,
type
=
int
,
location
=
"args"
,
default
=
1
)
self
.
parser
.
add_argument
(
"pageSize"
,
type
=
int
,
location
=
"args"
,
default
=
15
)
args
=
self
.
parser
.
parse_args
()
try
:
jwt
=
get_jwt_identity
()
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
# json_payload = request.json
# logger.warn(json_payload)
# data = getListDeviceSchema.load(json_payload)
logger
.
info
(
data
)
result
,
message
=
signalManager
.
actionGetlistDevice
.
emit
(
data
,
jwt
)
json_dumps
=
getListDeviceSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListDevicesSchema
.
dump
(
result
.
items
)
return
response_result
(
message
,
data
=
json_dumps
,
total
=
result
.
total
,
pageSize
=
args
.
pageSize
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
post
(
self
):
try
:
jwt
=
get_jwt_identity
()
json_payload
=
request
.
json
data
=
postDeviceSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPostDevice
.
emit
(
data
,
jwt
)
logger
.
info
(
result
)
logger
.
warn
(
message
)
return
response_result
(
message
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
DeviceResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getDeviceSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetDevice
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getDeviceSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
put
(
self
,
uuid
):
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
putDeviceSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPutDevice
.
emit
(
uuid
,
data
)
logger
.
info
(
result
)
logger
.
info
(
message
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
delete
(
self
,
uuid
):
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
# data = deleteDeviceSchema.load(json_payload)
result
,
message
=
signalManager
.
actionDeleteDevice
.
emit
(
uuid
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/file.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-09 12:39:40
LastEditTime: 2021-07-19 13:58:36
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\v
iews
\f
ile.py
'''
import
traceback
from
pathlib
import
Path
from
flask
import
current_app
,
jsonify
,
request
,
make_response
,
Response
from
flask_restful
import
Resource
,
fields
from
marshmallow
import
Schema
,
fields
from
werkzeug.datastructures
import
FileStorage
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
FileInit
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"args"
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
try
:
jwt
=
get_jwt_identity
()
result
,
message
=
signalManager
.
actionGetFileInit
.
emit
(
args
.
path
,
jwt
)
if
result
:
return
{
'config'
:
result
,
'result'
:
{
'message'
:
None
,
'status'
:
"success"
}
}
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FileContent
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"args"
,
required
=
False
,
default
=
None
)
self
.
parser
.
add_argument
(
"root"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
result
,
message
=
signalManager
.
actionGetFileContent
.
emit
(
args
.
disk
,
args
.
path
,
args
.
root
)
if
result
:
response
=
{
'result'
:
{
'message'
:
None
,
'status'
:
"success"
}
}
response
.
update
(
result
)
return
response
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FileTree
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"args"
,
required
=
False
)
self
.
parser
.
add_argument
(
"root"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
result
,
message
=
signalManager
.
actionGetFileTree
.
emit
(
args
.
disk
,
args
.
path
,
args
.
root
)
if
result
:
response
=
{
'result'
:
{
'message'
:
None
,
'status'
:
"success"
},
'directories'
:
None
}
response
.
update
({
'directories'
:
result
})
return
response
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FileDisk
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"args"
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
try
:
result
,
message
=
signalManager
.
actionGetFileDisk
.
emit
(
args
.
disk
)
if
result
:
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"Disk selected!"
,
'status'
:
"success"
}
}
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FileUpdate
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
post
(
self
):
# logger.info(request.form)
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"form"
,
nullable
=
False
,
required
=
True
)
self
.
parser
.
add_argument
(
"file"
,
type
=
FileStorage
,
location
=
"files"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
# logger.info(args.path)
file
=
request
.
files
.
get
(
"file"
)
# args.get('file')
result
,
message
=
signalManager
.
actionPostFileUpdate
.
emit
(
args
.
disk
,
args
.
path
,
file
)
if
result
:
return
{
'config'
:
result
,
'result'
:
{
'message'
:
"file update success"
,
'status'
:
"success"
}
}
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FileUpload
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
post
(
self
):
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"overwrite"
,
type
=
int
,
location
=
"form"
,
default
=
0
,
required
=
True
)
self
.
parser
.
add_argument
(
"files"
,
type
=
FileStorage
,
location
=
"files"
,
required
=
True
,
action
=
'append'
)
args
=
self
.
parser
.
parse_args
()
try
:
fileList
=
request
.
files
.
getlist
(
'files'
)
result
,
message
=
signalManager
.
actionPostFileUpload
.
emit
(
args
.
disk
,
args
.
path
,
args
.
overwrite
,
fileList
)
if
result
:
return
{
'config'
:
result
,
'result'
:
{
'message'
:
None
,
'status'
:
"success"
}
}
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FileDelete
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
post
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
# self.parser.add_argument("items", type=fields.Raw, location="json", required=True) # items: [{path: "code/app.php", type: "file"}]
args
=
self
.
parser
.
parse_args
()
try
:
json_payload
=
request
.
json
logger
.
info
(
json_payload
)
if
not
json_payload
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
result
,
message
=
signalManager
.
actionPostFileDelete
.
emit
(
**
json_payload
)
if
result
:
return
{
'config'
:
result
,
'result'
:
{
'message'
:
None
,
'status'
:
"success"
}
}
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FileCreate
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
post
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"name"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
result
,
message
=
signalManager
.
actionPostFileCreate
.
emit
(
args
.
disk
,
args
.
path
,
args
.
name
)
if
result
:
return
{
'config'
:
result
,
'result'
:
{
'message'
:
None
,
'status'
:
"success"
}
}
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FileCreateDir
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
post
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"name"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
result
,
message
=
signalManager
.
actionPostFileCreateDir
.
emit
(
args
.
disk
,
args
.
path
,
args
.
name
)
if
result
:
return
{
'config'
:
result
,
'result'
:
{
'message'
:
None
,
'status'
:
"success"
}
}
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FilePaste
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
post
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"clipboard"
,
type
=
dict
,
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
result
,
message
=
signalManager
.
actionPostFilePaste
.
emit
(
args
.
disk
,
args
.
items
)
if
result
:
return
{
'config'
:
result
,
'result'
:
{
'message'
:
None
,
'status'
:
"success"
}
}
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FileDownload
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
result
,
message
=
signalManager
.
actionGetFileDown
.
emit
(
args
.
disk
,
args
.
path
)
if
result
:
resp
,
mime
=
result
# return Response(resp, mimetype='text/xml')
return
Response
(
resp
,
content_type
=
'{}; charset=utf-8'
.
format
(
mime
))
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
FilePrview
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"disk"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
result
,
message
=
signalManager
.
actionGetFilePreview
.
emit
(
args
.
disk
,
args
.
path
)
if
result
:
content
,
mime
=
result
resp
=
make_response
(
content
)
resp
.
mimetype
=
mime
return
resp
return
{
'information'
:
list
(
message
),
'result'
:
{
'message'
:
"no data"
,
'status'
:
"fail"
}
}
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/login.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-22 09:26:14
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\v
iews
\
login.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
traceback
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
marshmallow.exceptions
import
ValidationError
from
application.signal_manager
import
signalManager
from
models.login
import
postLoginSchema
,
getListLoginSchema
,
getListLoginsSchema
,
getLoginSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
LoginResourceList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListLoginSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetlistLogin
.
emit
(
data
)
json_dumps
=
getListLoginSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListLoginsSchema
.
dump
(
result
.
items
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
def
post
(
self
):
try
:
json_payload
=
request
.
json
data
=
postLoginSchema
.
load
(
json_payload
)
# 更新data,插入ip信息,如果没有转发ip,那么则获取请求ip
data
.
update
({
"ip"
:
request
.
headers
.
get
(
'X-Forwarded-For'
,
request
.
remote_addr
),
"user_agent"
:
request
.
headers
.
get
(
'User-Agent'
,
""
)
})
print
(
"###############=======================>"
,
data
)
logger
.
info
(
data
)
result
,
message
=
signalManager
.
actionPostLogin
.
emit
(
data
)
print
(
">>>>>>>>>>>"
,
result
)
return
response_result
(
message
,
data
=
result
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
traceback
.
print_exc
()
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
traceback
.
print_exc
()
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
class
LoginResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getLoginSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetLogin
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getLoginSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/menu.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-28 17:16:06
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\v
iews
\
menu.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
traceback
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
MenuList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
result
=
[
{
"id"
:
"1044886626813353984"
,
"parentId"
:
"0"
,
"name"
:
"dashboard"
,
"path"
:
"/dashboard"
,
"icon"
:
"dashboard"
,
"leaf"
:
False
,
"children"
:
[
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"analysis"
,
"path"
:
"/dashboard/analysis"
,
"leaf"
:
True
,
"children"
:
[]
},
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"workplace"
,
"path"
:
"/dashboard/workplace"
,
"leaf"
:
True
,
"children"
:
[]
}
]
},
{
"id"
:
"1044886626813353984"
,
"parentId"
:
"0"
,
"name"
:
"system"
,
"path"
:
"/system"
,
"icon"
:
"setting"
,
"leaf"
:
False
,
"children"
:
[
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"setting"
,
"path"
:
"/system/setting"
,
"leaf"
:
False
,
"children"
:
[
{
"id"
:
"1044886630026190848"
,
"parentId"
:
"1044886629921333248"
,
"name"
:
"menu"
,
"path"
:
"/system/setting/menu"
,
"leaf"
:
True
,
"children"
:
[]
},
{
"id"
:
"1044886630122659840"
,
"parentId"
:
"1044886629921333248"
,
"name"
:
"module"
,
"path"
:
"/system/setting/module"
,
"leaf"
:
True
,
"children"
:
[]
},
{
"id"
:
"1044886630122659841"
,
"parentId"
:
"1044886629921333248"
,
"name"
:
"file-manager"
,
"path"
:
"/system/setting/file-manager"
,
"leaf"
:
True
,
"children"
:
[]
}
]
},
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"role"
,
"path"
:
"/system/role"
,
"leaf"
:
True
},
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"admin"
,
"path"
:
"/system/admin"
,
"leaf"
:
True
}
]
},
{
"id"
:
"1044886626813353984"
,
"icon"
:
"shop"
,
"parentId"
:
"0"
,
"name"
:
"application"
,
"path"
:
"/application"
,
"leaf"
:
False
,
"children"
:
[
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"index"
,
"path"
:
"/application/index"
,
"leaf"
:
True
,
"children"
:
[]
},
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"manager"
,
"path"
:
"/application/manager"
,
"leaf"
:
True
,
"children"
:
[]
}
]
},
{
"id"
:
"1044886626813353984"
,
"icon"
:
"usb"
,
"parentId"
:
"0"
,
"name"
:
"device"
,
"path"
:
"/device"
,
"leaf"
:
False
,
"children"
:
[
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"index"
,
"path"
:
"/device/index"
,
"leaf"
:
True
,
"children"
:
[]
}
]
},
{
"id"
:
"1044886626813353984"
,
"icon"
:
"tool"
,
"parentId"
:
"0"
,
"name"
:
"tools"
,
"path"
:
"/tools"
,
"leaf"
:
False
,
"children"
:
[
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"monitor"
,
"path"
:
"/tools/monitor"
,
"leaf"
:
True
,
"children"
:
[]
},
{
"id"
:
"1044886629921333248"
,
"parentId"
:
"1044886626813353984"
,
"name"
:
"index"
,
"path"
:
"/tools/index"
,
"leaf"
:
True
,
"children"
:
[]
}
]
}
]
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
result
)
def
post
(
self
):
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
Batch
(
Resource
):
def
__init__
(
self
):
self
.
parser
=
RequestParser
()
def
post
(
self
):
self
.
parser
.
add_argument
(
"ids"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
print
(
"========>"
,
args
)
result
,
message
=
signalManager
.
actionMenuBatch
.
emit
(
args
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
UpdateSort
(
Resource
):
def
__init__
(
self
):
self
.
parser
=
RequestParser
()
def
post
(
self
):
self
.
parser
.
add_argument
(
"id"
,
type
=
int
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"direction"
,
type
=
str
,
choices
=
[
"top"
,
"bottom"
],
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
print
(
"========>"
,
args
)
result
,
message
=
signalManager
.
actionUpdateSort
.
emit
(
args
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
Create
(
Resource
):
def
__init__
(
self
):
self
.
parser
=
RequestParser
()
def
post
(
self
):
self
.
parser
.
add_argument
(
"parentId"
,
type
=
int
,
location
=
"json"
,
default
=
None
,
required
=
False
)
self
.
parser
.
add_argument
(
"icon"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"name"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"remarks"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
print
(
"========>"
,
args
)
result
,
message
=
signalManager
.
actionMenuCreate
.
emit
(
args
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
# traceback.print_exc()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
Treelist
(
Resource
):
def
__init__
(
self
):
self
.
parser
=
RequestParser
()
def
post
(
self
):
self
.
parser
.
add_argument
(
"page"
,
type
=
int
,
location
=
"args"
,
default
=
1
,
required
=
False
)
self
.
parser
.
add_argument
(
"pageSize"
,
type
=
int
,
location
=
"args"
,
default
=
10
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
try
:
print
(
"========>"
,
args
)
result
,
message
=
signalManager
.
actionTreelist
.
emit
(
args
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
Treenodes
(
Resource
):
def
__init__
(
self
):
self
.
parser
=
RequestParser
()
def
get
(
self
):
self
.
parser
.
add_argument
(
"page"
,
type
=
int
,
location
=
"args"
,
default
=
1
,
required
=
False
)
self
.
parser
.
add_argument
(
"pageSize"
,
type
=
int
,
location
=
"args"
,
default
=
10
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
try
:
print
(
"========>"
,
args
)
result
,
message
=
signalManager
.
actionTreenodes
.
emit
(
args
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
Updatebyid
(
Resource
):
def
__init__
(
self
):
self
.
parser
=
RequestParser
()
def
post
(
self
):
self
.
parser
.
add_argument
(
"icon"
,
type
=
str
,
location
=
"json"
,
default
=
None
,
required
=
False
)
self
.
parser
.
add_argument
(
"name"
,
type
=
str
,
location
=
"json"
,
default
=
None
,
required
=
False
)
self
.
parser
.
add_argument
(
"parentId"
,
type
=
int
,
location
=
"json"
,
default
=
None
,
required
=
False
)
self
.
parser
.
add_argument
(
"path"
,
type
=
str
,
location
=
"json"
,
default
=
None
,
required
=
False
)
self
.
parser
.
add_argument
(
"remark"
,
type
=
str
,
location
=
"json"
,
default
=
None
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
try
:
print
(
"========>"
,
args
)
result
,
message
=
signalManager
.
actionUpdatebyid
.
emit
(
args
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/monitor.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-06-29 19:33:41
LastEditTime: 2021-07-26 18:43:32
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\b
ackend
\v
iew
\
monitor.py
'''
import
json
import
signal
import
time
import
pprint
import
traceback
import
jwt
from
typing
import
(
Any
,)
from
threading
import
Timer
from
datetime
import
datetime
,
timedelta
import
tornado.ioloop
import
tornado.web
from
tornado
import
httputil
from
tornado.web
import
RequestHandler
,
StaticFileHandler
from
tornado.websocket
import
WebSocketHandler
,
WebSocketClosedError
from
application.app
import
config
from
webcreator.utils
import
ObjectDict
from
webcreator.log
import
logger
from
models.device
import
DeviceModel
from
models.user
import
UserModel
from
controllers.monitor
import
insert_data
,
get_monitor_list
,
get_watch_list
def
datetime2secs
(
mydate
):
return
time
.
mktime
(
mydate
.
timetuple
())
def
secs2datetime
(
ts
):
return
datetime
.
fromtimestamp
(
ts
)
class
GracefulExit
(
SystemExit
):
code
=
1
def
raise_graceful_exit
(
*
args
):
tornado
.
ioloop
.
IOLoop
.
current
()
.
stop
()
print
(
"Gracefully shutdown"
,
args
)
raise
GracefulExit
()
class
BaseHandler
(
RequestHandler
):
"""解决JS跨域请求问题"""
def
set_default_headers
(
self
):
self
.
set_header
(
'Access-Control-Allow-Origin'
,
'*'
)
self
.
set_header
(
'Access-Control-Allow-Methods'
,
'POST, GET'
)
self
.
set_header
(
'Access-Control-Max-Age'
,
1000
)
self
.
set_header
(
'Access-Control-Allow-Headers'
,
'*'
)
self
.
set_header
(
'Content-type'
,
'application/json'
)
class
WebsocketResponse
(
ObjectDict
):
def
__init__
(
self
,
type
=
"Response"
,
api_code
=-
1
,
message
=
'fail'
,
data
=
None
,
traceback
=
""
):
super
(
WebsocketResponse
,
self
)
.
__init__
()
self
.
type
=
type
self
.
code
=
api_code
self
.
message
=
message
self
.
data
=
data
self
.
traceback
=
traceback
if
isinstance
(
self
.
data
,
list
):
self
.
count
=
len
(
self
.
data
)
def
pushmessage
(
func
):
def
send
(
*
agrs
,
**
kwargs
):
self
=
agrs
[
0
]
ret
=
func
(
*
agrs
,
**
kwargs
)
if
ret
:
msg
,
binary
=
ret
try
:
if
isinstance
(
msg
,
WebsocketResponse
)
or
isinstance
(
msg
,
dict
):
self
.
write_message
(
json
.
dumps
(
msg
),
binary
)
elif
isinstance
(
msg
,
str
):
self
.
write_message
(
msg
,
binary
)
else
:
self
.
write_message
(
repr
(
msg
),
binary
)
except
WebSocketClosedError
as
e
:
logger
.
error
(
e
)
traceback
.
print_exc
()
self
.
on_close
()
return
send
class
BaseWebsocket
(
WebSocketHandler
):
_clients
=
[]
handlers
=
{}
def
open
(
self
):
# 新加入一个连接后,设置一个接收消息时间戳
# 同时查询改用可以查看哪些设备
# 当有消息到来时,遍历用户列表,将设备IMEI与每个用户的IMEI列表比对
# 如果用户列表有这个IMEI,则需要向该用户广播消息
# 列表 [里面存放字典]
# 字典 { 'uuid': '', 'context': self, 'devices': ['imei', 'imei'], 'ts': '接收消息时间戳' }
className
=
self
.
__class__
.
__name__
logger
.
warning
(
"websocket of
%
s is opened"
%
className
)
if
className
not
in
self
.
handlers
:
self
.
handlers
[
className
]
=
set
()
self
.
handlers
[
className
]
.
add
(
self
)
logger
.
info
(
self
.
handlers
[
className
])
# pprint.pprint(self.handlers)
@
pushmessage
def
send
(
self
,
message
,
binary
=
False
):
return
message
,
binary
def
on_close
(
self
):
className
=
self
.
__class__
.
__name__
logger
.
warning
(
"websocket of
%
s is closed"
%
className
)
if
className
in
self
.
handlers
and
self
in
self
.
handlers
[
className
]:
# 更加健壮的处理是,这里需要增加一个self是否存在的判断
self
.
handlers
[
className
]
.
remove
(
self
)
for
i
,
c
in
enumerate
(
self
.
_clients
):
if
id
(
self
)
==
id
(
c
.
get
(
"context"
)):
del
self
.
_clients
[
i
]
def
check_origin
(
self
,
origin
):
logger
.
info
(
origin
)
return
True
@
classmethod
def
broadcastMessage
(
cls
,
message
):
pprint
.
pprint
(
message
)
print
(
"=======>"
,
cls
.
_clients
)
if
not
message
.
get
(
"imei"
):
return
False
for
item
in
cls
.
_clients
:
if
message
.
get
(
"imei"
)
in
item
.
get
(
"devices"
,
[]):
item
.
get
(
"context"
)
.
write_message
(
json
.
dumps
(
message
))
# className = cls.__name__
# message = json.dumps(message)
# if className in cls.handlers:
# for handler in cls.handlers[className]:
# # 判断用户能否查看该设备
# handler.send(message, binary)
class
NotifyHandler
(
BaseWebsocket
):
"""
建立与web前端的通信连接,发送状态信息报文
"""
_timer
=
None
def
__init__
(
self
,
application
:
tornado
.
web
.
Application
,
request
:
httputil
.
HTTPServerRequest
,
**
kwargs
:
Any
)
->
None
:
super
()
.
__init__
(
application
,
request
,
**
kwargs
)
self
.
on_heartbeat
()
def
open
(
self
):
super
(
NotifyHandler
,
self
)
.
open
()
def
on_message
(
self
,
message
):
try
:
className
=
self
.
__class__
.
__name__
message
=
json
.
loads
(
message
)
logger
.
info
(
message
)
# 判断消息类型
if
message
.
get
(
"type"
)
and
message
.
get
(
"token"
):
# 获取token值,检验正确与否,获取uuid
payload
=
jwt
.
decode
(
message
.
get
(
"token"
),
config
.
JWT_SECRET_KEY
,
verify
=
True
,
algorithms
=
[
'HS256'
])
logger
.
info
(
payload
)
# 认证包,认证不通过,则剔除该连接
if
message
.
get
(
"type"
)
==
"auth"
:
if
not
message
.
get
(
"token"
):
self
.
write_message
(
json
.
dumps
({
"code"
:
400
,
"data"
:
None
,
"msg"
:
"token can not be null"
}))
return
user
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
payload
.
get
(
"sub"
)
.
get
(
"uuid"
))
.
one_or_none
()
if
not
user
:
self
.
write_message
(
json
.
dumps
({
"code"
:
400
,
"data"
:
None
,
"msg"
:
"user not exists"
}))
# self.close()
return
logger
.
info
(
user
.
to_dict
())
# 查询该用户可查看设备
devices
=
DeviceModel
.
query
.
filter
(
DeviceModel
.
create_by
==
user
.
id
)
.
all
()
if
len
(
devices
):
self
.
_clients
.
append
({
'uuid'
:
payload
.
get
(
"sub"
)
.
get
(
"uuid"
),
'context'
:
self
,
'devices'
:
list
(
map
(
lambda
d
:
d
.
imei
,
devices
)),
'ts'
:
int
(
time
.
time
())
})
self
.
write_message
(
json
.
dumps
({
'code'
:
200
,
'data'
:
None
,
'msg'
:
'auth passed'
}))
else
:
# 没有设备,是否断开连接
self
.
write_message
(
json
.
dumps
({
'code'
:
400
,
'data'
:
None
,
'msg'
:
'no devices'
}))
# self.close()
elif
message
.
get
(
"type"
)
==
"heartbeat"
:
# 心跳包
# 收到心跳包消息,更新接收数据时间
logger
.
info
(
"////////////////////////"
)
for
c
in
self
.
_clients
:
if
c
.
get
(
"uuid"
)
==
payload
.
get
(
"sub"
)
.
get
(
"uuid"
):
c
[
"ts"
]
=
int
(
time
.
time
())
self
.
write_message
(
json
.
dumps
({
'code'
:
200
,
'data'
:
None
,
'msg'
:
'update session timestamp success'
}))
else
:
self
.
write_message
(
json
.
dumps
({
'code'
:
200
,
'data'
:
None
,
'msg'
:
'unkonw message packet, disconnect by server'
}))
self
.
handlers
[
className
]
.
remove
(
self
)
except
jwt
.
exceptions
.
ExpiredSignatureError
as
e
:
logger
.
error
(
e
)
self
.
write_message
(
json
.
dumps
({
'code'
:
401
,
'data'
:
None
,
'msg'
:
'auth fail'
}))
except
Exception
as
e
:
# 认证失败会导致触发异常,这里不能remove(self),否则会导致on_close方法报错
self
.
write_message
(
json
.
dumps
({
'code'
:
400
,
'data'
:
e
.
args
,
'msg'
:
"server error"
}))
logger
.
error
(
e
)
traceback
.
print_exc
()
logger
.
info
(
message
)
def
on_heartbeat
(
self
):
# 心跳定时器,固定间隔扫描连接列表,当连接超时,主动剔除该连接
for
i
in
range
(
len
(
self
.
_clients
)
-
1
,
-
1
,
-
1
):
if
int
(
time
.
time
())
-
self
.
_clients
[
i
]
.
get
(
"ts"
)
>
30
:
logger
.
info
(
"################################################"
)
# self._clients.pop(i)
del
self
.
_clients
[
i
]
className
=
self
.
__class__
.
__name__
if
self
.
handlers
.
get
(
className
,
None
)
and
self
in
self
.
handlers
[
className
]:
self
.
handlers
[
className
]
.
remove
(
self
)
self
.
_timer
=
Timer
(
1
,
self
.
on_heartbeat
)
self
.
_timer
.
start
()
class
MainHandler
(
BaseHandler
):
def
get
(
self
,
*
args
,
**
kwargs
):
print
(
"#############"
,
args
)
print
(
"/////////////"
,
kwargs
)
print
(
self
.
request
.
path
)
# 请求路径
print
(
self
.
request
.
method
)
# 请求方法
print
(
self
.
request
.
host
)
# IP地址
print
(
self
.
request
.
protocol
)
# self.get_query_argument('a', value)
# self.get_body_argument()
# self.request.files
self
.
write
(
json
.
dumps
({
"msg"
:
"Hello, world"
}))
def
post
(
self
):
if
not
self
.
request
.
body
:
return
None
try
:
data
=
tornado
.
escape
.
json_decode
(
self
.
request
.
body
)
logger
.
info
(
data
)
self
.
write
(
json
.
dumps
({
'code'
:
100
,
'data'
:
data
,
'msg'
:
'success'
}))
message
=
{
'imei'
:
'12345678900005'
,
'type'
:
'report'
,
'system'
:
{
'free_size'
:
0
},
'lvgl'
:
{
'total_size'
:
5242880
,
'free_cnt'
:
31
,
'free_size'
:
1279664
,
'free_biggest_size'
:
1205448
,
'used_cnt'
:
832
,
'used_pct'
:
76
,
'frag_pct'
:
6
},
'evm'
:
{
'total_size'
:
2097152
,
'free_size'
:
0
,
'gc_usage'
:
50
},
'image'
:
[{
'uri'
:
'evue_launcher'
,
'length'
:
1043
,
'png_total_count'
:
0
,
'png_uncompressed_size'
:
0
,
'png_file_size'
:
0
},
{
'uri'
:
'kdgs_1_storyList'
,
'length'
:
9608
,
'png_total_count'
:
193
,
'png_uncompressed_size'
:
370884
,
'png_file_size'
:
209807
}]}
insert_data
(
message
)
# 这里不能使用广播,得点对点发送,有此设备的账号才能看到调试信息
NotifyHandler
.
broadcastMessage
(
message
)
except
Exception
as
e
:
logger
.
info
(
self
.
request
.
body
)
logger
.
error
(
e
)
traceback
.
print_exc
()
class
WatchHandler
(
BaseHandler
):
def
get
(
self
,
*
args
,
**
kwargs
):
# 获取手表列表
print
(
"#############"
,
args
)
print
(
"/////////////"
,
kwargs
)
print
(
self
.
request
.
path
)
# 请求路径
print
(
self
.
request
.
method
)
# 请求方法
print
(
self
.
request
.
host
)
# IP地址
print
(
self
.
request
.
protocol
)
try
:
result
=
get_watch_list
()
if
result
:
self
.
write
(
json
.
dumps
({
'code'
:
200
,
'data'
:
result
,
'msg'
:
'success'
}))
else
:
self
.
write
(
json
.
dumps
({
'code'
:
204
,
'data'
:
None
,
'msg'
:
'no data'
}))
except
Exception
as
e
:
logger
.
error
(
e
)
self
.
write
(
json
.
dumps
({
'code'
:
500
,
'data'
:
None
,
'msg'
:
'server error'
}))
def
post
(
self
):
data
=
tornado
.
escape
.
json_decode
(
self
.
request
.
body
)
self
.
write
(
json
.
dumps
({
'code'
:
100
,
'data'
:
data
,
'msg'
:
'success'
}))
class
DeviceMessageHandler
(
BaseHandler
):
def
get
(
self
):
if
not
self
.
get_argument
(
'watch'
,
None
):
self
.
write
(
json
.
dumps
({
'code'
:
400
,
'msg'
:
'params error, watch can not be null'
}))
return
try
:
watch
=
self
.
get_query_argument
(
'watch'
)
category
=
self
.
get_query_argument
(
'category'
,
'all'
)
start
=
self
.
get_query_argument
(
'start'
,
None
)
end
=
self
.
get_query_argument
(
'end'
,
None
)
if
start
and
start
.
isdigit
():
start
=
int
(
start
)
start
=
time
.
localtime
(
start
)
start
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
start
)
else
:
start
=
(
datetime
.
now
()
-
timedelta
(
minutes
=
10
))
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
end
and
end
.
isdigit
():
end
=
time
.
localtime
(
int
(
end
))
end
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
end
)
result
=
get_monitor_list
(
int
(
watch
),
category
,
start
,
end
)
if
result
:
self
.
write
(
json
.
dumps
({
'code'
:
200
,
'data'
:
result
,
'msg'
:
'success'
,
'type'
:
'array'
if
isinstance
(
result
,
list
)
else
'object'
}))
else
:
self
.
write
(
json
.
dumps
({
'code'
:
204
,
'data'
:
None
,
'msg'
:
'no data'
}))
except
Exception
as
e
:
logger
.
error
(
e
)
traceback
.
print_exc
()
self
.
write
(
json
.
dumps
({
'code'
:
500
,
'data'
:
None
,
'msg'
:
'server error'
}))
def
post
(
self
):
if
not
self
.
request
.
body
:
logger
.
info
(
self
.
request
.
body
)
return
None
try
:
# data = tornado.escape.json_decode(self.request.body)
data
=
str
(
self
.
request
.
body
,
encoding
=
"ISO-8859-1"
)
data
=
json
.
loads
(
data
)
logger
.
info
(
data
)
data
[
'system'
]
.
update
({
'host'
:
self
.
request
.
remote_ip
,
'path'
:
self
.
request
.
path
,
'protocol'
:
self
.
request
.
protocol
})
result
=
insert_data
(
data
)
data
[
'type'
]
=
'report'
data
[
'system'
]
.
update
({
'timestamp'
:
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
})
NotifyHandler
.
broadcastMessage
(
data
)
self
.
write
(
json
.
dumps
({
'code'
:
100
if
result
else
400
,
'message'
:
'success'
if
result
else
"fail"
}))
except
Exception
as
e
:
logger
.
info
(
self
.
request
.
body
)
logger
.
error
(
e
)
traceback
.
print_exc
()
def
make_app
():
return
tornado
.
web
.
Application
([
(
r"/"
,
MainHandler
),
(
r"/api/v1/evm_store/monitor"
,
DeviceMessageHandler
),
(
r"/api/v1/evm_store/watch"
,
WatchHandler
),
(
r"/ws/v1/notify"
,
NotifyHandler
),
(
r"/dist/(.*)"
,
StaticFileHandler
,
{
"path"
:
"dist"
}),
])
if
__name__
==
"__main__"
:
app
=
make_app
()
app
.
listen
(
5001
)
signal
.
signal
(
signal
.
SIGINT
,
raise_graceful_exit
)
signal
.
signal
(
signal
.
SIGTERM
,
raise_graceful_exit
)
tornado
.
ioloop
.
IOLoop
.
current
()
.
start
()
tools/build_out/views/monitorEvm.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.monitorEvm
import
getListMonitorEvmSchema
,
getListMonitorEvmsSchema
,
getMonitorEvmSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
MonitorEvmResourceList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListMonitorEvmSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetlistMonitorEvm
.
emit
(
data
)
json_dumps
=
getListMonitorEvmSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListMonitorEvmsSchema
.
dump
(
result
.
items
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
MonitorEvmResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getMonitorEvmSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetMonitorEvm
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getMonitorEvmSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/monitorImage.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.monitorImage
import
getListMonitorImageSchema
,
getListMonitorImagesSchema
,
getMonitorImageSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
MonitorImageResourceList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListMonitorImageSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetlistMonitorImage
.
emit
(
data
)
json_dumps
=
getListMonitorImageSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListMonitorImagesSchema
.
dump
(
result
.
items
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
MonitorImageResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getMonitorImageSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetMonitorImage
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getMonitorImageSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/monitorLvgl.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.monitorLvgl
import
getListMonitorLvglSchema
,
getListMonitorLvglsSchema
,
getMonitorLvglSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
MonitorLvglResourceList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListMonitorLvglSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetlistMonitorLvgl
.
emit
(
data
)
json_dumps
=
getListMonitorLvglSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListMonitorLvglsSchema
.
dump
(
result
.
items
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
MonitorLvglResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getMonitorLvglSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetMonitorLvgl
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getMonitorLvglSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/monitorSystem.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.monitorSystem
import
getListMonitorSystemSchema
,
getListMonitorSystemsSchema
,
getMonitorSystemSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
MonitorSystemResourceList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListMonitorSystemSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetlistMonitorSystem
.
emit
(
data
)
json_dumps
=
getListMonitorSystemSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListMonitorSystemsSchema
.
dump
(
result
.
items
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
MonitorSystemResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getMonitorSystemSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetMonitorSystem
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getMonitorSystemSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/monitorWatch.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.monitorWatch
import
getListMonitorWatchSchema
,
getListMonitorWatchsSchema
,
getMonitorWatchSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
MonitorWatchResourceList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListMonitorWatchSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetlistMonitorWatch
.
emit
(
data
)
json_dumps
=
getListMonitorWatchSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListMonitorWatchsSchema
.
dump
(
result
.
items
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
MonitorWatchResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getMonitorWatchSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetMonitorWatch
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getMonitorWatchSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/openapi.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-19 14:29:33
LastEditTime: 2021-07-23 00:37:20
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\v
iews
\a
pi.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
os
import
time
import
json
import
random
import
traceback
import
uuid
from
pathlib
import
Path
from
datetime
import
datetime
,
timedelta
from
flask
import
current_app
,
jsonify
,
request
,
Response
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
werkzeug.utils
import
secure_filename
from
werkzeug.datastructures
import
FileStorage
from
marshmallow.exceptions
import
ValidationError
from
application.app
import
db
from
application.config
import
config
from
application.signal_manager
import
signalManager
from
models
import
MyModel
,
MyModel2
from
models.app
import
AppModel
from
models.annex
import
AnnexModel
from
models.login
import
LoginModel
from
models.device
import
DeviceModel
from
models.package
import
PackageModel
from
models.monitorEvm
import
MonitorEvmModel
from
models.monitorLvgl
import
MonitorLvglModel
from
models.monitorImage
import
MonitorImageModel
from
models.monitorWatch
import
MonitorWatchModel
from
models.monitorSystem
import
MonitorSystemModel
from
webcreator.log
import
logger
from
webcreator.utils.ccode
import
convert_string
from
webcreator.response
import
ResponseCode
,
response_result
class
AppReviewResource
(
Resource
):
def
__init__
(
self
):
self
.
parser
=
RequestParser
()
# 设置启动器接口
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
):
self
.
parser
.
add_argument
(
"app"
,
type
=
str
,
location
=
"args"
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
try
:
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
jwt
=
get_jwt_identity
()
result
,
message
=
signalManager
.
actionSetLauncher
.
emit
(
data
,
jwt
)
if
result
:
return
response_result
(
message
,
data
=
result
)
return
response_result
(
message
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
@
jwt_required
(
locations
=
[
"headers"
])
def
post
(
self
):
self
.
parser
.
add_argument
(
"review"
,
type
=
int
,
location
=
"json"
,
default
=
0
,
required
=
True
)
self
.
parser
.
add_argument
(
"app"
,
type
=
str
,
location
=
"json"
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
try
:
jwt
=
get_jwt_identity
()
result
,
message
=
signalManager
.
actionPostAppReview
.
emit
(
args
.
app
,
args
.
review
,
jwt
)
if
result
:
return
response_result
(
message
,
data
=
result
)
return
response_result
(
message
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
class
BuildAppResource
(
Resource
):
def
__init__
(
self
):
self
.
parser
=
RequestParser
()
def
get
(
self
):
try
:
return
ResponseCode
.
HTTP_SUCCESS
result
=
db
.
session
.
query
(
AnnexModel
)
.
all
()
for
item
in
result
:
item
.
uuid
=
uuid
.
uuid1
()
.
hex
logger
.
info
(
item
.
uuid
)
db
.
session
.
flush
()
db
.
session
.
commit
()
result
=
db
.
session
.
query
(
AppModel
)
.
all
()
for
item
in
result
:
item
.
uuid
=
uuid
.
uuid1
()
.
hex
logger
.
info
(
item
.
uuid
)
db
.
session
.
flush
()
db
.
session
.
commit
()
result
=
db
.
session
.
query
(
LoginModel
)
.
all
()
for
item
in
result
:
item
.
uuid
=
uuid
.
uuid1
()
.
hex
logger
.
info
(
item
.
uuid
)
db
.
session
.
flush
()
db
.
session
.
commit
()
result
=
db
.
session
.
query
(
DeviceModel
)
.
all
()
for
item
in
result
:
item
.
uuid
=
uuid
.
uuid1
()
.
hex
logger
.
info
(
item
.
uuid
)
db
.
session
.
flush
()
db
.
session
.
commit
()
result
=
db
.
session
.
query
(
PackageModel
)
.
all
()
for
item
in
result
:
item
.
uuid
=
uuid
.
uuid1
()
.
hex
if
item
.
source
==
None
:
item
.
source
=
0
logger
.
info
(
item
.
uuid
)
db
.
session
.
flush
()
db
.
session
.
commit
()
result
=
db
.
session
.
query
(
MonitorEvmModel
)
.
all
()
for
item
in
result
:
item
.
uuid
=
uuid
.
uuid1
()
.
hex
logger
.
info
(
item
.
uuid
)
db
.
session
.
flush
()
db
.
session
.
commit
()
result
=
db
.
session
.
query
(
MonitorLvglModel
)
.
all
()
for
item
in
result
:
item
.
uuid
=
uuid
.
uuid1
()
.
hex
logger
.
info
(
item
.
uuid
)
db
.
session
.
flush
()
db
.
session
.
commit
()
result
=
db
.
session
.
query
(
MonitorImageModel
)
.
all
()
for
item
in
result
:
item
.
uuid
=
uuid
.
uuid1
()
.
hex
logger
.
info
(
item
.
uuid
)
db
.
session
.
flush
()
db
.
session
.
commit
()
result
=
db
.
session
.
query
(
MonitorWatchModel
)
.
all
()
for
item
in
result
:
item
.
uuid
=
uuid
.
uuid1
()
.
hex
logger
.
info
(
item
.
uuid
)
db
.
session
.
flush
()
db
.
session
.
commit
()
# result_proxy = conn.execute("select id, host, path, protocol, create_at from monitor_request")
# result = result_proxy.fetchall()
result
=
db
.
session
.
query
(
MyModel2
)
.
filter
()
.
all
()
for
item
in
result
:
res
=
MonitorSystemModel
.
query
.
filter
(
MonitorSystemModel
.
id
==
item
.
id
)
.
first
()
if
not
res
:
continue
res
.
is_delete
=
0
res
.
uuid
=
uuid
.
uuid1
()
.
hex
res
.
host
=
item
.
host
res
.
path
=
item
.
path
res
.
protocol
=
item
.
protocol
new_dt
=
item
.
create_at
[:
19
]
res
.
create_at
=
datetime
.
strptime
(
new_dt
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
res
.
update_at
=
datetime
.
strptime
(
new_dt
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
db
.
session
.
flush
()
db
.
session
.
commit
()
result
=
db
.
session
.
query
(
MyModel
)
.
filter
()
.
all
()
for
item
in
result
:
# print(item[3])
# 查找app,更新download_url
# app = AppModel.query.filter(AppModel.create_at >= datetime.strptime(item[6], "%Y-%m-%d %H:%M:%S.%f"), AppModel.create_at <= datetime.strptime(item[6], "%Y-%m-%d %H:%M:%S.%f") - timedelta(secondsd=2)).all()
print
(
"====>"
,
item
.
create_at
,
(
datetime
.
strptime
(
item
.
create_at
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S.
%
f"
)
+
timedelta
(
seconds
=
2
))
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
))
app
=
AppModel
.
query
.
filter
(
AppModel
.
create_at
>=
item
.
create_at
,
AppModel
.
create_at
<=
(
datetime
.
strptime
(
item
.
create_at
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S.
%
f"
)
+
timedelta
(
seconds
=
2
))
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
))
.
first
()
if
not
app
:
continue
print
(
app
)
# 再判断是否存在于package中,不存在则插入
res
=
db
.
session
.
query
(
PackageModel
)
.
filter
(
PackageModel
.
file_path
==
item
.
app_path
)
.
limit
(
1
)
.
one_or_none
()
if
res
:
app
.
download_url
=
item
.
app_path
res
.
app_version
=
item
.
app_version
db
.
session
.
flush
()
else
:
res
=
PackageModel
(
app
=
app
.
id
,
app_version
=
item
.
app_version
,
file_path
=
item
.
app_path
,
package_info
=
item
.
app_info
,
create_at
=
datetime
.
strptime
(
item
.
create_at
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S.
%
f"
),
create_by
=
item
.
create_by
,
update_at
=
datetime
.
strptime
(
item
.
create_at
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S.
%
f"
),
update_by
=
item
.
create_by
)
db
.
session
.
add
(
res
)
db
.
session
.
flush
()
logger
.
info
(
res
)
print
(
item
)
db
.
session
.
commit
()
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
)
except
:
traceback
.
print_exc
()
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
def
post
(
self
):
self
.
parser
.
add_argument
(
"access_key"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"app_name"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"app_version"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"category"
,
type
=
str
,
location
=
"form"
,
required
=
True
)
self
.
parser
.
add_argument
(
"app_desc"
,
type
=
str
,
location
=
"form"
,
required
=
False
)
self
.
parser
.
add_argument
(
"binfiles"
,
type
=
FileStorage
,
location
=
"files"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
# logger.info(request.host)
# logger.info(request.host_url)
# logger.info(request.path)
# logger.info(request.full_path)
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
if
'binfiles'
in
request
.
files
:
files
=
[]
dt
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
)
upload_path
=
Path
(
config
.
EPK_DIR
)
.
joinpath
(
args
.
access_key
)
.
joinpath
(
dt
)
if
not
upload_path
.
exists
():
os
.
makedirs
(
upload_path
.
resolve
()
.
as_posix
())
for
f
in
request
.
files
.
getlist
(
'binfiles'
):
file_path
=
upload_path
.
joinpath
(
secure_filename
(
f
.
filename
))
f
.
save
(
file_path
.
resolve
()
.
as_posix
())
files
.
append
(
file_path
.
resolve
()
.
as_posix
())
data
.
update
({
'host_url'
:
request
.
host_url
})
result
,
message
=
signalManager
.
actionApplicationBuild
.
emit
(
data
,
files
)
if
result
:
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
result
)
else
:
return
response_result
(
message
)
else
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
msg
=
"files can not be null"
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
CStringToolResource
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
def
get
(
self
):
result
=
{
"results"
:
[
{
"gender"
:
"female"
,
"name"
:
{
"title"
:
"Miss"
,
"first"
:
"Candice"
,
"last"
:
"Gonzales"
},
"location"
:
{
"street"
:
{
"number"
:
3007
,
"name"
:
"Northaven Rd"
},
"city"
:
"Warragul"
,
"state"
:
"Queensland"
,
"country"
:
"Australia"
,
"postcode"
:
6657
,
"coordinates"
:
{
"latitude"
:
"-87.1892"
,
"longitude"
:
"91.2147"
},
"timezone"
:
{
"offset"
:
"-1:00"
,
"description"
:
"Azores, Cape Verde Islands"
}
},
"email"
:
"candice.gonzales@example.com"
,
"login"
:
{
"uuid"
:
"253648f6-1ba1-4196-aaf8-0b7a0a7f819b"
,
"username"
:
"lazybear738"
,
"password"
:
"wallet"
,
"salt"
:
"TOehKzxN"
,
"md5"
:
"01f4d04fbbdc7da7145c733e6d6fef77"
,
"sha1"
:
"3c63e0f753b75c4bc141f49c4e8072d945beddc1"
,
"sha256"
:
"102535a2f99c2dee933c1261bd3f70e042c628818a938e97a95391eabe0df252"
},
"dob"
:
{
"date"
:
"1970-03-01T16:04:10.320Z"
,
"age"
:
51
},
"registered"
:
{
"date"
:
"2013-07-27T18:45:18.202Z"
,
"age"
:
8
},
"phone"
:
"06-4951-5747"
,
"cell"
:
"0479-024-688"
,
"id"
:
{
"name"
:
"TFN"
,
"value"
:
"046353523"
},
"picture"
:
{
"large"
:
"https://randomuser.me/api/portraits/women/3.jpg"
,
"medium"
:
"https://randomuser.me/api/portraits/med/women/3.jpg"
,
"thumbnail"
:
"https://randomuser.me/api/portraits/thumb/women/3.jpg"
},
"nat"
:
"AU"
}
],
"info"
:
{
"seed"
:
"60ef4c21e9a77500"
,
"results"
:
1
,
"page"
:
1
,
"version"
:
"1.3"
}
}
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
result
)
@
jwt_required
(
locations
=
[
"headers"
])
def
post
(
self
):
self
.
parser
.
add_argument
(
"string"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
jwt
=
get_jwt_identity
()
logger
.
info
(
jwt
)
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
convert_string
(
args
.
string
))
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
class
ObfuscatedCode
(
Resource
):
def
__init__
(
self
)
->
None
:
super
()
.
__init__
()
self
.
parser
=
RequestParser
()
def
post
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
self
.
parser
.
add_argument
(
"string"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
print
(
args
)
# fname = "./a.c"
# target = os.sep.join(["out", fname])
# if os.path.exists(fname):
# os.remove(fname)
# if os.path.exists(target):
# os.remove(target)
# with open(fname, "w+") as f:
# f.write(data['string'])
# result = os.system("./opqcp {i} ./out".format(i=fname))
# print(result)
# with open(target) as f:
# result = f.read()
# return result
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
# 获取启动器接口
class
LauncherResource
(
Resource
):
def
__init__
(
self
)
->
None
:
super
()
.
__init__
()
self
.
parser
=
RequestParser
()
def
post
(
self
):
# self.parser.add_argument("page", type=int, location="args", default=1)
self
.
parser
.
add_argument
(
"imei"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
result
,
message
=
signalManager
.
actionGetLauncher
.
emit
(
data
)
if
result
:
ret
=
result
.
read_bytes
()
# with open(result.resolve().as_posix(), "rb") as f:
# ret = f.read()
return
Response
(
ret
,
mimetype
=
"text/html"
,
content_type
=
"text/html; charset=utf-8"
)
return
response_result
(
message
,
data
=
result
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
# 获取App列表接口
class
AppListResource
(
Resource
):
def
__init__
(
self
)
->
None
:
super
()
.
__init__
()
self
.
parser
=
RequestParser
()
def
get
(
self
):
try
:
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
def
post
(
self
):
self
.
parser
.
add_argument
(
"imei"
,
type
=
str
,
location
=
"json"
,
required
=
False
)
self
.
parser
.
add_argument
(
"review"
,
type
=
int
,
location
=
"json"
,
required
=
False
)
self
.
parser
.
add_argument
(
"category"
,
type
=
str
,
location
=
"json"
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
try
:
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
dataList
=
None
result
,
message
=
signalManager
.
actionGetAppList
.
emit
(
data
)
if
result
:
dataList
=
[]
# 遍历列表,添加一些额外信息
for
item
in
result
:
t
=
item
.
to_dict
()
t
.
update
({
'download'
:
random
.
randint
(
1
,
1000
),
'like'
:
random
.
randint
(
0
,
100
),
'meta_data'
:
json
.
loads
(
item
.
meta_data
)})
dataList
.
append
(
t
)
# result = getListAppsSchema.dumps(result)
category
=
[
{
"uuid"
:
1
,
"img"
:
"music.png"
,
"title"
:
"音乐"
},
{
"uuid"
:
2
,
"img"
:
"movie.png"
,
"title"
:
"视频"
},
{
"uuid"
:
3
,
"img"
:
"camera.png"
,
"title"
:
"相机"
},
{
"uuid"
:
4
,
"img"
:
"voice.png"
,
"title"
:
"语音"
},
{
"uuid"
:
5
,
"img"
:
"tool.png"
,
"title"
:
"工具"
}
]
return
response_result
(
message
,
data
=
dataList
,
category
=
category
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
traceback
.
print_exc
()
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
# 获取应用接口
class
App
(
Resource
):
def
__init__
(
self
)
->
None
:
super
()
.
__init__
()
self
.
parser
=
RequestParser
()
def
get
(
self
):
# self.parser.add_argument("page", type=int, location="args", default=1)
self
.
parser
.
add_argument
(
"uuid"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
result
,
message
=
signalManager
.
actionGetApplication
.
emit
(
data
)
if
result
:
result
=
result
.
to_dict
()
result
.
update
({
'download'
:
random
.
randint
(
1
,
1000
),
'like'
:
random
.
randint
(
0
,
100
),
'timestamp'
:
int
(
time
.
time
()),
'meta_data'
:
json
.
loads
(
result
[
"meta_data"
])})
return
response_result
(
message
,
data
=
result
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
traceback
.
print_exc
()
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
# 获取应用信息接口
class
AppInfo
(
Resource
):
def
__init__
(
self
)
->
None
:
super
()
.
__init__
()
self
.
parser
=
RequestParser
()
# 检查app是否为最新版本
def
get
(
self
):
self
.
parser
.
add_argument
(
"uuid"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
self
.
parser
.
add_argument
(
"imei"
,
type
=
str
,
location
=
"args"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
logger
.
info
(
args
)
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
result
,
message
=
signalManager
.
actionCheckVersion
.
emit
(
data
)
if
result
:
return
{
'data'
:
{
'status'
:
1
,
'time'
:
int
(
time
.
time
())},
'version'
:
None
,
'downloadUrl'
:
None
}
return
{
'data'
:
{
'status'
:
0
,
'time'
:
int
(
time
.
time
())}}
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
# 下载EPK文件接口
class
DownloadEpk
(
Resource
):
def
__init__
(
self
)
->
None
:
super
()
.
__init__
()
self
.
parser
=
RequestParser
()
def
post
(
self
):
self
.
parser
.
add_argument
(
"byId"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"uuid"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
self
.
parser
.
add_argument
(
"imei"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
print
(
args
)
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
data
.
update
({
'real_ip'
:
request
.
headers
.
get
(
'X-Forwarded-For'
,
'127.0.0.1'
)})
result
,
message
=
signalManager
.
actionGetEpk
.
emit
(
data
)
# 读取epk文件,按照格式返回相应结构体数据
logger
.
info
(
data
)
if
result
:
ret
=
result
.
read_bytes
()
# with open(result.as_posix(), "rb") as f:
# ret = f.read()
# logger.info(type(ret))
return
Response
(
ret
,
content_type
=
"text/html; charset=utf-8"
)
return
response_result
(
message
,
data
=
result
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
class
DownloadApp
(
Resource
):
def
__init__
(
self
)
->
None
:
super
()
.
__init__
()
self
.
parser
=
RequestParser
()
def
get
(
self
):
# self.parser.add_argument("page", type=int, location="args", default=1)
self
.
parser
.
add_argument
(
"imei"
,
type
=
str
,
location
=
"json"
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
try
:
print
(
args
)
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
class
Workbench
(
Resource
):
def
__init__
(
self
)
->
None
:
super
()
.
__init__
()
self
.
parser
=
RequestParser
()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
self
.
parser
.
add_argument
(
"string"
,
type
=
str
,
location
=
"json"
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
try
:
jwt
=
get_jwt_identity
()
result
,
message
=
signalManager
.
actionWorkbench
.
emit
(
jwt
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
\ No newline at end of file
tools/build_out/views/package.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-27 16:41:32
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\v
iews
\
package.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
os
import
json
import
traceback
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.package
import
getListPackageSchema
,
getListPackagesSchema
,
getPackageSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
PackageResourceList
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
.
add_argument
(
"app"
,
type
=
str
,
location
=
"args"
,
nullable
=
True
,
required
=
False
)
self
.
parser
.
add_argument
(
"page"
,
type
=
int
,
location
=
"args"
,
default
=
1
)
self
.
parser
.
add_argument
(
"pageSize"
,
type
=
int
,
location
=
"args"
,
default
=
15
)
args
=
self
.
parser
.
parse_args
()
try
:
jwt
=
get_jwt_identity
()
data
=
dict
()
for
key
,
value
in
args
.
items
():
if
value
!=
None
:
data
[
key
]
=
value
result
,
message
=
signalManager
.
actionGetlistPackage
.
emit
(
data
,
jwt
)
if
result
:
# json_dumps = getListPackagesSchema.dump(result.items)
replace_key
=
'******'
response
=
[]
for
p
,
a
in
result
.
items
:
t
=
p
.
to_dict
()
if
p
.
geo_location
!=
""
and
isinstance
(
p
.
geo_location
,
str
):
t
[
'geo_location'
]
=
json
.
loads
(
p
.
geo_location
)
if
p
.
remarks
!=
""
and
isinstance
(
p
.
remarks
,
str
):
t
[
'remarks'
]
=
json
.
loads
(
p
.
remarks
)
t
[
'remarks'
][
'appDir'
]
=
replace_key
+
t
[
'remarks'
][
'appDir'
][
len
(
replace_key
):]
t
[
'app_name'
]
=
a
.
app_name
t
[
'file_dir'
]
=
os
.
path
.
dirname
(
p
.
file_path
)
t
[
'application'
]
=
a
.
to_dict
()
t
[
'package_info'
]
=
json
.
loads
(
p
.
package_info
)
t
[
'package_info'
][
'epkfile'
]
=
replace_key
+
t
[
'package_info'
][
'epkfile'
][
len
(
replace_key
):]
response
.
append
(
t
)
return
response_result
(
message
,
data
=
response
,
total
=
result
.
total
,
pageSize
=
args
.
pageSize
)
return
response_result
(
message
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
PackageResource
(
Resource
):
def
__init__
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
self
.
parser
=
RequestParser
()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
jwt
=
get_jwt_identity
()
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
result
,
message
=
signalManager
.
actionGetPackage
.
emit
(
uuid
,
jwt
)
if
result
:
json_dumps
=
getPackageSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
traceback
.
print_exc
()
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/views/user.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
application.signal_manager
import
signalManager
from
models.user
import
postUserSchema
,
deleteUserSchema
,
getListUserSchema
,
getListUsersSchema
,
getUserSchema
,
putUserSchema
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
class
UserResourceList
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
def
get
(
self
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetlistUser
.
emit
(
data
)
json_dumps
=
getListUserSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListUsersSchema
.
dump
(
result
.
items
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
def
post
(
self
):
try
:
json_payload
=
request
.
json
data
=
postUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPostUser
.
emit
(
data
)
logger
.
info
(
result
)
logger
.
warn
(
message
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
class
UserResource
(
Resource
):
def
__init__
(
self
):
pass
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser = RequestParser()
@
jwt_required
(
locations
=
[
"headers"
])
def
get
(
self
,
uuid
):
# 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
# self.parser.add_argument("page", type=int, location="args", default=1)
# self.parser.add_argument("pageSize", type=int, location="args", default=15)
# args = self.parser.parse_args()
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetUser
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getUserSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
put
(
self
,
uuid
):
try
:
json_payload
=
request
.
json
data
=
putUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPutUser
.
emit
(
uuid
,
data
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
delete
(
self
,
uuid
):
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
# data = deleteUserSchema.load(json_payload)
result
,
message
=
signalManager
.
actionDeleteUser
.
emit
(
uuid
)
return
response_result
(
message
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
)
tools/build_out/webcreator/__init__.py
deleted
100644 → 0
View file @
32df1548
# -*- coding: utf_8 -*-
\ No newline at end of file
tools/build_out/webcreator/event.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-06-15 17:40:14
LastEditTime: 2021-06-30 17:22:44
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\r
esources
\
webcreator
\
event.py
'''
# -*- coding: utf_8 -*-
class
PySignal
(
object
):
"""
Simple event class used to provide hooks for different types of events in Locust.
Here's how to use the EventHook class::
my_event = PySignal()
def on_my_event(a, b, **kw):
print "Event was fired with arguments:
%
s,
%
s"
%
(a, b)
my_event += on_my_event
my_event.fire(a="foo", b="bar")
my_event.emit(a="foo", b="bar")
"""
def
__init__
(
self
):
self
.
_handlers
=
[]
def
__iadd__
(
self
,
handler
):
return
self
.
connect
(
handler
)
def
__isub__
(
self
,
handler
):
return
self
.
disconnect
(
handler
)
def
connect
(
self
,
handler
):
self
.
_handlers
.
append
(
handler
)
return
self
def
disconnect
(
self
,
handler
):
self
.
_handlers
.
remove
(
handler
)
return
self
def
fire
(
self
,
*
args
,
**
kwargs
):
return
self
.
emit
(
*
args
,
**
kwargs
)
def
emit
(
self
,
*
args
,
**
kwargs
):
rets
=
{}
for
handler
in
self
.
_handlers
:
ret
=
handler
(
*
args
,
**
kwargs
)
rets
[
handler
.
__name__
]
=
ret
if
len
(
rets
)
==
1
:
return
list
(
rets
.
values
())[
0
]
# list()用来兼容python3
return
rets
if
__name__
==
'__main__'
:
my_event
=
PySignal
()
def
on_my_event
(
a
,
b
,
**
kw
):
print
(
a
,
b
)
print
(
kw
)
my_event
.
connect
(
on_my_event
)
my_event
.
fire
(
1
,
2
,
c
=
"foo"
,
d
=
"bar"
)
my_event
.
emit
(
3
,
4
,
e
=
"foo"
,
f
=
"bar"
)
tools/build_out/webcreator/log.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-04-22 18:04:15
LastEditTime: 2021-07-14 18:38:28
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\r
esources
\
webcreator
\
log.py
'''
# -*- coding: utf_8 -*-
import
os
import
logging
from
logging.handlers
import
RotatingFileHandler
logPath
=
os
.
getcwd
()
+
os
.
path
.
sep
+
"logs"
if
not
os
.
path
.
exists
(
logPath
):
os
.
makedirs
(
logPath
)
fh
=
RotatingFileHandler
(
"logs/running.log"
,
maxBytes
=
10
*
1024
*
1024
,
backupCount
=
100
)
fh
.
setLevel
(
logging
.
DEBUG
)
ch
=
logging
.
StreamHandler
()
ch
.
setLevel
(
logging
.
DEBUG
)
formatter
=
logging
.
Formatter
(
'[
%(asctime)
s][
%(levelname)7
s][in
%(pathname)
s ->
%(funcName)
s line:
%(lineno)
s]
%(message)
s'
)
fh
.
setFormatter
(
formatter
)
ch
.
setFormatter
(
formatter
)
logger
=
logging
.
root
logger
.
setLevel
(
logging
.
DEBUG
)
logger
.
addHandler
(
fh
)
logger
.
addHandler
(
ch
)
\ No newline at end of file
tools/build_out/webcreator/response.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-19 17:40:36
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
webcreator
\r
esponse.py
'''
# -*- coding: utf_8 -*-
'''
请求方法:
OPTION : 用于获取资源支持的所有 HTTP 方法
HEAD : 用于只获取请求某个资源返回的头信息
GET : 用于从服务器获取资源信息
完成请求后返回状态码 200 OK
POST : 用于创建新资源
创建完成后返回状态码 201 Created
PUT : 用于完整的替换资源或者创建指定身份的资源
如果是创建了资源,则返回 201 Created
如果是替换了资源,则返回 200 OK
DELETE : 用于删除某个资源
完成请求后返回状态码 204 No Content
PATCH : 用于局部更新资源
完成请求后返回状态码 200 OK
================================================================================
状态码:
请求成功
200:请求执行成功并返回相应数据
201:创建成功并返回相应资源数据
202:接受请求,但无法立即完成创建行为
204:请求执行成功,不返回相应资源数据
重定向
301:被请求的资源已永久移动到新位置
302:请求的资源现在临时从不通的URI响应请求
303:对应当前请求的响应可以在另一个 URI 上被找到,客户端应该使用 GET 方法进行请求
307:对应当前请求的响应可以在另一个 URI 上被找到,客户端应该保持原有的请求方法进行请求
条件请求
304:资源自从上次请求后没有再次发生变化,主要使用场景在于实现数据缓存
409:请求操作和资源的当前状态存在冲突。主要使用场景在于实现并发控制
412:服务器在验证请求的头字段中给出先决条件时,没能满足其中的一个或多个。主要使用场景在于实现并发控制
客户端错误
400 : 请求体包含语法错误
401 : 需要验证用户身份
403 : 服务器拒绝执行
404 : 找不到目标资源
405 : 不允许执行目标方法,响应中应该带有 Allow 头,内容为对该资源有效的 HTTP 方法
406 : 服务器不支持客户端请求的内容格式
410 : 被请求的资源已被删除
413 : POST 或者 PUT 请求的消息实体过大
415 : 服务器不支持请求中提交的数据的格式
422 : 请求格式正确,但是由于含有语义错误,无法响应
428 : 要求先决条件,如果想要请求能成功必须满足一些预设的条件要求先决条件
服务端错误
500 : 服务器遇到了一个未曾预料的状况,导致了它无法完成对请求的处理
502 : 作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应
501 : 服务器不支持当前请求所需要的某个功能
503 : 由于临时的服务器维护或者过载,服务器当前无法处理请求
'''
class
ResponseCode
(
object
):
# 通用状态码
HTTP_SUCCESS
=
(
200
,
"success"
)
HTTP_NO_DATA
=
(
204
,
"no data"
)
HTTP_NO_CHANGE
=
(
304
,
'nothing change'
)
HTTP_AUTH_FAIL
=
(
401
,
'authentication failed'
)
HTTP_INVAILD_REQUEST
=
(
403
,
'invaild request'
)
HTTP_NOT_FOUND
=
(
404
,
"not found"
)
HTTP_SERVER_ERROR
=
(
500
,
"server error"
)
# 用户模块
USER_NOT_EXISTS
=
(
1010001
,
'user not exists'
)
USER_EXISTS
=
(
1010002
,
'user already exists'
)
USER_PASSWORD_ERROR
=
(
1010003
,
'password error'
)
# 应用模块
APPLICATION_NOT_EXISTS
=
(
3010001
,
'application not exists'
)
APPLICATION_EXISTS
=
(
3010002
,
'application already exists'
)
# 文件管理模块
FILE_NOT_EXISTS
=
(
3010001
,
'file not exists'
)
FILE_EXISTS
=
(
3010002
,
'file already exists'
)
DIRECTORY_NOT_EXISTS
=
(
3010003
,
'directory not exists'
)
DIRECTORY_EXISTS
=
(
3010004
,
'directory already exists'
)
# 设备管理模块
DEVICE_NOT_EXISTS
=
(
3010001
,
'device not exists'
)
DEVICE_EXISTS
=
(
3010002
,
'device already exists'
)
IMEI_NOT_EXISTS
=
(
3010001
,
'device imei not exists'
)
IMEI_EXISTS
=
(
3010002
,
'device imei already exists'
)
def
response_result
(
response
,
msg
=
None
,
data
=
None
,
**
kwargs
):
c
,
m
=
response
if
msg
==
None
:
msg
=
m
result
=
{
'code'
:
c
,
'msg'
:
msg
,
'data'
:
data
}
result
.
update
(
kwargs
)
return
result
tools/build_out/webcreator/utils/__init__.py
deleted
100644 → 0
View file @
32df1548
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
typing
import
(
Any
,
Optional
,
Dict
,
Mapping
,
List
,
Tuple
,
Match
,
Callable
,
Type
,
Sequence
,
)
import
shutil
import
time
import
re
import
os
import
json
import
functools
import
hashlib
import
random
import
string
import
datetime
import
threading
import
decimal
import
urllib
from
urllib
import
parse
,
request
from
urllib.parse
import
urlparse
,
urljoin
,
urlencode
class
DecimalEncoder
(
json
.
JSONEncoder
):
def
default
(
self
,
o
):
if
isinstance
(
o
,
decimal
.
Decimal
):
return
float
(
o
)
super
(
DecimalEncoder
,
self
)
.
default
(
o
)
def
ThreadMaker
(
f
):
def
runner
(
*
args
,
**
argv
):
t
=
threading
.
Thread
(
target
=
f
,
args
=
args
,
kwargs
=
argv
)
t
.
start
()
return
t
return
runner
def
copytree
(
src
,
dst
,
symlinks
=
False
,
ignore
=
None
):
names
=
os
.
listdir
(
src
)
if
ignore
is
not
None
:
ignored_names
=
ignore
else
:
ignored_names
=
set
()
if
not
os
.
path
.
exists
(
dst
):
os
.
makedirs
(
dst
)
errors
=
[]
for
name
in
names
:
if
name
in
ignored_names
:
continue
if
re
.
match
(
r'.*?.pyc$'
,
name
):
continue
srcname
=
os
.
path
.
join
(
src
,
name
)
dstname
=
os
.
path
.
join
(
dst
,
name
)
try
:
if
symlinks
and
os
.
path
.
islink
(
srcname
):
linkto
=
os
.
readlink
(
srcname
)
os
.
symlink
(
linkto
,
dstname
)
elif
os
.
path
.
isdir
(
srcname
):
copytree
(
srcname
,
dstname
,
symlinks
,
ignore
)
else
:
shutil
.
copy2
(
srcname
,
dstname
)
# XXX What about devices, sockets etc.?
except
(
IOError
,
os
.
error
)
as
why
:
errors
.
append
((
srcname
,
dstname
,
str
(
why
)))
# catch the Error from the recursive copytree so that we can
# continue with other files
except
Exception
as
e
:
errors
.
extend
(
e
.
args
[
0
])
try
:
shutil
.
copystat
(
src
,
dst
)
except
WindowsError
:
# can't copy file access times on Windows
pass
except
OSError
as
why
:
errors
.
extend
((
src
,
dst
,
str
(
why
)))
if
errors
:
raise
Exception
(
errors
)
def
timing
(
f
):
@
functools
.
wraps
(
f
)
def
inner
(
*
args
,
**
kwargs
):
startTime
=
time
.
time
()
f
(
*
args
,
**
kwargs
)
print
(
"[function]:
%
s [finished in]:
%
fs"
%
(
f
.
__name__
,
time
.
time
()
-
startTime
))
return
inner
def
timeToSeconds
(
t
,
sep
=
":"
):
if
t
==
""
:
t
=
"0:0:0"
ts
=
[
int
(
i
)
for
i
in
t
.
split
(
sep
)]
return
ts
[
0
]
*
60
*
60
+
ts
[
1
]
*
60
+
ts
[
2
]
def
secondsToTime
(
seconds
,
sep
=
":"
):
h
=
seconds
/
3600
m
=
seconds
%
3600
/
60
s
=
(
seconds
-
h
*
3600
-
m
*
60
)
%
60
return
sep
.
join
([
str
(
i
)
for
i
in
[
h
,
m
,
s
]])
def
md5_encryption
(
s
):
md5
=
hashlib
.
md5
(
"EhuqUkwV"
.
encode
(
"utf-8"
))
md5
.
update
(
s
.
encode
(
'utf-8'
))
return
md5
.
hexdigest
()
def
filter_dict
(
source
:
dict
,
rules_list
:
list
):
# 如果source中的词典数量过多,请使用itertools模块的ifilter。 它会返回一个迭代器,而不是立即用整个列表填充系统的内存
result
=
dict
()
# res = [d for d in source.keys() if d in rules_list]
# res = list(filter(lambda d: d in rules_list, source.keys()))
for
k
in
source
.
keys
():
if
k
in
rules_list
:
result
.
update
(
k
,
source
[
k
])
return
result
def
get_location_by_ip
(
ip
):
params
=
{
'ak'
:
'aZEAgYG8wKuLd6DS9BmCloGtfnGGkRMn'
,
'coor'
:
'bd09ll'
}
parameters
=
urllib
.
parse
.
urlencode
(
params
)
headers
=
{
'User-Agent'
:
'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'
}
if
ip
!=
'127.0.0.1'
:
params
.
update
({
'ip'
:
ip
})
parameters
=
urllib
.
parse
.
urlencode
(
params
)
url
=
'http://api.map.baidu.com/location/ip'
req
=
request
.
Request
(
url
=
'
%
s
%
s
%
s'
%
(
url
,
'?'
,
parameters
),
headers
=
headers
)
ret
=
request
.
urlopen
(
req
)
.
read
()
jsonData
=
json
.
loads
(
ret
)
return
jsonData
def
sql_filter
(
sql
):
return
re
.
sub
(
r"[\"\\/*\'=\-#;<>+
%
$()!@]"
,
""
,
sql
)
def
random_string
(
length
=
32
):
return
''
.
join
(
random
.
sample
(
string
.
ascii_letters
+
string
.
digits
,
length
))
def
get_days_before_datetime
(
dt
,
dayAgo
):
if
not
isinstance
(
dt
,
datetime
.
datetime
):
dt
=
datetime
.
datetime
.
strptime
(
dt
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
# 先获得时间数组格式的日期
dayAgo
=
(
dt
-
datetime
.
timedelta
(
days
=
dayAgo
))
# 转换为其他字符串格式
return
dayAgo
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
class
Klass
:
def
__init__
(
self
):
pass
klass
=
Klass
()
def
dict2obj
(
dictionary
):
klass
.
__dict__
.
update
(
dictionary
)
return
klass
class
ObjectDict
(
Dict
[
str
,
Any
]):
"""Makes a dictionary behave like an object, with attribute-style access."""
def
__getattr__
(
self
,
name
:
str
)
->
Any
:
try
:
return
self
[
name
]
except
KeyError
:
raise
AttributeError
(
name
)
def
__setattr__
(
self
,
name
:
str
,
value
:
Any
)
->
None
:
self
[
name
]
=
value
if
__name__
==
"__main__"
:
d
=
{
'a'
:
1
,
'b'
:
2
}
print
(
dict2obj
(
d
))
print
(
os
.
path
.
abspath
(
__file__
))
print
(
random_string
(
7
))
tools/build_out/webcreator/utils/ccode.py
deleted
100644 → 0
View file @
32df1548
# -*- coding: utf-8 -*-
import
sys
header
=
\
u'''
/****************************************************************************
**
** Copyright (C) 2021 @scriptiot
**
** EVM是一款通用化设计的虚拟机引擎,拥有语法解析前端接口、编译器、虚拟机和虚拟机扩展接口框架。
** 支持js、python、qml、lua等多种脚本语言,纯C开发,零依赖,支持主流 ROM > 50KB, RAM > 2KB的MCU;
** 自带垃圾回收(GC)先进的内存管理,采用最复杂的压缩算法,无内存碎片(大部分解释器都存在内存碎片)
** Version : 3.0
** Email : scriptiot@aliyun.com
** Website : https://github.com/scriptiot
** Licence: MIT Licence
****************************************************************************/
'''
def
cstr_encode
(
text
,
splitLines
=
True
,
escapePercent
=
False
):
output
=
"
\"
"
count
=
len
(
text
)
for
i
in
range
(
count
):
if
text
[
i
]
==
'
\f
'
:
output
+=
"
\\
f"
elif
text
[
i
]
==
'
\n
'
:
if
splitLines
:
output
+=
"
\\
n
\"\n\"
"
else
:
output
+=
"
\\
n"
;
elif
text
[
i
]
==
'
\r
'
:
output
+=
"
\\
r"
elif
text
[
i
]
==
'
\t
'
:
output
+=
"
\\
t"
elif
text
[
i
]
==
'
\"
'
:
output
+=
"
\\\"
"
elif
text
[
i
]
==
'
\\
'
:
output
+=
"
\\\\
"
elif
text
[
i
]
==
'
%
'
:
if
escapePercent
:
output
+=
"
%%
"
else
:
output
+=
"
%
"
else
:
output
+=
text
[
i
]
output
+=
"
\"
"
return
output
def
convert
(
fpath
):
with
open
(
fpath
,
"r"
)
as
f
:
content
=
f
.
read
()
ret
=
cstr_encode
(
content
)
ccode
=
"
%
s
\n
const char * appjs_content=
\\\n
%
s;"
%
(
header
,
ret
)
with
open
(
"appjs.c"
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
ccode
)
return
ccode
def
convert_string
(
string
):
return
"
%
s
\n
const char * appjs_content=
\\\n
%
s;"
%
(
header
,
cstr_encode
(
string
))
if
__name__
==
'__main__'
:
ret
=
convert
(
sys
.
argv
[
1
])
print
(
ret
)
tools/build_out/webcreator/utils/epk.py
deleted
100644 → 0
View file @
32df1548
#-*- coding: UTF-8 -*-
#!/usr/bin/python
import
os
import
sys
import
fs
import
struct
import
json
from
collections
import
OrderedDict
import
zlib
import
pprint
import
hashlib
from
ctypes
import
*
import
platform
lib_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
if
platform
.
system
()
==
'Windows'
:
pDll
=
CDLL
(
os
.
sep
.
join
([
lib_path
,
"lib"
,
"eheatshrink.dll"
]))
elif
platform
.
system
()
==
'Linux'
:
pDll
=
CDLL
(
os
.
sep
.
join
([
lib_path
,
"lib"
,
"libeheatshrink.so"
]))
pDll
.
ecompress_size
.
restype
=
c_uint32
pDll
.
ecompress_size
.
argtypes
=
[
c_void_p
,
c_uint32
]
pDll
.
ecompress
.
restype
=
POINTER
(
c_uint8
)
pDll
.
ecompress
.
argtypes
=
[
c_void_p
,
c_uint32
]
def
heatshrink_compress
(
buf
:
bytes
,
level
:
int
):
count
=
len
(
buf
)
size
=
pDll
.
ecompress_size
(
buf
,
count
)
pDll
.
ecompress
.
restype
=
POINTER
(
c_uint8
)
pDll
.
ecompress
.
argtypes
=
[
c_void_p
,
c_uint32
]
ret
=
pDll
.
ecompress
(
buf
,
count
)
arr
=
bytearray
(
size
)
i
=
0
while
i
<
size
:
arr
[
i
]
=
ret
[
i
]
i
=
i
+
1
return
arr
def
str_to_hex
(
s
):
return
' '
.
join
([
hex
(
ord
(
c
))
.
replace
(
'0x'
,
''
)
for
c
in
s
])
def
hex_to_str
(
s
):
return
''
.
join
([
chr
(
i
)
for
i
in
[
int
(
b
,
16
)
for
b
in
s
.
split
(
' '
)]])
def
str_to_bin
(
s
):
return
' '
.
join
([
bin
(
ord
(
c
))
.
replace
(
'0b'
,
''
)
for
c
in
s
])
def
bin_to_str
(
s
):
return
''
.
join
([
chr
(
i
)
for
i
in
[
int
(
b
,
2
)
for
b
in
s
.
split
(
' '
)]])
def
eprint
(
*
args
,
**
kwargs
):
# print(*args, **kwargs)
pass
class
EpkApp
(
object
):
def
__init__
(
self
,
appName
,
appDir
,
algorithm
=
'zlib'
,
appVersion
=
"1.0"
,
output
=
"epks"
):
super
(
EpkApp
,
self
)
.
__init__
()
self
.
_appName
=
appName
self
.
_appDir
=
os
.
path
.
abspath
(
appDir
)
self
.
algorithm
=
algorithm
eprint
(
sys
.
argv
)
eprint
(
appName
)
eprint
(
appDir
)
eprint
(
self
.
_appDir
)
self
.
_appVersion
=
appVersion
self
.
_appCRCCode
=
None
self
.
_files
=
[]
self
.
_infoPath
=
os
.
sep
.
join
([
self
.
_appDir
,
"
%
s.json"
%
self
.
_appName
])
self
.
_epksDir
=
output
if
not
os
.
path
.
exists
(
self
.
_epksDir
):
fs
.
open_fs
(
os
.
getcwd
())
.
makedirs
(
output
)
self
.
_epkName
=
os
.
sep
.
join
([
self
.
_epksDir
,
"
%
s.epk"
%
self
.
_appName
])
def
compress
(
self
):
if
self
.
algorithm
==
'h'
:
return
heatshrink_compress
return
zlib
.
compress
def
epkInfo
(
self
):
epkInfo
=
OrderedDict
({
"appName"
:
self
.
_appName
,
"appVersion"
:
self
.
_appVersion
,
"files"
:
self
.
fileinfos
(
self
.
_appDir
),
})
infocontent
=
json
.
dumps
(
epkInfo
)
with
open
(
self
.
_infoPath
,
"w"
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
infocontent
)
return
epkInfo
def
fileinfos
(
self
,
path
):
path
=
os
.
path
.
abspath
(
path
)
home_fs
=
fs
.
open_fs
(
path
)
files
=
[]
for
jspath
in
home_fs
.
glob
(
'*'
,
namespaces
=
[
'details'
]):
fpath
=
"C:/
%
s"
%
jspath
.
info
.
name
fname
=
jspath
.
info
.
name
fsize
=
jspath
.
info
.
size
fbasename
,
fext
=
os
.
path
.
splitext
(
jspath
.
info
.
name
)
if
fext
in
[
""
,
".exe"
,
".dll"
,
".nv"
,
".conf"
]:
continue
finfo
=
{
"path"
:
fpath
,
"name"
:
fname
,
"size"
:
fsize
,
"basename"
:
fbasename
,
"ext"
:
fext
}
if
self
.
_infoPath
==
os
.
sep
.
join
([
path
,
fname
]):
eprint
(
finfo
)
files
.
insert
(
0
,
finfo
)
else
:
files
.
append
(
finfo
)
if
fext
==
".evue"
:
self
.
fileMD5
(
finfo
)
return
files
def
header
(
self
,
epk_start
=
0xAA
,
md5_offset
=
0
,
file_count
=
0
):
if
self
.
algorithm
==
'zlib'
:
bytes_header
=
struct
.
pack
(
"<BBLH"
,
epk_start
,
1
,
md5_offset
,
file_count
)
else
:
bytes_header
=
struct
.
pack
(
"<BBLH"
,
epk_start
,
2
,
md5_offset
,
file_count
)
return
bytes_header
def
fileMD5
(
self
,
info
):
md5path
=
os
.
sep
.
join
([
self
.
_appDir
,
"
%
s.md5"
%
info
[
"basename"
]])
fpath
=
os
.
sep
.
join
([
self
.
_appDir
,
info
[
"name"
]])
with
open
(
fpath
,
"rb"
)
as
f
:
filecontent
=
f
.
read
()
newmd5
=
self
.
md5
(
filecontent
)
with
open
(
md5path
,
"wb"
)
as
f
:
f
.
write
(
newmd5
)
return
newmd5
def
sign
(
self
,
content
):
ret
=
b
""
for
i
in
range
(
int
(
len
(
content
)
/
2
)):
ret
+=
struct
.
pack
(
"<B"
,
int
(
"0x
%
s"
%
(
content
[
i
*
2
:
i
*
2
+
2
]),
16
))
ret
=
ret
+
b
'EVM is NB ++!'
return
ret
def
md5
(
self
,
filecontent
):
newmd5
=
''
content
=
filecontent
for
i
in
range
(
3
):
md5
=
hashlib
.
md5
()
#获取一个md5加密算法对象
md5
.
update
(
content
)
#指定需要加密的字符串
newmd5
=
md5
.
hexdigest
()
#获取加密后的16进制字符串
eprint
(
"md5 == "
,
newmd5
)
content
=
self
.
sign
(
newmd5
)
ret
=
b
""
for
i
in
range
(
int
(
len
(
newmd5
)
/
2
)):
ret
+=
struct
.
pack
(
"<B"
,
int
(
"0x
%
s"
%
(
newmd5
[
i
*
2
:
i
*
2
+
2
]),
16
))
return
ret
def
packFile
(
self
,
info
,
level
=
9
):
fname
=
info
[
"name"
]
fpath
=
os
.
sep
.
join
([
self
.
_appDir
,
fname
])
fext
=
info
[
"ext"
]
fileBytes
=
b
""
if
fext
==
"md5"
:
fileBytes
+=
struct
.
pack
(
"<B"
,
1
)
else
:
fileBytes
+=
struct
.
pack
(
"<B"
,
2
)
_name
=
fname
+
"
\0
"
fileBytes
+=
struct
.
pack
(
"<B"
,
len
(
_name
))
fileBytes
+=
struct
.
pack
(
"<
%
ds"
%
len
(
_name
),
fname
.
encode
(
"utf-8"
))
with
open
(
fpath
,
"rb"
)
as
fc
:
fileContentBytes
=
fc
.
read
()
eprint
(
info
[
"name"
])
eprint
(
len
(
fileContentBytes
))
fileBytes
+=
struct
.
pack
(
"<L"
,
len
(
fileContentBytes
))
if
fext
==
"md5"
:
fileCompressBytes
=
fileContentBytes
else
:
fileCompressBytes
=
self
.
compress
()(
fileContentBytes
,
level
)
eprint
(
"==="
,
fileCompressBytes
[
0
])
eprint
(
fileCompressBytes
)
fileBytes
+=
struct
.
pack
(
"<L"
,
len
(
fileCompressBytes
))
eprint
(
fileBytes
)
fileBytes
+=
fileCompressBytes
return
fileBytes
def
pack
(
self
,
level
=
9
):
for
i
in
range
(
10
):
infos
=
self
.
epkInfo
()
# infos = self.epkInfo()
# infos = self.epkInfo()
epkFileBytes
=
b
""
ret
=
None
epkFileContentBytes
=
b
""
file_count
=
len
(
infos
[
"files"
])
with
open
(
self
.
_epkName
,
"wb"
)
as
f
:
for
info
in
infos
[
"files"
]:
epkFileContentBytes
+=
self
.
packFile
(
info
)
epkFileContentLength
=
len
(
epkFileContentBytes
)
epkFileBytes
+=
self
.
header
(
md5_offset
=
8
+
epkFileContentLength
,
file_count
=
file_count
)
epkFileBytes
+=
epkFileContentBytes
epkmd5Bytes
=
self
.
md5
(
epkFileBytes
)
epkFileBytes
+=
struct
.
pack
(
"<H"
,
len
(
epkmd5Bytes
))
epkFileBytes
+=
epkmd5Bytes
crcBytes
=
zlib
.
crc32
(
epkFileBytes
)
epkFileBytes
+=
struct
.
pack
(
"<L"
,
crcBytes
)
f
.
write
(
epkFileBytes
)
ret
=
{
"epkfile"
:
self
.
_epkName
,
"epk_filecontent_size"
:
epkFileContentLength
,
"md5_offset"
:
10
+
epkFileContentLength
,
"file_count"
:
file_count
,
"md5_length"
:
len
(
epkmd5Bytes
),
"md5"
:
epkmd5Bytes
,
"raw_crc"
:
hex
(
crcBytes
),
"compress_level"
:
level
,
"buff_length"
:
len
(
epkFileBytes
)
}
pprint
.
pprint
(
ret
)
return
ret
def
main
(
path
,
appName
,
algorithm
):
epk
=
EpkApp
(
appName
,
path
,
algorithm
)
epk
.
pack
()
if
__name__
==
'__main__'
:
main
(
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
])
tools/build_out/webcreator/utils/epk_2.0.py
deleted
100644 → 0
View file @
32df1548
#-*- coding: UTF-8 -*-
#!/usr/bin/python
import
os
import
sys
import
fs
import
struct
import
json
from
collections
import
OrderedDict
import
zlib
import
pprint
import
hashlib
from
ctypes
import
*
import
platform
current_abspath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
platform
.
system
()
==
'Windows'
:
pDll
=
CDLL
(
os
.
sep
.
join
([
current_abspath
,
"lib"
,
"eheatshrink.dll"
]))
elif
platform
.
system
()
==
'Linux'
:
pDll
=
CDLL
(
os
.
sep
.
join
([
current_abspath
,
"lib"
,
"libeheatshrink.so"
]))
pDll
.
ecompress_size
.
restype
=
c_uint32
pDll
.
ecompress_size
.
argtypes
=
[
c_void_p
,
c_uint32
]
pDll
.
ecompress
.
restype
=
POINTER
(
c_uint8
)
pDll
.
ecompress
.
argtypes
=
[
c_void_p
,
c_uint32
]
def
heatshrink_compress
(
buf
:
bytes
,
level
:
int
):
count
=
len
(
buf
)
size
=
pDll
.
ecompress_size
(
buf
,
count
)
pDll
.
ecompress
.
restype
=
POINTER
(
c_uint8
)
pDll
.
ecompress
.
argtypes
=
[
c_void_p
,
c_uint32
]
ret
=
pDll
.
ecompress
(
buf
,
count
)
arr
=
bytearray
(
size
)
i
=
0
while
i
<
size
:
arr
[
i
]
=
ret
[
i
]
i
=
i
+
1
return
arr
def
str_to_hex
(
s
):
return
' '
.
join
([
hex
(
ord
(
c
))
.
replace
(
'0x'
,
''
)
for
c
in
s
])
def
hex_to_str
(
s
):
return
''
.
join
([
chr
(
i
)
for
i
in
[
int
(
b
,
16
)
for
b
in
s
.
split
(
' '
)]])
def
str_to_bin
(
s
):
return
' '
.
join
([
bin
(
ord
(
c
))
.
replace
(
'0b'
,
''
)
for
c
in
s
])
def
bin_to_str
(
s
):
return
''
.
join
([
chr
(
i
)
for
i
in
[
int
(
b
,
2
)
for
b
in
s
.
split
(
' '
)]])
class
EpkApp
(
object
):
def
__init__
(
self
,
appName
,
appDir
,
algorithm
=
'zlib'
,
appVersion
=
"1.0"
,
output
=
"epks"
):
super
(
EpkApp
,
self
)
.
__init__
()
self
.
_appName
=
appName
self
.
_appDir
=
os
.
path
.
abspath
(
appDir
)
self
.
algorithm
=
algorithm
self
.
_appVersion
=
appVersion
self
.
_appCRCCode
=
None
self
.
_files
=
[]
self
.
_infoPath
=
os
.
sep
.
join
([
self
.
_appDir
,
"
%
s.json"
%
self
.
_appName
])
self
.
_epksDir
=
output
if
not
os
.
path
.
exists
(
self
.
_epksDir
):
fs
.
open_fs
(
os
.
getcwd
())
.
makedirs
(
output
)
self
.
_epkName
=
os
.
sep
.
join
([
self
.
_epksDir
,
"
%
s.epk"
%
self
.
_appName
])
def
compress
(
self
):
if
self
.
algorithm
==
'h'
:
return
heatshrink_compress
return
zlib
.
compress
def
epkInfo
(
self
):
epkInfo
=
OrderedDict
({
"appName"
:
self
.
_appName
,
"appVersion"
:
self
.
_appVersion
,
"files"
:
self
.
fileinfos
(
self
.
_appDir
),
})
infocontent
=
json
.
dumps
(
epkInfo
)
with
open
(
self
.
_infoPath
,
"w"
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
infocontent
)
return
epkInfo
def
fileinfos
(
self
,
path
):
path
=
os
.
path
.
abspath
(
path
)
home_fs
=
fs
.
open_fs
(
path
)
files
=
[]
for
jspath
in
home_fs
.
glob
(
'*'
,
namespaces
=
[
'details'
]):
fpath
=
"C:/
%
s"
%
jspath
.
info
.
name
fname
=
jspath
.
info
.
name
fsize
=
jspath
.
info
.
size
fbasename
,
fext
=
os
.
path
.
splitext
(
jspath
.
info
.
name
)
if
fext
in
[
""
,
".exe"
,
".dll"
,
".nv"
,
".conf"
]:
continue
finfo
=
{
"path"
:
fpath
,
"name"
:
fname
,
"size"
:
fsize
,
"basename"
:
fbasename
,
"ext"
:
fext
}
if
self
.
_infoPath
==
os
.
sep
.
join
([
path
,
fname
]):
files
.
insert
(
0
,
finfo
)
else
:
files
.
append
(
finfo
)
if
fext
==
".evue"
:
self
.
fileMD5
(
finfo
)
return
files
def
header
(
self
,
epk_start
=
0xAAAA
,
md5_offset
=
0
,
file_count
=
0
):
bytes_header
=
struct
.
pack
(
"<HLH"
,
epk_start
,
md5_offset
,
file_count
)
return
bytes_header
def
fileMD5
(
self
,
info
):
md5path
=
os
.
sep
.
join
([
self
.
_appDir
,
"
%
s.md5"
%
info
[
"basename"
]])
fpath
=
os
.
sep
.
join
([
self
.
_appDir
,
info
[
"name"
]])
with
open
(
fpath
,
"rb"
)
as
f
:
filecontent
=
f
.
read
()
newmd5
=
self
.
md5
(
filecontent
)
with
open
(
md5path
,
"wb"
)
as
f
:
f
.
write
(
newmd5
)
return
newmd5
def
sign
(
self
,
content
):
ret
=
b
""
for
i
in
range
(
int
(
len
(
content
)
/
2
)):
ret
+=
struct
.
pack
(
"<B"
,
int
(
"0x
%
s"
%
(
content
[
i
*
2
:
i
*
2
+
2
]),
16
))
ret
=
ret
+
b
'EVM is NB ++!'
return
ret
def
md5
(
self
,
filecontent
):
newmd5
=
''
content
=
filecontent
for
i
in
range
(
3
):
md5
=
hashlib
.
md5
()
#获取一个md5加密算法对象
md5
.
update
(
content
)
#指定需要加密的字符串
newmd5
=
md5
.
hexdigest
()
#获取加密后的16进制字符串
content
=
self
.
sign
(
newmd5
)
ret
=
b
""
for
i
in
range
(
int
(
len
(
newmd5
)
/
2
)):
ret
+=
struct
.
pack
(
"<B"
,
int
(
"0x
%
s"
%
(
newmd5
[
i
*
2
:
i
*
2
+
2
]),
16
))
return
ret
def
packFile
(
self
,
info
,
level
=
9
):
fname
=
info
[
"name"
]
fpath
=
os
.
sep
.
join
([
self
.
_appDir
,
fname
])
fext
=
info
[
"ext"
]
fileBytes
=
b
""
if
fext
==
"md5"
:
fileBytes
+=
struct
.
pack
(
"<B"
,
1
)
else
:
fileBytes
+=
struct
.
pack
(
"<B"
,
2
)
_name
=
fname
+
"
\0
"
fileBytes
+=
struct
.
pack
(
"<B"
,
len
(
_name
))
fileBytes
+=
struct
.
pack
(
"<
%
ds"
%
len
(
_name
),
fname
.
encode
(
"utf-8"
))
with
open
(
fpath
,
"rb"
)
as
fc
:
fileContentBytes
=
fc
.
read
()
fileBytes
+=
struct
.
pack
(
"<L"
,
len
(
fileContentBytes
))
if
fext
==
"md5"
:
fileCompressBytes
=
fileContentBytes
else
:
fileCompressBytes
=
self
.
compress
()(
fileContentBytes
,
level
)
fileBytes
+=
struct
.
pack
(
"<L"
,
len
(
fileCompressBytes
))
fileBytes
+=
fileCompressBytes
return
fileBytes
def
pack
(
self
,
level
=
9
):
for
i
in
range
(
10
):
infos
=
self
.
epkInfo
()
# infos = self.epkInfo()
# infos = self.epkInfo()
epkFileBytes
=
b
""
epkFileContentBytes
=
b
""
file_count
=
len
(
infos
[
"files"
])
with
open
(
self
.
_epkName
,
"wb"
)
as
f
:
for
info
in
infos
[
"files"
]:
epkFileContentBytes
+=
self
.
packFile
(
info
)
epkFileContentLength
=
len
(
epkFileContentBytes
)
epkFileBytes
+=
self
.
header
(
md5_offset
=
8
+
epkFileContentLength
,
file_count
=
file_count
)
epkFileBytes
+=
epkFileContentBytes
epkmd5Bytes
=
self
.
md5
(
epkFileBytes
)
epkFileBytes
+=
struct
.
pack
(
"<H"
,
len
(
epkmd5Bytes
))
epkFileBytes
+=
epkmd5Bytes
crcBytes
=
zlib
.
crc32
(
epkFileBytes
)
epkFileBytes
+=
struct
.
pack
(
"<L"
,
crcBytes
)
f
.
write
(
epkFileBytes
)
ret
=
{
"epkfile"
:
self
.
_epkName
,
"epk_filecontent_size"
:
epkFileContentLength
,
"md5_offset"
:
10
+
epkFileContentLength
,
"file_count"
:
file_count
,
"md5_length"
:
len
(
epkmd5Bytes
),
"md5"
:
epkmd5Bytes
,
"raw_crc"
:
hex
(
crcBytes
),
"compress_level"
:
level
,
"buff_length"
:
len
(
epkFileBytes
)
}
pprint
.
pprint
(
ret
)
return
ret
def
main
(
path
,
appName
,
algorithm
):
epk
=
EpkApp
(
appName
,
path
,
algorithm
)
epk
.
pack
()
if
__name__
==
'__main__'
:
main
(
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
])
tools/build_out/webcreator/utils/lib/eheatshrink.dll
deleted
100644 → 0
View file @
32df1548
File deleted
tools/build_out/webcreator/utils/lib/libeheatshrink.so
deleted
100644 → 0
View file @
32df1548
File deleted
tools/build_out/webcreator/utils/tools_epk_1.0.py
deleted
100644 → 0
View file @
32df1548
#-*- coding: UTF-8 -*-
#!/usr/bin/python
import
os
import
sys
import
fs
import
struct
import
json
from
collections
import
OrderedDict
import
zlib
import
pprint
import
hashlib
def
str_to_hex
(
s
):
return
' '
.
join
([
hex
(
ord
(
c
))
.
replace
(
'0x'
,
''
)
for
c
in
s
])
def
hex_to_str
(
s
):
return
''
.
join
([
chr
(
i
)
for
i
in
[
int
(
b
,
16
)
for
b
in
s
.
split
(
' '
)]])
def
str_to_bin
(
s
):
return
' '
.
join
([
bin
(
ord
(
c
))
.
replace
(
'0b'
,
''
)
for
c
in
s
])
def
bin_to_str
(
s
):
return
''
.
join
([
chr
(
i
)
for
i
in
[
int
(
b
,
2
)
for
b
in
s
.
split
(
' '
)]])
class
EpkApp
(
object
):
def
__init__
(
self
,
appName
,
appDir
,
appVersion
=
"1.0"
,
output
=
"epks"
):
super
(
EpkApp
,
self
)
.
__init__
()
self
.
_appName
=
appName
self
.
_appDir
=
os
.
path
.
abspath
(
appDir
)
self
.
_appVersion
=
appVersion
self
.
_appCRCCode
=
None
self
.
_files
=
[]
self
.
_infoPath
=
os
.
sep
.
join
([
self
.
_appDir
,
"
%
s.json"
%
self
.
_appName
])
self
.
_epksDir
=
output
if
not
os
.
path
.
exists
(
self
.
_epksDir
):
fs
.
open_fs
(
os
.
getcwd
())
.
makedirs
(
output
)
self
.
_epkName
=
os
.
sep
.
join
([
self
.
_epksDir
,
"
%
s.epk"
%
self
.
_appName
])
def
epkInfo
(
self
):
epkInfo
=
OrderedDict
({
"appName"
:
self
.
_appName
,
"appVersion"
:
self
.
_appVersion
,
"files"
:
self
.
fileinfos
(
self
.
_appDir
),
})
infocontent
=
json
.
dumps
(
epkInfo
)
with
open
(
self
.
_infoPath
,
"w"
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
infocontent
)
return
epkInfo
def
fileinfos
(
self
,
path
):
path
=
os
.
path
.
abspath
(
path
)
home_fs
=
fs
.
open_fs
(
path
)
files
=
[]
for
jspath
in
home_fs
.
glob
(
'*'
,
namespaces
=
[
'details'
]):
fpath
=
"C:/
%
s"
%
jspath
.
info
.
name
fname
=
jspath
.
info
.
name
fsize
=
jspath
.
info
.
size
fbasename
=
jspath
.
info
.
name
.
split
(
"."
)[
0
]
fext
=
jspath
.
info
.
name
.
split
(
"."
)[
1
]
if
fext
in
[
"exe"
,
"dll"
,
"nv"
,
"conf"
]:
continue
finfo
=
{
"path"
:
fpath
,
"name"
:
fname
,
"size"
:
fsize
,
"basename"
:
fbasename
,
"ext"
:
fext
}
if
self
.
_infoPath
==
os
.
sep
.
join
([
path
,
fname
]):
files
.
insert
(
0
,
finfo
)
else
:
files
.
append
(
finfo
)
if
fext
==
"evue"
:
self
.
fileMD5
(
finfo
)
return
files
def
header
(
self
,
epk_start
=
0xAAAA
,
md5_offset
=
0
,
file_count
=
0
):
bytes_header
=
struct
.
pack
(
"<HLH"
,
epk_start
,
md5_offset
,
file_count
)
return
bytes_header
def
fileMD5
(
self
,
info
):
md5path
=
os
.
sep
.
join
([
self
.
_appDir
,
"
%
s.md5"
%
info
[
"basename"
]])
fpath
=
os
.
sep
.
join
([
self
.
_appDir
,
info
[
"name"
]])
with
open
(
fpath
,
"rb"
)
as
f
:
filecontent
=
f
.
read
()
print
(
fpath
)
newmd5
=
self
.
md5
(
filecontent
)
print
(
md5path
)
with
open
(
md5path
,
"wb"
)
as
f
:
f
.
write
(
newmd5
)
return
newmd5
def
sign
(
self
,
content
):
ret
=
b
""
for
i
in
range
(
int
(
len
(
content
)
/
2
)):
ret
+=
struct
.
pack
(
"<B"
,
int
(
"0x
%
s"
%
(
content
[
i
*
2
:
i
*
2
+
2
]),
16
))
ret
=
ret
+
b
'EVM is NB ++!'
return
ret
def
md5
(
self
,
filecontent
):
newmd5
=
''
content
=
filecontent
for
i
in
range
(
3
):
md5
=
hashlib
.
md5
()
#获取一个md5加密算法对象
md5
.
update
(
content
)
#指定需要加密的字符串
newmd5
=
md5
.
hexdigest
()
#获取加密后的16进制字符串
print
(
newmd5
)
content
=
self
.
sign
(
newmd5
)
ret
=
b
""
for
i
in
range
(
int
(
len
(
newmd5
)
/
2
)):
ret
+=
struct
.
pack
(
"<B"
,
int
(
"0x
%
s"
%
(
newmd5
[
i
*
2
:
i
*
2
+
2
]),
16
))
return
ret
def
packFile
(
self
,
info
,
level
=
9
):
fname
=
info
[
"name"
]
fpath
=
os
.
sep
.
join
([
self
.
_appDir
,
fname
])
fext
=
info
[
"ext"
]
fileBytes
=
b
""
if
fext
==
"md5"
:
fileBytes
+=
struct
.
pack
(
"<B"
,
1
)
else
:
fileBytes
+=
struct
.
pack
(
"<B"
,
2
)
_name
=
fname
+
"
\0
"
fileBytes
+=
struct
.
pack
(
"<B"
,
len
(
_name
))
fileBytes
+=
struct
.
pack
(
"<
%
ds"
%
len
(
_name
),
fname
.
encode
(
"utf-8"
))
with
open
(
fpath
,
"rb"
)
as
fc
:
fileContentBytes
=
fc
.
read
()
print
(
info
[
"name"
])
print
(
len
(
fileContentBytes
))
fileBytes
+=
struct
.
pack
(
"<L"
,
len
(
fileContentBytes
))
if
fext
==
"md5"
:
fileCompressBytes
=
fileContentBytes
else
:
fileCompressBytes
=
zlib
.
compress
(
fileContentBytes
,
level
)
print
(
len
(
fileCompressBytes
))
fileBytes
+=
struct
.
pack
(
"<L"
,
len
(
fileCompressBytes
))
fileBytes
+=
fileCompressBytes
return
fileBytes
def
pack
(
self
,
level
=
9
):
for
i
in
range
(
10
):
infos
=
self
.
epkInfo
()
# infos = self.epkInfo()
# infos = self.epkInfo()
result
=
{}
epkFileBytes
=
b
""
epkFileContentBytes
=
b
""
file_count
=
len
(
infos
[
"files"
])
with
open
(
self
.
_epkName
,
"wb"
)
as
f
:
for
info
in
infos
[
"files"
]:
epkFileContentBytes
+=
self
.
packFile
(
info
)
epkFileContentLength
=
len
(
epkFileContentBytes
)
epkFileBytes
+=
self
.
header
(
md5_offset
=
8
+
epkFileContentLength
,
file_count
=
file_count
)
epkFileBytes
+=
epkFileContentBytes
epkmd5Bytes
=
self
.
md5
(
epkFileBytes
)
epkFileBytes
+=
struct
.
pack
(
"<H"
,
len
(
epkmd5Bytes
))
epkFileBytes
+=
epkmd5Bytes
crcBytes
=
zlib
.
crc32
(
epkFileBytes
)
epkFileBytes
+=
struct
.
pack
(
"<L"
,
crcBytes
)
f
.
write
(
epkFileBytes
)
ret
=
{
"epkfile"
:
self
.
_epkName
,
"epk_filecontent_size"
:
epkFileContentLength
,
"md5_offset"
:
10
+
epkFileContentLength
,
"file_count"
:
file_count
,
"md5_length"
:
len
(
epkmd5Bytes
),
"md5"
:
epkmd5Bytes
,
"raw_crc"
:
hex
(
crcBytes
),
"compress_level"
:
level
,
"buff_length"
:
len
(
epkFileBytes
)
}
result
=
ret
return
result
def
main
(
path
,
appName
):
epk
=
EpkApp
(
appName
,
path
)
epk
.
pack
()
if
__name__
==
'__main__'
:
main
(
sys
.
argv
[
1
],
sys
.
argv
[
2
])
tools/build_out/webcreator/webscoket.py
deleted
100644 → 0
View file @
32df1548
'''
Author: your name
Date: 2021-06-15 17:40:19
LastEditTime: 2021-07-14 18:38:12
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\r
esources
\
webcreator
\
webscoket.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
json
from
tornado.websocket
import
WebSocketHandler
,
WebSocketClosedError
from
.utils
import
ObjectDict
from
.log
import
logger
class
WebsocketResponse
(
ObjectDict
):
def
__init__
(
self
,
type
=
"Response"
,
api_code
=-
1
,
message
=
'fail'
,
data
=
None
,
traceback
=
""
):
super
(
WebsocketResponse
,
self
)
.
__init__
()
self
.
type
=
type
self
.
code
=
api_code
self
.
message
=
message
self
.
data
=
data
self
.
traceback
=
traceback
if
isinstance
(
self
.
data
,
list
):
self
.
count
=
len
(
self
.
data
)
def
pushmessage
(
func
):
def
send
(
*
agrs
,
**
kwargs
):
self
=
agrs
[
0
]
ret
=
func
(
*
agrs
,
**
kwargs
)
if
ret
:
msg
,
binary
=
ret
try
:
if
isinstance
(
msg
,
WebsocketResponse
)
or
isinstance
(
msg
,
dict
):
self
.
write_message
(
json
.
dumps
(
msg
),
binary
)
elif
isinstance
(
msg
,
str
)
or
isinstance
(
msg
,
str
):
self
.
write_message
(
msg
,
binary
)
else
:
self
.
write_message
(
repr
(
msg
),
binary
)
except
WebSocketClosedError
as
e
:
logger
.
error
(
e
)
self
.
on_close
()
return
send
class
BaseWebsocket
(
WebSocketHandler
):
handlers
=
{}
def
open
(
self
):
logger
.
warn
(
"websocket of
%
s is opened"
,
repr
(
self
))
className
=
self
.
__class__
.
__name__
if
className
not
in
self
.
handlers
:
self
.
handlers
[
className
]
=
set
()
self
.
handlers
[
className
]
.
add
(
self
)
@
pushmessage
def
send
(
self
,
message
,
binary
=
False
):
return
message
,
binary
def
on_close
(
self
):
logger
.
warn
(
"websocket of
%
s is closed"
,
repr
(
self
))
className
=
self
.
__class__
.
__name__
if
className
in
self
.
handlers
:
self
.
handlers
[
className
]
.
remove
(
self
)
def
check_origin
(
self
,
origin
):
return
True
@
classmethod
def
boardcastMessage
(
cls
,
message
,
binary
=
False
):
className
=
cls
.
__name__
if
className
in
cls
.
handlers
:
for
handler
in
cls
.
handlers
[
className
]:
handler
.
send
(
message
,
binary
)
class
NotifyHandler
(
BaseWebsocket
):
"""
建立与web前端的通信连接,发送状态信息报文
"""
def
open
(
self
):
super
(
NotifyHandler
,
self
)
.
open
()
def
on_message
(
self
,
message
):
pass
class
ThreadNotifyHandler
(
BaseWebsocket
):
"""
建立与tornado主线程与子线程之间的通信连接
"""
def
open
(
self
):
super
(
ThreadNotifyHandler
,
self
)
.
open
()
def
on_message
(
self
,
message
):
NotifyHandler
.
boardcastMessage
(
message
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment