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
a36af83d
Commit
a36af83d
authored
Jul 14, 2021
by
wanli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
68ec88f3
Changes
32
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
1180 additions
and
28938 deletions
+1180
-28938
tools/build_out/README.md
tools/build_out/README.md
+1
-11
tools/build_out/controllers/__init__.py
tools/build_out/controllers/__init__.py
+10
-32
tools/build_out/controllers/app.py
tools/build_out/controllers/app.py
+28
-231
tools/build_out/controllers/area.py
tools/build_out/controllers/area.py
+12
-22
tools/build_out/controllers/login.py
tools/build_out/controllers/login.py
+21
-56
tools/build_out/controllers/package.py
tools/build_out/controllers/package.py
+21
-122
tools/build_out/controllers/user.py
tools/build_out/controllers/user.py
+14
-24
tools/build_out/logs/running.log
tools/build_out/logs/running.log
+3
-27813
tools/build_out/manager.py
tools/build_out/manager.py
+8
-0
tools/build_out/models/app.py
tools/build_out/models/app.py
+11
-12
tools/build_out/models/area.py
tools/build_out/models/area.py
+1
-1
tools/build_out/models/base.py
tools/build_out/models/base.py
+1
-2
tools/build_out/models/login.py
tools/build_out/models/login.py
+15
-27
tools/build_out/models/package.py
tools/build_out/models/package.py
+3
-16
tools/build_out/models/user.py
tools/build_out/models/user.py
+67
-44
tools/build_out/views/__init__.py
tools/build_out/views/__init__.py
+1
-38
tools/build_out/views/app.py
tools/build_out/views/app.py
+30
-28
tools/build_out/views/area.py
tools/build_out/views/area.py
+14
-14
tools/build_out/views/login.py
tools/build_out/views/login.py
+20
-31
tools/build_out/views/package.py
tools/build_out/views/package.py
+12
-15
tools/build_out/views/user.py
tools/build_out/views/user.py
+32
-26
tools/build_out/webcreator/event.py
tools/build_out/webcreator/event.py
+13
-1
tools/build_out/webcreator/log.py
tools/build_out/webcreator/log.py
+14
-1
tools/build_out/webcreator/response.py
tools/build_out/webcreator/response.py
+26
-85
tools/build_out/webcreator/utils/__init__.py
tools/build_out/webcreator/utils/__init__.py
+1
-152
tools/resources/webcreator/utils/__init__.py
tools/resources/webcreator/utils/__init__.py
+1
-134
tools/resources/webcreator/utils/ccode.py
tools/resources/webcreator/utils/ccode.py
+76
-0
tools/resources/webcreator/utils/epk.py
tools/resources/webcreator/utils/epk.py
+267
-0
tools/resources/webcreator/utils/epk_2.0.py
tools/resources/webcreator/utils/epk_2.0.py
+234
-0
tools/resources/webcreator/utils/lib/eheatshrink.dll
tools/resources/webcreator/utils/lib/eheatshrink.dll
+0
-0
tools/resources/webcreator/utils/lib/libeheatshrink.so
tools/resources/webcreator/utils/lib/libeheatshrink.so
+0
-0
tools/resources/webcreator/utils/tools_epk_1.0.py
tools/resources/webcreator/utils/tools_epk_1.0.py
+223
-0
No files found.
tools/build_out/README.md
View file @
a36af83d
<!--
*
@Author: your name
*
@Date: 2021-06-30 17:43:46
*
@LastEditTime: 2021-07-11 13:48:10
*
@LastEditors: Please set LastEditors
*
@Description: In User Settings Edit
*
@FilePath:
\e
vm-store
\t
ools
\b
uild_out
\R
EADME.md
-->
# Flask-Migrate
# Flask-Migrate
数据库迁移工具:使用Flask-Migrate数据库迁移框架可以保证数据库结构在发生变化时,改变数据库结构不至于丢失数据库的数据。
数据库迁移工具:使用Flask-Migrate数据库迁移框架可以保证数据库结构在发生变化时,改变数据库结构不至于丢失数据库的数据。
...
@@ -76,6 +68,4 @@ python manager.py db migrate
...
@@ -76,6 +68,4 @@ python manager.py db migrate
python manager.py db upgrade
python manager.py db upgrade
```
```
详情参考:
详情参考:https://zhuanlan.zhihu.com/p/307612189
+
https://zhuanlan.zhihu.com/p/307612189
\ No newline at end of file
+
https://file-manager.webmai.ru/
\ No newline at end of file
tools/build_out/controllers/__init__.py
View file @
a36af83d
'''
Author: your name
Date: 2021-06-30 17:43:46
LastEditTime: 2021-07-09 13:10:51
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
controllers
\
__init__.py
'''
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf_8 -*-
# -*- coding: utf_8 -*-
...
@@ -7,14 +15,7 @@ from .app import appManager
...
@@ -7,14 +15,7 @@ from .app import appManager
from
.package
import
packageManager
from
.package
import
packageManager
from
.user
import
userManager
from
.user
import
userManager
from
.login
import
loginManager
from
.login
import
loginManager
from
.device
import
deviceManager
from
.file_manager
import
fileManager
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
.file
import
fileManager
def
initConnect
():
def
initConnect
():
signalManager
.
actionPostArea
.
connect
(
areaManager
.
post
)
signalManager
.
actionPostArea
.
connect
(
areaManager
.
post
)
...
@@ -37,28 +38,5 @@ def initConnect():
...
@@ -37,28 +38,5 @@ def initConnect():
signalManager
.
actionPostLogin
.
connect
(
loginManager
.
post
)
signalManager
.
actionPostLogin
.
connect
(
loginManager
.
post
)
signalManager
.
actionGetListLogin
.
connect
(
loginManager
.
getList
)
signalManager
.
actionGetListLogin
.
connect
(
loginManager
.
getList
)
signalManager
.
actionGetLogin
.
connect
(
loginManager
.
get
)
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
)
# file manager api
signalManager
.
actionGetFileContent
.
connect
(
fileManager
.
content
)
signalManager
.
actionGetFileContent
.
connect
(
fileManager
.
content
)
signalManager
.
actionGetFileDisk
.
connect
(
fileManager
.
disk
)
# signalManager.actionGEt
signalManager
.
actionGetFileDown
.
connect
(
fileManager
.
download
)
\ No newline at end of file
signalManager
.
actionGetFileInit
.
connect
(
fileManager
.
initialize
)
signalManager
.
actionGetFilePreview
.
connect
(
fileManager
.
preview
)
signalManager
.
actionGetFileTree
.
connect
(
fileManager
.
tree
)
tools/build_out/controllers/app.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
os
import
re
import
json
import
shutil
from
datetime
import
datetime
from
datetime
import
datetime
from
sqlalchemy
import
func
,
distinct
from
application.app
import
db
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
models.app
import
AppModel
from
application.config
import
config
from
webcreator.utils.epk
import
EpkApp
from
webcreator.log
import
logger
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
# from webcreator.response import ResponseCode, response_result
class
AppResource
(
object
):
class
AppResource
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -24,74 +11,10 @@ class AppResource(object):
...
@@ -24,74 +11,10 @@ class AppResource(object):
def
get
(
self
,
uuid
,
params
):
def
get
(
self
,
uuid
,
params
):
# handle business
# handle business
filters
=
[
AppModel
.
is_delete
==
False
,
AppModel
.
uuid
==
uuid
]
filters
=
[
AppModel
.
is_delete
==
False
,
AppModel
.
uuid
==
uuid
]
app
=
AppModel
.
query
.
filter
(
*
filters
)
.
one_or_none
()
result
=
AppModel
.
query
.
filter
(
*
filters
)
.
first
()
if
not
app
:
if
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
True
,
result
)
return
(
False
,
result
)
user
=
UserModel
.
query
.
filter
(
UserModel
.
id
==
params
.
get
(
'user'
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# 根据app查询应用,获取应用有哪些文件
# 按格式创建文件夹,将这些文件移动到这个文件夹
# 将这些零散文件进行打包
# 更新数据库对应文件的路径
source_files
=
AnnexModel
.
query
.
filter
(
AnnexModel
.
app
==
app
)
.
all
()
if
not
source_files
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
dtNowString
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
)
dirname
=
"{}-{}-{}-{}"
.
format
(
app
.
app_name
,
app
.
app_version
,
app
.
category
,
dtNowString
)
upload_dir
=
os
.
sep
.
join
([
config
.
UPLOAD_ROOT_DIR
,
config
.
EPK_DIR
])
target_dir
=
os
.
sep
.
join
([
upload_dir
,
dirname
])
dest_dir
=
os
.
sep
.
join
([
target_dir
,
"src"
])
if
not
os
.
path
.
exists
(
dest_dir
):
os
.
makedirs
(
dest_dir
)
app_files
=
[]
for
sf
in
source_files
:
target_file
=
sf
.
path
if
not
os
.
path
.
exists
(
sf
.
path
):
target_file
=
os
.
sep
.
join
([
config
.
UPLOAD_ROOT_DIR
,
sf
.
path
])
filename
=
os
.
path
.
basename
(
target_file
)
name
,
suffix
=
os
.
path
.
splitext
(
filename
)
name
=
re
.
sub
(
r"_\d{14}$"
,
""
,
name
)
dst_file
=
os
.
path
.
normpath
(
os
.
sep
.
join
([
dest_dir
,
name
+
suffix
]))
shutil
.
copy
(
os
.
path
.
normpath
(
target_file
),
dst_file
)
app_files
.
append
([
sf
.
id
,
dst_file
])
with
open
(
os
.
sep
.
join
([
target_dir
,
"epk.json"
]),
"w"
)
as
f
:
json
.
dump
(
app
.
to_dict
(
exclude
=
[
"uuid"
,
"create_at"
,
"update_at"
,
"delete_at"
]),
f
)
# 打包成EPK文件
app_info
=
{}
params
=
{
'appName'
:
app
.
app_name
,
'appDir'
:
dest_dir
,
'appVersion'
:
app
.
app_version
,
'output'
:
target_dir
}
if
user
.
role
==
"administrator"
or
user
.
role
==
"community"
:
params
[
'algorithm'
]
=
"h"
epk
=
EpkApp
(
**
params
)
app_info
=
epk
.
pack
()
app_info
[
'md5'
]
=
str
(
app_info
[
'md5'
])
# 更新数据库对应文件路径
# 将文件拷贝过去后,需要重新更新数据库文件记录
epk_path
=
os
.
sep
.
join
([
target_dir
.
replace
(
config
.
UPLOAD_ROOT_DIR
,
""
),
"{}.epk"
.
format
(
app
.
app_name
)])
.
replace
(
'
\\
'
,
'/'
)
package
=
PackageModel
.
query
.
filter
(
PackageModel
.
app
==
app
)
.
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
=
app_info
,
create_by
=
user
,
create_at
=
datetime
.
now
())
db
.
session
.
add
(
package
)
db
.
session
.
commit
()
return
{
'app_name'
:
app
.
app_name
,
'app_path'
:
epk_path
},
ResponseCode
.
HTTP_NOT_FOUND
def
getList
(
self
,
params
):
def
getList
(
self
,
params
):
# handle business
# handle business
...
@@ -99,178 +22,52 @@ class AppResource(object):
...
@@ -99,178 +22,52 @@ class AppResource(object):
filters
=
[
AppModel
.
is_delete
==
False
]
filters
=
[
AppModel
.
is_delete
==
False
]
result
=
AppModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AppModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
result
=
AppModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AppModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
not
result
:
return
(
True
,
result
.
items
,
result
.
total
)
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
user
=
UserModel
.
query
.
filter
(
UserModel
.
id
==
params
.
get
(
'user'
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
temp
=
{}
if
user
.
role
==
"administrator"
:
temp
.
update
({
"is_delete"
:
False
})
else
:
temp
.
update
({
"create_by"
:
user
,
"is_delete"
:
False
})
if
"scope_type"
in
params
and
params
.
get
(
"scope_type"
)
==
"list"
:
result
=
AppModel
.
query
.
filter_by
(
**
temp
)
.
order_by
(
AppModel
.
create_at
.
desc
())
temp
=
[]
for
item
in
result
:
temp
.
append
(
item
.
to_dict
(
only
=
[
"uuid"
,
"app_name"
]))
return
(
temp
,
len
(
temp
)),
ResponseCode
.
HTTP_SUCCESS
elif
"scope_type"
in
params
and
params
.
get
(
"scope_type"
)
==
"distinct"
:
result
=
db
.
session
.
query
(
AppModel
,
func
.
count
(
distinct
(
AppModel
.
name
)))
.
all
()
temp
=
[]
for
item
in
result
:
temp
.
append
(
item
)
return
(
temp
,
len
(
temp
)),
ResponseCode
.
HTTP_SUCCESS
result
=
AppModel
.
query
.
filter_by
(
**
temp
)
.
order_by
(
AppModel
.
sort
)
.
order_by
(
AppModel
.
create_at
.
desc
())
.
paginate
(
params
.
get
(
"pagenum"
,
1
),
params
.
get
(
"pagesize"
,
10
),
error_out
=
False
)
if
result
.
total
and
len
(
result
.
items
):
temp
=
[]
for
item
in
result
.
items
:
t
=
dict
()
t
.
update
(
item
.
to_json
())
t
.
update
({
"create_by"
:
item
.
create_by
.
to_dict
(
only
=
[
"uuid"
,
"username"
]),
"update_by"
:
item
.
update_by
.
to_dict
(
only
=
[
"uuid"
,
"username"
]),
"create_at"
:
item
.
create_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
item
.
create_at
else
None
,
"update_at"
:
item
.
update_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
item
.
update_at
else
None
,
})
temp
.
append
(
t
)
result
=
temp
return
result
,
ResponseCode
.
HTTP_SUCCESS
def
post
(
self
,
params
,
jwt
=
{}):
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
# handle business
# 应用打包
result
=
AppModel
.
query
.
filter
(
AppModel
.
app_name
==
params
.
get
(
'app_name'
))
.
first
()
# 插入一条打包记录
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
user
=
UserModel
.
query
.
filter
(
UserModel
.
id
==
params
.
get
(
'user'
))
.
one_or_none
()
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
if
not
user
:
result
.
update_date
=
datetime
.
now
()
return
False
,
ResponseCode
.
USER_NOT_EXISTS
db
.
session
.
commit
()
return
(
True
,
None
)
# 判断下app是否存在
elif
result
and
result
.
is_delete
==
False
:
# result = Apps.select(app_name=data.get("app_name"), is_delete=False).count()
return
(
False
,
"record code exists"
)
# if result < 1:
# return False, "app_name has been exists."
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
=
""
if
params
.
get
(
"fileList"
):
app_files
=
params
.
get
(
"fileList"
)
params
.
pop
(
"fileList"
)
epk_path
=
params
.
get
(
"epk_path"
)
params
.
pop
(
"epk_path"
)
app
=
AppModel
(
**
params
)
db
.
session
.
add
(
app
)
db
.
session
.
commit
()
# 在EPK目录下生成JSON文件
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
:
res
=
AnnexModel
(
app
=
app
,
title
=
os
.
path
.
basename
(
a
),
path
=
a
,
size
=
os
.
path
.
getsize
(
a
),
create_by
=
user
,
create_at
=
datetime
.
now
(),
update_by
=
user
,
update_at
=
datetime
.
now
())
db
.
session
.
add
(
res
)
db
.
session
.
flush
()
db
.
session
.
commit
()
app_info
=
{}
params
=
{
'appName'
:
app
.
app_name
,
'appDir'
:
epk_path
,
'appVersion'
:
app
.
app_version
,
'output'
:
os
.
path
.
dirname
(
epk_path
)
}
if
user
.
role
==
"administrator"
or
user
.
role
==
"community"
:
params
[
'algorithm'
]
=
"h"
epk
=
EpkApp
(
**
params
)
app_info
=
epk
.
pack
()
epk_filename
=
os
.
sep
.
join
([
os
.
path
.
dirname
(
epk_path
)
.
replace
(
config
.
UPLOAD_ROOT_DIR
,
""
),
"{}.epk"
.
format
(
app
.
app_name
)])
.
replace
(
'
\\
'
,
'/'
)
if
app_info
:
app_info
[
'md5'
]
=
str
(
app_info
[
'md5'
])
package
=
PackageModel
(
app
=
app
,
file_path
=
epk_filename
,
app_version
=
params
.
get
(
"app_version"
),
package_info
=
app_info
,
source
=
1
,
create_by
=
user
,
create_at
=
datetime
.
now
(),
update_by
=
user
,
update_at
=
datetime
.
now
()
)
result
=
AppModel
(
**
params
)
db
.
session
.
add
(
package
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
(
True
,
None
)
return
True
,
ResponseCode
.
HTTP_SUCCESS
# result = AppModel.query.filter(AppModel.app_name == params.get('app_name')).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 = AppModel(**params)
# db.session.add(result)
# db.session.commit()
# return True, ResponseCode.HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
user
=
UserModel
.
query
.
filter
(
UserModel
.
id
==
params
.
get
(
'user'
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# handle business
# handle business
app
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
uuid
)
.
first
()
result
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
uuid
)
.
first
()
if
not
app
:
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
if
params
:
if
params
:
# 更新文件
if
params
.
get
(
"app_files"
):
for
a
in
params
.
get
(
"app_files"
):
res
=
AnnexModel
(
app
=
app
,
title
=
a
.
get
(
"filename"
),
path
=
a
.
get
(
"filepath"
),
size
=
a
.
get
(
"filesize"
),
create_by
=
user
,
create_at
=
datetime
.
now
(),
update_by
=
user
,
update_at
=
datetime
.
now
())
db
.
session
.
add
(
res
)
db
.
session
.
flush
()
db
.
session
.
commit
()
params
.
pop
(
"app_files"
)
# 更新icon
if
params
.
get
(
"app_icon"
):
condition
=
{
'update_by'
:
user
,
'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
():
for
key
,
value
in
params
.
items
():
if
value
!=
None
:
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
setattr
(
app
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
app
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
app
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
# handle business
result
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
uuid
)
.
first
()
result
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
appManager
=
AppResource
()
appManager
=
AppResource
()
\ No newline at end of file
tools/build_out/controllers/area.py
View file @
a36af83d
'''
Author: your name
Date: 2021-06-30 18:03:41
LastEditTime: 2021-07-12 11:31:06
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
controllers
\a
rea.py
'''
from
datetime
import
datetime
from
datetime
import
datetime
from
application.app
import
db
from
application.app
import
db
from
models.area
import
AreaModel
from
models.area
import
AreaModel
from
webcreator.log
import
logger
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
# from webcreator.response import ResponseCode, response_result
class
AreaResource
(
object
):
class
AreaResource
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -21,8 +13,8 @@ class AreaResource(object):
...
@@ -21,8 +13,8 @@ class AreaResource(object):
filters
=
[
AreaModel
.
is_delete
==
False
,
AreaModel
.
uuid
==
uuid
]
filters
=
[
AreaModel
.
is_delete
==
False
,
AreaModel
.
uuid
==
uuid
]
result
=
AreaModel
.
query
.
filter
(
*
filters
)
.
first
()
result
=
AreaModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
result
)
return
result
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
result
)
def
getList
(
self
,
params
):
def
getList
(
self
,
params
):
# handle business
# handle business
...
@@ -30,9 +22,7 @@ class AreaResource(object):
...
@@ -30,9 +22,7 @@ class AreaResource(object):
filters
=
[
AreaModel
.
is_delete
==
False
]
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
)
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
(
True
,
result
.
items
,
result
.
total
)
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
# handle business
...
@@ -42,9 +32,9 @@ class AreaResource(object):
...
@@ -42,9 +32,9 @@ class AreaResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
elif
result
and
result
.
is_delete
==
False
:
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"record code exists"
)
result
=
AreaModel
(
**
params
)
result
=
AreaModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
add
(
result
)
...
@@ -55,7 +45,7 @@ class AreaResource(object):
...
@@ -55,7 +45,7 @@ class AreaResource(object):
# handle business
# handle business
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
uuid
==
uuid
)
.
first
()
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
if
params
:
if
params
:
for
key
,
value
in
params
.
items
():
for
key
,
value
in
params
.
items
():
...
@@ -63,21 +53,21 @@ class AreaResource(object):
...
@@ -63,21 +53,21 @@ class AreaResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
# handle business
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
uuid
==
uuid
)
.
first
()
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
areaManager
=
AreaResource
()
areaManager
=
AreaResource
()
\ No newline at end of file
tools/build_out/controllers/login.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
json
from
datetime
import
datetime
from
datetime
import
datetime
from
flask_jwt_extended
import
(
create_access_token
,)
from
application.app
import
db
from
application.app
import
db
from
models.login
import
LoginModel
from
models.login
import
LoginModel
from
models.user
import
UserModel
from
webcreator.log
import
logger
from
webcreator.log
import
logger
from
webcreator
import
utils
# from webcreator.response import ResponseCode, response_result
from
webcreator.response
import
ResponseCode
@
utils
.
ThreadMaker
def
update_login_information
(
ip
,
log_id
):
try
:
jsonData
=
utils
.
get_location_by_ip
(
ip
)
logger
.
info
(
jsonData
)
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
):
class
LoginResource
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -35,8 +13,8 @@ class LoginResource(object):
...
@@ -35,8 +13,8 @@ class LoginResource(object):
filters
=
[
LoginModel
.
is_delete
==
False
,
LoginModel
.
uuid
==
uuid
]
filters
=
[
LoginModel
.
is_delete
==
False
,
LoginModel
.
uuid
==
uuid
]
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
first
()
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
result
)
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
result
)
def
getList
(
self
,
params
):
def
getList
(
self
,
params
):
# handle business
# handle business
...
@@ -44,43 +22,30 @@ class LoginResource(object):
...
@@ -44,43 +22,30 @@ class LoginResource(object):
filters
=
[
LoginModel
.
is_delete
==
False
]
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
)
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
(
True
,
result
.
items
,
result
.
total
)
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
# handle business
user
=
UserModel
.
query
.
filter
(
UserModel
.
account
==
params
.
get
(
"account"
))
.
first
()
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
user
==
params
.
get
(
'user'
))
.
first
()
if
not
user
:
if
result
and
result
.
is_delete
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
logger
.
info
(
params
)
result
.
update_date
=
datetime
.
now
()
if
user
.
password
!=
utils
.
md5_encryption
(
params
.
get
(
"password"
)):
db
.
session
.
commit
()
return
False
,
ResponseCode
.
USER_PASSWORD_ERROR
return
(
True
,
None
)
elif
result
and
result
.
is_delete
==
False
:
return
(
False
,
"record code exists"
)
# 插入一条登录记录
result
=
LoginModel
(
**
params
)
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
.
add
(
result
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
(
True
,
None
)
# 获取当前登录IP地理位置信息
update_login_information
(
params
.
get
(
"ip"
),
result
.
id
)
# 生成一个token,返回给前端
result
=
{
'uuid'
:
user
.
uuid
,
'name'
:
user
.
username
,
'token'
:
create_access_token
(
identity
=
{
'uuid'
:
user
.
uuid
,
'name'
:
user
.
username
}),
}
return
result
,
ResponseCode
.
HTTP_SUCCESS
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
# handle business
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
uuid
==
uuid
)
.
first
()
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
if
params
:
if
params
:
for
key
,
value
in
params
.
items
():
for
key
,
value
in
params
.
items
():
...
@@ -88,21 +53,21 @@ class LoginResource(object):
...
@@ -88,21 +53,21 @@ class LoginResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
# handle business
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
uuid
==
uuid
)
.
first
()
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
loginManager
=
LoginResource
()
loginManager
=
LoginResource
()
\ No newline at end of file
tools/build_out/controllers/package.py
View file @
a36af83d
'''
Author: your name
Date: 2021-06-30 18:03:41
LastEditTime: 2021-07-12 11:11:49
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
datetime
import
datetime
from
datetime
import
datetime
from
application.app
import
db
,
config
from
application.app
import
db
from
models.annex
import
AnnexModel
from
models.app
import
AppModel
from
models.user
import
UserModel
from
models.package
import
PackageModel
from
models.package
import
PackageModel
from
webcreator.utils.epk
import
EpkApp
from
webcreator.log
import
logger
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
# from webcreator.response import ResponseCode, response_result
class
PackageResource
(
object
):
class
PackageResource
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -31,8 +13,8 @@ class PackageResource(object):
...
@@ -31,8 +13,8 @@ class PackageResource(object):
filters
=
[
PackageModel
.
is_delete
==
False
,
PackageModel
.
uuid
==
uuid
]
filters
=
[
PackageModel
.
is_delete
==
False
,
PackageModel
.
uuid
==
uuid
]
result
=
PackageModel
.
query
.
filter
(
*
filters
)
.
first
()
result
=
PackageModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
result
)
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
result
)
def
getList
(
self
,
params
):
def
getList
(
self
,
params
):
# handle business
# handle business
...
@@ -40,113 +22,30 @@ class PackageResource(object):
...
@@ -40,113 +22,30 @@ class PackageResource(object):
filters
=
[
PackageModel
.
is_delete
==
False
]
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
)
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
(
True
,
result
.
items
,
result
.
total
)
return
result
,
ResponseCode
.
HTTP_SUCCESS
user
=
UserModel
.
query
.
filter
(
id
=
params
.
get
(
'user'
))
.
onr_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
temp
=
{}
if
user
.
role
==
"administrator"
:
temp
.
update
({
"is_delete"
:
False
})
else
:
temp
.
update
({
"create_by"
:
user
.
id
,
"is_delete"
:
False
})
if
"scope_type"
in
params
and
params
.
get
(
"scope_type"
)
==
"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
)
})
return
temp
,
len
(
temp
),
"get build_logs {}."
.
format
(
"success"
if
temp
else
"fail"
)
result
=
PackageModel
.
query
.
filter_by
(
**
temp
)
.
order_by
(
PackageModel
.
create_at
.
desc
())
.
paginate
(
params
.
get
(
"pagenum"
,
1
),
params
.
get
(
"pagesize"
,
10
),
error_out
=
False
)
if
result
.
total
and
len
(
result
.
items
):
temp
=
[]
for
item
in
result
.
items
:
t
=
item
.
to_dict
()
t
.
update
({
"create_at"
:
item
.
create_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
item
.
create_at
else
None
,
"update_at"
:
item
.
update_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
item
.
update_at
else
None
,
})
temp
.
append
(
t
)
return
(
temp
,
result
.
total
),
ResponseCode
.
HTTP_SUCCESS
return
result
,
ResponseCode
.
HTTP_NO_DATA
def
post
(
self
,
params
,
jwt
=
{}):
def
post
(
self
,
params
,
jwt
=
{}):
# 判断用户是否存在
user
=
UserModel
.
query
.
filter
(
UserModel
.
id
==
params
.
get
(
'user'
))
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
=
os
.
sep
.
join
([
config
.
UPLOAD_ROOT_DIR
,
"uploads"
,
"evueapps"
])
target_dir
=
os
.
sep
.
join
([
upload_dir
,
user
.
account
,
dir_format
])
dest_dir
=
os
.
sep
.
join
([
target_dir
,
"src"
])
if
not
os
.
path
.
exists
(
dest_dir
):
os
.
makedirs
(
dest_dir
)
app_files
=
[]
for
sf
in
source_files
:
target_file
=
os
.
sep
.
join
([
config
.
UPLOAD_ROOT_DIR
,
sf
.
path
])
filename
=
os
.
path
.
basename
(
target_file
)
name
,
suffix
=
os
.
path
.
splitext
(
filename
)
name
=
re
.
sub
(
r"_\d{14}$"
,
""
,
name
)
dst_file
=
os
.
path
.
normpath
(
os
.
sep
.
join
([
dest_dir
,
name
+
suffix
]))
shutil
.
move
(
os
.
path
.
normpath
(
target_file
),
dst_file
)
app_files
.
append
([
sf
.
id
,
dst_file
])
# 打包成EPK文件
app_info
=
{}
params
=
{
'appName'
:
app
.
app_name
,
'appDir'
:
dest_dir
,
'appVersion'
:
app
.
app_version
,
'output'
:
target_dir
}
if
user
.
role
==
"administrator"
or
user
.
role
==
"community"
:
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
=
os
.
sep
.
join
([
target_dir
.
replace
(
config
.
UPLOAD_ROOT_DIR
,
""
),
"{}.epk"
.
format
(
app
.
app_name
)])
.
replace
(
'
\\
'
,
'/'
)
# handle business
# handle business
#
result = PackageModel.query.filter(PackageModel.app == params.get('app')).first()
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
app
==
params
.
get
(
'app'
))
.
first
()
#
if result and result.is_delete:
if
result
and
result
.
is_delete
:
#
result.is_delete = False
result
.
is_delete
=
False
#
result.update_by = jwt.get("id", "")
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
#
result.update_date = datetime.now()
result
.
update_date
=
datetime
.
now
()
#
db.session.commit()
db
.
session
.
commit
()
# return True, ResponseCode.HTTP_SUCCESS
return
(
True
,
None
)
#
elif result and result.is_delete == False:
elif
result
and
result
.
is_delete
==
False
:
# return False, ResponseCode.HTTP_INVAILD_REQUEST
return
(
False
,
"record code exists"
)
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
()
)
result
=
PackageModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
# handle business
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
uuid
==
uuid
)
.
first
()
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
if
params
:
if
params
:
for
key
,
value
in
params
.
items
():
for
key
,
value
in
params
.
items
():
...
@@ -154,21 +53,21 @@ class PackageResource(object):
...
@@ -154,21 +53,21 @@ class PackageResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
# handle business
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
uuid
==
uuid
)
.
first
()
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
packageManager
=
PackageResource
()
packageManager
=
PackageResource
()
\ No newline at end of file
tools/build_out/controllers/user.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
datetime
import
datetime
from
datetime
import
datetime
from
application.app
import
db
from
application.app
import
db
from
models.user
import
UserModel
from
models.user
import
UserModel
from
webcreator.log
import
logger
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
# from webcreator.response import ResponseCode, response_result
class
UserResource
(
object
):
class
UserResource
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -16,8 +13,8 @@ class UserResource(object):
...
@@ -16,8 +13,8 @@ class UserResource(object):
filters
=
[
UserModel
.
is_delete
==
False
,
UserModel
.
uuid
==
uuid
]
filters
=
[
UserModel
.
is_delete
==
False
,
UserModel
.
uuid
==
uuid
]
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
first
()
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
result
)
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
result
)
def
getList
(
self
,
params
):
def
getList
(
self
,
params
):
# handle business
# handle business
...
@@ -25,37 +22,30 @@ class UserResource(object):
...
@@ -25,37 +22,30 @@ class UserResource(object):
filters
=
[
UserModel
.
is_delete
==
False
]
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
)
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
(
True
,
result
.
items
,
result
.
total
)
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
def
post
(
self
,
params
,
jwt
=
{}):
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
# handle business
result
=
UserModel
.
query
.
filter
(
UserModel
.
a
ccount
==
params
.
get
(
'account
'
))
.
first
()
result
=
UserModel
.
query
.
filter
(
UserModel
.
a
pp_name
==
params
.
get
(
'app_name
'
))
.
first
()
if
result
and
result
.
is_delete
:
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
elif
result
and
result
.
is_delete
==
False
:
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
USER_EXISTS
return
(
False
,
"record code exists"
)
# 密码使用md5加密,可以使用元编程模式劫持,不用手动一个个修改了
# params.update({ "password": utils.md5_encryption(params.get("password")) })
result
=
UserModel
(
**
params
)
result
=
UserModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
logger
.
info
(
uuid
)
logger
.
info
(
params
)
# handle business
# handle business
result
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
uuid
)
.
first
()
result
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
if
params
:
if
params
:
for
key
,
value
in
params
.
items
():
for
key
,
value
in
params
.
items
():
...
@@ -63,21 +53,21 @@ class UserResource(object):
...
@@ -63,21 +53,21 @@ class UserResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
# handle business
result
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
uuid
)
.
first
()
result
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
userManager
=
UserResource
()
userManager
=
UserResource
()
\ No newline at end of file
tools/build_out/logs/running.log
View file @
a36af83d
This source diff could not be displayed because it is too large. You can
view the blob
instead.
tools/build_out/manager.py
View file @
a36af83d
'''
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 -*-
# -*- coding: utf-8 -*-
from
tornado.wsgi
import
WSGIContainer
from
tornado.wsgi
import
WSGIContainer
from
tornado.httpserver
import
HTTPServer
from
tornado.httpserver
import
HTTPServer
...
...
tools/build_out/models/app.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
.base
import
PrimaryModel
...
@@ -11,20 +10,20 @@ class AppModel(PrimaryModel):
...
@@ -11,20 +10,20 @@ class AppModel(PrimaryModel):
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
app_icon
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
app_icon
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
category
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
category
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
category_2th
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
category_2th
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
developer
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
developer
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
download_url
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
,
default
=
''
)
download_url
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
app_file_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
app_file_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_screen_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
app_screen_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_arch
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
,
default
=
''
)
app_arch
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
app_review
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
,
default
=
''
)
app_review
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
)
# __table_args__ = (
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
# )
def
__init__
(
self
,
app_name
,
app_icon
,
app_version
,
category
=
0
,
category_2th
=
0
,
developer
=
0
,
download_url
=
''
,
app_file_size
=
0
,
app_screen_size
=
0
,
app_arch
=
''
,
app_review
=
''
):
def
__init__
(
self
,
app_name
,
app_icon
,
app_version
,
category
,
category_2th
,
developer
,
download_url
,
app_file_size
,
app_screen_size
,
app_arch
,
app_review
):
self
.
app_name
=
app_name
self
.
app_name
=
app_name
self
.
app_icon
=
app_icon
self
.
app_icon
=
app_icon
self
.
app_version
=
app_version
self
.
app_version
=
app_version
...
@@ -40,7 +39,7 @@ class AppModel(PrimaryModel):
...
@@ -40,7 +39,7 @@ class AppModel(PrimaryModel):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'<AppModel
%
r>'
%
(
self
.
app_name
)
return
'<AppModel
%
r>'
%
(
self
.
app_name
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
return
{
'app_name'
:
self
.
app_name
,
'app_name'
:
self
.
app_name
,
'app_icon'
:
self
.
app_icon
,
'app_icon'
:
self
.
app_icon
,
...
...
tools/build_out/models/area.py
View file @
a36af83d
...
@@ -31,7 +31,7 @@ class AreaModel(PrimaryModel):
...
@@ -31,7 +31,7 @@ class AreaModel(PrimaryModel):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'<AreaModel
%
r>'
%
(
self
.
areaCode
)
return
'<AreaModel
%
r>'
%
(
self
.
areaCode
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
return
{
'areaCode'
:
self
.
areaCode
,
'areaCode'
:
self
.
areaCode
,
'areaName'
:
self
.
areaName
,
'areaName'
:
self
.
areaName
,
...
...
tools/build_out/models/base.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf_8 -*-
import
uuid
import
uuid
from
datetime
import
datetime
from
datetime
import
datetime
...
...
tools/build_out/models/login.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf_8 -*-
import
json
from
application.app
import
db
,
ma
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
from
webcreator.log
import
logger
class
LoginModel
(
PrimaryModel
):
class
LoginModel
(
PrimaryModel
):
__tablename__
=
'evm_login'
__tablename__
=
'evm_login'
...
@@ -29,19 +26,10 @@ class LoginModel(PrimaryModel):
...
@@ -29,19 +26,10 @@ class LoginModel(PrimaryModel):
self
.
geo_location
=
geo_location
self
.
geo_location
=
geo_location
self
.
operator
=
operator
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
):
def
__repr__
(
self
):
return
'<LoginModel
%
r>'
%
(
self
.
user
)
return
'<LoginModel
%
r>'
%
(
self
.
user
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
return
{
'login_at'
:
self
.
login_at
,
'login_at'
:
self
.
login_at
,
'user_agent'
:
self
.
user_agent
,
'user_agent'
:
self
.
user_agent
,
...
@@ -70,12 +58,12 @@ class GetListLoginSchema(ma.SQLAlchemySchema):
...
@@ -70,12 +58,12 @@ class GetListLoginSchema(ma.SQLAlchemySchema):
page
=
fields
.
Integer
(
required
=
False
)
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
user
=
fields
.
Integer
(
required
=
False
)
user
=
ma
.
auto_field
(
)
login_at
=
fields
.
String
(
required
=
False
)
login_at
=
ma
.
auto_field
(
)
user_agent
=
fields
.
String
(
required
=
False
)
user_agent
=
ma
.
auto_field
(
)
ip
=
fields
.
String
(
required
=
False
)
ip
=
ma
.
auto_field
(
)
geo_location
=
fields
.
String
(
required
=
False
)
geo_location
=
ma
.
auto_field
(
)
operator
=
fields
.
String
(
required
=
False
)
operator
=
ma
.
auto_field
(
)
getListLoginSchema
=
GetListLoginSchema
()
getListLoginSchema
=
GetListLoginSchema
()
getListLoginsSchema
=
GetListLoginSchema
(
many
=
True
)
getListLoginsSchema
=
GetListLoginSchema
(
many
=
True
)
...
@@ -86,11 +74,11 @@ class GetLoginSchema(ma.SQLAlchemySchema):
...
@@ -86,11 +74,11 @@ class GetLoginSchema(ma.SQLAlchemySchema):
unknown
=
EXCLUDE
# 未知字段默认排除
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
LoginModel
model
=
LoginModel
user
=
fields
.
Integer
(
required
=
False
)
user
=
ma
.
auto_field
(
)
login_at
=
fields
.
String
(
required
=
False
)
login_at
=
ma
.
auto_field
(
)
user_agent
=
fields
.
String
(
required
=
False
)
user_agent
=
ma
.
auto_field
(
)
ip
=
fields
.
String
(
required
=
False
)
ip
=
ma
.
auto_field
(
)
geo_location
=
fields
.
String
(
required
=
False
)
geo_location
=
ma
.
auto_field
(
)
operator
=
fields
.
String
(
required
=
False
)
operator
=
ma
.
auto_field
(
)
getLoginSchema
=
GetLoginSchema
()
getLoginSchema
=
GetLoginSchema
()
tools/build_out/models/package.py
View file @
a36af83d
'''
# -*- coding: utf-8 -*-
Author: your name
Date: 2021-06-30 18:03:41
LastEditTime: 2021-07-12 01:59:31
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\b
uild_out
\
models
\
package.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
.base
import
PrimaryModel
...
@@ -31,7 +22,7 @@ class PackageModel(PrimaryModel):
...
@@ -31,7 +22,7 @@ class PackageModel(PrimaryModel):
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
# )
def
__init__
(
self
,
app
,
app_version
,
package_info
,
file_path
,
source
=
""
,
user_agent
=
""
,
download_url
=
""
,
ip
=
""
,
geo_location
=
""
,
operator
=
""
,
create_by
=
None
,
create_at
=
None
,
update_by
=
None
,
update_at
=
None
):
def
__init__
(
self
,
app
,
app_version
,
package_info
,
file_path
,
source
,
user_agent
,
download_url
,
ip
,
geo_location
,
operator
):
self
.
app
=
app
self
.
app
=
app
self
.
app_version
=
app_version
self
.
app_version
=
app_version
self
.
package_info
=
package_info
self
.
package_info
=
package_info
...
@@ -42,15 +33,11 @@ class PackageModel(PrimaryModel):
...
@@ -42,15 +33,11 @@ class PackageModel(PrimaryModel):
self
.
ip
=
ip
self
.
ip
=
ip
self
.
geo_location
=
geo_location
self
.
geo_location
=
geo_location
self
.
operator
=
operator
self
.
operator
=
operator
self
.
create_by
=
create_by
self
.
create_at
=
create_at
self
.
update_by
=
update_by
self
.
update_at
=
update_at
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'<PackageModel
%
r>'
%
(
self
.
app
)
return
'<PackageModel
%
r>'
%
(
self
.
app
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
return
{
'app_version'
:
self
.
app_version
,
'app_version'
:
self
.
app_version
,
'package_info'
:
self
.
package_info
,
'package_info'
:
self
.
package_info
,
...
...
tools/build_out/models/user.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf_8 -*-
from
application.app
import
db
,
ma
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
from
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
from
webcreator
import
utils
from
webcreator.log
import
logger
class
UserModel
(
PrimaryModel
):
class
UserModel
(
PrimaryModel
):
__tablename__
=
'evm_user'
__tablename__
=
'evm_user'
username
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
account
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
app_icon
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
password
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
role
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
category
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
email
=
db
.
Column
(
db
.
String
,
nullable
=
False
,
default
=
''
)
category_2th
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
phone
=
db
.
Column
(
db
.
String
,
nullable
=
False
,
default
=
''
)
developer
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
download_url
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
app_file_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_screen_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_arch
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
app_review
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
)
# __table_args__ = (
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
# )
def
__init__
(
self
,
username
,
account
,
password
,
role
=
0
,
email
=
''
,
phone
=
''
):
def
__init__
(
self
,
app_name
,
app_icon
,
app_version
,
category
,
category_2th
,
developer
,
download_url
,
app_file_size
,
app_screen_size
,
app_arch
,
app_review
):
self
.
username
=
username
self
.
app_name
=
app_name
self
.
account
=
account
self
.
app_icon
=
app_icon
self
.
password
=
password
self
.
app_version
=
app_version
self
.
role
=
role
self
.
category
=
category
self
.
email
=
email
self
.
category_2th
=
category_2th
self
.
phone
=
phone
self
.
developer
=
developer
self
.
download_url
=
download_url
def
__setattr__
(
self
,
key
,
value
):
self
.
app_file_size
=
app_file_size
# logger.info(f"execute __setattr__:key={key}, value={value}")
self
.
app_screen_size
=
app_screen_size
if
key
==
'password'
:
self
.
app_arch
=
app_arch
self
.
__dict__
[
key
]
=
utils
.
md5_encryption
(
value
)
self
.
app_review
=
app_review
else
:
self
.
__dict__
[
key
]
=
value
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'<UserModel
%
r>'
%
(
self
.
user
name
)
return
'<UserModel
%
r>'
%
(
self
.
app_
name
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
return
{
'username'
:
self
.
username
,
'app_name'
:
self
.
app_name
,
'account'
:
self
.
account
,
'app_icon'
:
self
.
app_icon
,
'password'
:
self
.
password
,
'app_version'
:
self
.
app_version
,
'role'
:
self
.
role
,
'category'
:
self
.
category
,
'email'
:
self
.
email
,
'category_2th'
:
self
.
category_2th
,
'phone'
:
self
.
phone
,
'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
,
'app_review'
:
self
.
app_review
,
}
}
...
@@ -56,9 +61,15 @@ class PostUserSchema(ma.SQLAlchemySchema):
...
@@ -56,9 +61,15 @@ class PostUserSchema(ma.SQLAlchemySchema):
unknown
=
EXCLUDE
# 未知字段默认排除
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
model
=
UserModel
username
=
ma
.
auto_field
()
app_name
=
ma
.
auto_field
()
account
=
ma
.
auto_field
()
app_icon
=
ma
.
auto_field
()
password
=
ma
.
auto_field
()
app_version
=
ma
.
auto_field
()
category
=
ma
.
auto_field
()
category_2th
=
ma
.
auto_field
()
developer
=
ma
.
auto_field
()
app_screen_size
=
ma
.
auto_field
()
app_arch
=
ma
.
auto_field
()
app_review
=
ma
.
auto_field
()
postUserSchema
=
PostUserSchema
()
postUserSchema
=
PostUserSchema
()
...
@@ -77,9 +88,13 @@ class GetListUserSchema(ma.SQLAlchemySchema):
...
@@ -77,9 +88,13 @@ class GetListUserSchema(ma.SQLAlchemySchema):
unknown
=
EXCLUDE
# 未知字段默认排除
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
model
=
UserModel
uuid
=
ma
.
auto_field
()
page
=
fields
.
Integer
(
required
=
False
)
username
=
ma
.
auto_field
()
pageSize
=
fields
.
Integer
(
required
=
False
)
account
=
ma
.
auto_field
()
app_name
=
ma
.
auto_field
()
app_version
=
ma
.
auto_field
()
category
=
ma
.
auto_field
()
category_2th
=
ma
.
auto_field
()
app_arch
=
ma
.
auto_field
()
getListUserSchema
=
GetListUserSchema
()
getListUserSchema
=
GetListUserSchema
()
getListUsersSchema
=
GetListUserSchema
(
many
=
True
)
getListUsersSchema
=
GetListUserSchema
(
many
=
True
)
...
@@ -90,8 +105,11 @@ class GetUserSchema(ma.SQLAlchemySchema):
...
@@ -90,8 +105,11 @@ class GetUserSchema(ma.SQLAlchemySchema):
unknown
=
EXCLUDE
# 未知字段默认排除
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
model
=
UserModel
username
=
ma
.
auto_field
()
app_name
=
ma
.
auto_field
()
account
=
ma
.
auto_field
()
app_version
=
ma
.
auto_field
()
category
=
ma
.
auto_field
()
category_2th
=
ma
.
auto_field
()
app_arch
=
ma
.
auto_field
()
getUserSchema
=
GetUserSchema
()
getUserSchema
=
GetUserSchema
()
...
@@ -101,8 +119,13 @@ class PutUserSchema(ma.SQLAlchemySchema):
...
@@ -101,8 +119,13 @@ class PutUserSchema(ma.SQLAlchemySchema):
unknown
=
EXCLUDE
# 未知字段默认排除
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
model
=
UserModel
account
=
fields
.
String
(
required
=
False
,
allow_none
=
True
)
app_name
=
ma
.
auto_field
()
username
=
fields
.
String
(
required
=
False
,
allow_none
=
True
)
app_icon
=
ma
.
auto_field
()
password
=
fields
.
String
(
required
=
False
,
allow_none
=
True
)
app_version
=
ma
.
auto_field
()
app_screen_size
=
ma
.
auto_field
()
app_arch
=
ma
.
auto_field
()
app_review
=
ma
.
auto_field
()
category
=
ma
.
auto_field
()
category_2th
=
ma
.
auto_field
()
putUserSchema
=
PutUserSchema
()
putUserSchema
=
PutUserSchema
()
tools/build_out/views/__init__.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf_8 -*-
from
flask
import
Blueprint
from
flask
import
Blueprint
from
flask_restful
import
Api
from
flask_restful
import
Api
...
@@ -8,14 +7,6 @@ from . import app
...
@@ -8,14 +7,6 @@ from . import app
from
.
import
package
from
.
import
package
from
.
import
user
from
.
import
user
from
.
import
login
from
.
import
login
from
.
import
device
from
.
import
annex
from
.
import
file
from
.
import
monitorWatch
from
.
import
monitorSystem
from
.
import
monitorLvgl
from
.
import
monitorImage
from
.
import
monitorEvm
api_v1
=
Blueprint
(
'api_v1'
,
__name__
)
api_v1
=
Blueprint
(
'api_v1'
,
__name__
)
...
@@ -36,31 +27,3 @@ api.add_resource(user.UserResourceList, '/user')
...
@@ -36,31 +27,3 @@ api.add_resource(user.UserResourceList, '/user')
api
.
add_resource
(
login
.
LoginResource
,
'/login/<string:uuid>'
)
api
.
add_resource
(
login
.
LoginResource
,
'/login/<string:uuid>'
)
api
.
add_resource
(
login
.
LoginResourceList
,
'/login'
)
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
(
file
.
FileInit
,
"/file-manager/initialize"
)
api
.
add_resource
(
file
.
FileContent
,
"/file-manager/content"
)
api
.
add_resource
(
file
.
FileDisk
,
"/file-manager/disk"
)
api
.
add_resource
(
file
.
FileTree
,
"/file-manager/tree"
)
api
.
add_resource
(
file
.
FileDownload
,
"/file-manager/download"
)
api
.
add_resource
(
file
.
FilePrview
,
"/file-manager/preview"
)
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'
)
tools/build_out/views/app.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_restful.reqparse
import
RequestParser
...
@@ -26,29 +23,31 @@ class AppResourceList(Resource):
...
@@ -26,29 +23,31 @@ class AppResourceList(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
logger
.
warn
(
json_payload
)
data
=
getListAppSchema
.
load
(
json_payload
)
data
=
getListAppSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetListApp
.
emit
(
data
)
result
=
signalManager
.
actionGetListApp
.
emit
(
data
)
json_dumps
=
getListAppSchema
.
dump
(
result
)
json_dumps
=
getListAppSchema
.
dump
(
result
)
if
result
:
if
result
[
0
]
:
json_dumps
=
getListAppsSchema
.
dump
(
result
.
items
)
json_dumps
=
getListAppsSchema
.
dump
(
result
[
1
]
)
logger
.
warn
(
json_dumps
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
]
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
@
jwt_required
(
locations
=
[
"headers"
])
def
post
(
self
):
def
post
(
self
):
try
:
try
:
json_payload
=
request
.
json
json_payload
=
request
.
json
data
=
postAppSchema
.
load
(
json_payload
)
data
=
postAppSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPostApp
.
emit
(
data
)
result
=
signalManager
.
actionPostApp
.
emit
(
data
)
logger
.
info
(
result
)
if
result
[
0
]
==
False
:
logger
.
warn
(
message
)
# json_dumps = postAppSchema.dump(result)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
logger
.
warn
(
result
)
return
response_result
(
ResponseCode
.
OK
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
class
AppResource
(
Resource
):
class
AppResource
(
Resource
):
...
@@ -68,14 +67,14 @@ class AppResource(Resource):
...
@@ -68,14 +67,14 @@ class AppResource(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getAppSchema
.
load
(
json_payload
)
data
=
getAppSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetApp
.
emit
(
uuid
,
data
)
result
=
signalManager
.
actionGetApp
.
emit
(
uuid
,
data
)
if
result
:
if
result
[
0
]
:
json_dumps
=
getAppSchema
.
dump
(
result
)
json_dumps
=
getAppSchema
.
dump
(
result
[
1
]
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
@
jwt_required
(
locations
=
[
"headers"
])
...
@@ -84,13 +83,14 @@ class AppResource(Resource):
...
@@ -84,13 +83,14 @@ class AppResource(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
print
(
"========>"
,
uuid
,
json_payload
)
data
=
putAppSchema
.
load
(
json_payload
)
data
=
putAppSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPutApp
.
emit
(
uuid
,
data
)
result
=
signalManager
.
actionPutApp
.
emit
(
uuid
,
data
)
logger
.
info
(
result
)
if
result
[
0
]
==
True
:
logger
.
info
(
message
)
# json_dumps = putAppSchema.dump(result)
return
response_result
(
message
,
data
=
result
)
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
NOTHING_CHANGE
,
msg
=
result
[
1
])
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
@
jwt_required
(
locations
=
[
"headers"
])
...
@@ -99,8 +99,10 @@ class AppResource(Resource):
...
@@ -99,8 +99,10 @@ class AppResource(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
print
(
"========>"
,
uuid
,
json_payload
)
# data = deleteAppSchema.load(json_payload)
# data = deleteAppSchema.load(json_payload)
result
,
message
=
signalManager
.
actionDeleteApp
.
emit
(
uuid
)
result
=
signalManager
.
actionDeleteApp
.
emit
(
uuid
)
return
response_result
(
message
,
data
=
result
)
if
result
[
0
]
==
True
:
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
tools/build_out/views/area.py
View file @
a36af83d
...
@@ -28,11 +28,11 @@ class AreaResourceList(Resource):
...
@@ -28,11 +28,11 @@ class AreaResourceList(Resource):
if
result
[
0
]:
if
result
[
0
]:
json_dumps
=
getListAreasSchema
.
dump
(
result
[
1
])
json_dumps
=
getListAreasSchema
.
dump
(
result
[
1
])
logger
.
warn
(
json_dumps
)
logger
.
warn
(
json_dumps
)
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
json_dumps
,
count
=
result
[
2
])
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
])
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
@
jwt_required
(
locations
=
[
"headers"
])
def
post
(
self
):
def
post
(
self
):
...
@@ -42,12 +42,12 @@ class AreaResourceList(Resource):
...
@@ -42,12 +42,12 @@ class AreaResourceList(Resource):
result
=
signalManager
.
actionPostArea
.
emit
(
data
)
result
=
signalManager
.
actionPostArea
.
emit
(
data
)
if
result
[
0
]
==
False
:
if
result
[
0
]
==
False
:
# json_dumps = postAreaSchema.dump(result)
# json_dumps = postAreaSchema.dump(result)
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
msg
=
result
[
1
])
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
logger
.
warn
(
result
)
logger
.
warn
(
result
)
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
)
return
response_result
(
ResponseCode
.
OK
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
class
AreaResource
(
Resource
):
class
AreaResource
(
Resource
):
...
@@ -70,11 +70,11 @@ class AreaResource(Resource):
...
@@ -70,11 +70,11 @@ class AreaResource(Resource):
result
=
signalManager
.
actionGetArea
.
emit
(
uuid
,
data
)
result
=
signalManager
.
actionGetArea
.
emit
(
uuid
,
data
)
if
result
[
0
]:
if
result
[
0
]:
json_dumps
=
getAreaSchema
.
dump
(
result
[
1
])
json_dumps
=
getAreaSchema
.
dump
(
result
[
1
])
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
HTTP_NOT_FOUND
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
@
jwt_required
(
locations
=
[
"headers"
])
...
@@ -86,11 +86,11 @@ class AreaResource(Resource):
...
@@ -86,11 +86,11 @@ class AreaResource(Resource):
result
=
signalManager
.
actionPutArea
.
emit
(
uuid
,
data
)
result
=
signalManager
.
actionPutArea
.
emit
(
uuid
,
data
)
if
result
[
0
]
==
True
:
if
result
[
0
]
==
True
:
# json_dumps = putAreaSchema.dump(result)
# json_dumps = putAreaSchema.dump(result)
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
)
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
NOTHING_CHANGE
,
msg
=
result
[
1
])
return
response_result
(
ResponseCode
.
NOTHING_CHANGE
,
msg
=
result
[
1
])
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
@
jwt_required
(
locations
=
[
"headers"
])
...
@@ -101,8 +101,8 @@ class AreaResource(Resource):
...
@@ -101,8 +101,8 @@ class AreaResource(Resource):
# data = deleteAreaSchema.load(json_payload)
# data = deleteAreaSchema.load(json_payload)
result
=
signalManager
.
actionDeleteArea
.
emit
(
uuid
)
result
=
signalManager
.
actionDeleteArea
.
emit
(
uuid
)
if
result
[
0
]
==
True
:
if
result
[
0
]
==
True
:
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
)
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
msg
=
result
[
1
])
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
tools/build_out/views/login.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
marshmallow.exceptions
import
ValidationError
from
application.signal_manager
import
signalManager
from
application.signal_manager
import
signalManager
from
models.login
import
postLoginSchema
,
getListLoginSchema
,
getListLoginsSchema
,
getLoginSchema
from
models.login
import
postLoginSchema
,
getListLoginSchema
,
getListLoginsSchema
,
getLoginSchema
from
webcreator.log
import
logger
from
webcreator.log
import
logger
...
@@ -27,37 +23,30 @@ class LoginResourceList(Resource):
...
@@ -27,37 +23,30 @@ class LoginResourceList(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
logger
.
warn
(
json_payload
)
data
=
getListLoginSchema
.
load
(
json_payload
)
data
=
getListLoginSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetListLogin
.
emit
(
data
)
result
=
signalManager
.
actionGetListLogin
.
emit
(
data
)
json_dumps
=
getListLoginSchema
.
dump
(
result
)
json_dumps
=
getListLoginSchema
.
dump
(
result
)
if
result
:
if
result
[
0
]:
json_dumps
=
getListLoginsSchema
.
dump
(
result
.
items
)
json_dumps
=
getListLoginsSchema
.
dump
(
result
[
1
])
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
])
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
except
Exception
as
e
:
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
return
response_result
(
ResponseCode
.
DB_ERROR
)
def
post
(
self
):
def
post
(
self
):
try
:
try
:
json_payload
=
request
.
json
json_payload
=
request
.
json
data
=
postLoginSchema
.
load
(
json_payload
)
data
=
postLoginSchema
.
load
(
json_payload
)
# 更新data,插入ip信息,如果没有转发ip,那么则获取请求ip
result
=
signalManager
.
actionPostLogin
.
emit
(
data
)
data
.
update
({
"ip"
:
request
.
headers
.
get
(
'X-Forwarded-For'
,
request
.
remote_addr
),
"user_agent"
:
request
.
headers
.
get
(
'User-Agent'
,
""
)
})
if
result
[
0
]
==
False
:
result
,
message
=
signalManager
.
actionPostLogin
.
emit
(
data
)
# json_dumps = postLoginSchema.dump(result
)
return
response_result
(
message
,
data
=
result
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
]
)
except
ValidationError
as
e
:
logger
.
warn
(
result
)
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
return
response_result
(
ResponseCode
.
OK
)
except
Exception
as
e
:
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
return
response_result
(
ResponseCode
.
DB_ERROR
)
class
LoginResource
(
Resource
):
class
LoginResource
(
Resource
):
...
@@ -77,11 +66,11 @@ class LoginResource(Resource):
...
@@ -77,11 +66,11 @@ class LoginResource(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getLoginSchema
.
load
(
json_payload
)
data
=
getLoginSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetLogin
.
emit
(
uuid
,
data
)
result
=
signalManager
.
actionGetLogin
.
emit
(
uuid
,
data
)
if
result
:
if
result
[
0
]
:
json_dumps
=
getLoginSchema
.
dump
(
result
)
json_dumps
=
getLoginSchema
.
dump
(
result
[
1
]
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
tools/build_out/views/package.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_restful.reqparse
import
RequestParser
...
@@ -26,16 +23,16 @@ class PackageResourceList(Resource):
...
@@ -26,16 +23,16 @@ class PackageResourceList(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
logger
.
warn
(
json_payload
)
data
=
getListPackageSchema
.
load
(
json_payload
)
data
=
getListPackageSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetListPackage
.
emit
(
data
)
result
=
signalManager
.
actionGetListPackage
.
emit
(
data
)
json_dumps
=
getListPackageSchema
.
dump
(
result
)
json_dumps
=
getListPackageSchema
.
dump
(
result
)
if
result
:
if
result
[
0
]
:
json_dumps
=
getListPackagesSchema
.
dump
(
result
.
items
)
json_dumps
=
getListPackagesSchema
.
dump
(
result
[
1
]
)
logger
.
warn
(
json_dumps
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
]
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
class
PackageResource
(
Resource
):
class
PackageResource
(
Resource
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -54,11 +51,11 @@ class PackageResource(Resource):
...
@@ -54,11 +51,11 @@ class PackageResource(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getPackageSchema
.
load
(
json_payload
)
data
=
getPackageSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetPackage
.
emit
(
uuid
,
data
)
result
=
signalManager
.
actionGetPackage
.
emit
(
uuid
,
data
)
if
result
:
if
result
[
0
]
:
json_dumps
=
getPackageSchema
.
dump
(
result
)
json_dumps
=
getPackageSchema
.
dump
(
result
[
1
]
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
tools/build_out/views/user.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from
flask
import
current_app
,
jsonify
,
request
from
flask
import
current_app
,
jsonify
,
request
from
flask_restful
import
Resource
from
flask_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_restful.reqparse
import
RequestParser
...
@@ -26,28 +23,31 @@ class UserResourceList(Resource):
...
@@ -26,28 +23,31 @@ class UserResourceList(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
logger
.
warn
(
json_payload
)
data
=
getListUserSchema
.
load
(
json_payload
)
data
=
getListUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetListUser
.
emit
(
data
)
result
=
signalManager
.
actionGetListUser
.
emit
(
data
)
json_dumps
=
getListUserSchema
.
dump
(
result
)
json_dumps
=
getListUserSchema
.
dump
(
result
)
if
result
:
if
result
[
0
]
:
json_dumps
=
getListUsersSchema
.
dump
(
result
.
items
)
json_dumps
=
getListUsersSchema
.
dump
(
result
[
1
]
)
logger
.
warn
(
json_dumps
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
]
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
post
(
self
):
def
post
(
self
):
try
:
try
:
json_payload
=
request
.
json
json_payload
=
request
.
json
data
=
postUserSchema
.
load
(
json_payload
)
data
=
postUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPostUser
.
emit
(
data
)
result
=
signalManager
.
actionPostUser
.
emit
(
data
)
logger
.
info
(
result
)
if
result
[
0
]
==
False
:
logger
.
warn
(
message
)
# json_dumps = postUserSchema.dump(result)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
logger
.
warn
(
result
)
return
response_result
(
ResponseCode
.
OK
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
class
UserResource
(
Resource
):
class
UserResource
(
Resource
):
...
@@ -67,26 +67,30 @@ class UserResource(Resource):
...
@@ -67,26 +67,30 @@ class UserResource(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getUserSchema
.
load
(
json_payload
)
data
=
getUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetUser
.
emit
(
uuid
,
data
)
result
=
signalManager
.
actionGetUser
.
emit
(
uuid
,
data
)
if
result
:
if
result
[
0
]
:
json_dumps
=
getUserSchema
.
dump
(
result
)
json_dumps
=
getUserSchema
.
dump
(
result
[
1
]
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
@
jwt_required
(
locations
=
[
"headers"
])
def
put
(
self
,
uuid
):
def
put
(
self
,
uuid
):
try
:
try
:
json_payload
=
request
.
json
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
putUserSchema
.
load
(
json_payload
)
data
=
putUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPutUser
.
emit
(
uuid
,
data
)
result
=
signalManager
.
actionPutUser
.
emit
(
uuid
,
data
)
return
response_result
(
message
,
data
=
result
)
if
result
[
0
]
==
True
:
# json_dumps = putUserSchema.dump(result)
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
NOTHING_CHANGE
,
msg
=
result
[
1
])
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
@
jwt_required
(
locations
=
[
"headers"
])
...
@@ -95,8 +99,10 @@ class UserResource(Resource):
...
@@ -95,8 +99,10 @@ class UserResource(Resource):
json_payload
=
request
.
json
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
print
(
"========>"
,
uuid
,
json_payload
)
# data = deleteUserSchema.load(json_payload)
# data = deleteUserSchema.load(json_payload)
result
,
message
=
signalManager
.
actionDeleteUser
.
emit
(
uuid
)
result
=
signalManager
.
actionDeleteUser
.
emit
(
uuid
)
return
response_result
(
message
,
data
=
result
)
if
result
[
0
]
==
True
:
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
except
Exception
as
e
:
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
tools/build_out/webcreator/event.py
View file @
a36af83d
'''
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 -*-
# -*- coding: utf_8 -*-
############################
# 信号槽
############################
class
PySignal
(
object
):
class
PySignal
(
object
):
"""
"""
Simple event class used to provide hooks for different types of events in Locust.
Simple event class used to provide hooks for different types of events in Locust.
...
@@ -33,7 +45,7 @@ class PySignal(object):
...
@@ -33,7 +45,7 @@ class PySignal(object):
return
self
return
self
def
fire
(
self
,
*
args
,
**
kwargs
):
def
fire
(
self
,
*
args
,
**
kwargs
):
return
self
.
emit
(
*
args
,
**
kwargs
)
return
self
.
emit
(
*
args
,
**
kwargs
)
def
emit
(
self
,
*
args
,
**
kwargs
):
def
emit
(
self
,
*
args
,
**
kwargs
):
...
...
tools/build_out/webcreator/log.py
View file @
a36af83d
'''
Author: your name
Date: 2021-04-22 18:04:15
LastEditTime: 2021-07-09 00:52:08
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\t
ools
\r
esources
\
webcreator
\
log.py
'''
# -*- coding: utf_8 -*-
# -*- coding: utf_8 -*-
############################
# Log
# 日志
############################
import
os
import
os
import
logging
import
logging
from
logging.handlers
import
RotatingFileHandler
from
logging.handlers
import
RotatingFileHandler
...
@@ -21,4 +34,4 @@ ch.setFormatter(formatter)
...
@@ -21,4 +34,4 @@ ch.setFormatter(formatter)
logger
=
logging
.
root
logger
=
logging
.
root
logger
.
setLevel
(
logging
.
DEBUG
)
logger
.
setLevel
(
logging
.
DEBUG
)
logger
.
addHandler
(
fh
)
logger
.
addHandler
(
fh
)
logger
.
addHandler
(
ch
)
logger
.
addHandler
(
ch
)
\ No newline at end of file
tools/build_out/webcreator/response.py
View file @
a36af83d
# -*- coding: utf_8 -*-
# -*- coding: utf_8 -*-
'''
############################
请求方法:
# Response
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
):
class
ResponseCode
(
object
):
# 通用状态码
OK
=
(
200
,
'ok'
)
HTTP_SUCCESS
=
(
200
,
"success"
)
NO_DATA
=
(
204
,
'no data'
)
HTTP_NO_DATA
=
(
204
,
"no data"
)
NOT_FOUND
=
(
404
,
'not found'
)
HTTP_NO_CHANGE
=
(
304
,
'nothing change'
)
NOTHING_CHANGE
=
(
304
,
'nothing change'
)
HTTP_AUTH_FAIL
=
(
401
,
'authentication failed'
)
REQUEST_ERROR
=
(
400
,
'request error'
)
HTTP_INVAILD_REQUEST
=
(
403
,
'invaild request'
)
AUTHORIZATION_ERROR
=
(
401
,
'authentication error'
)
HTTP_NOT_FOUND
=
(
404
,
"not found"
)
INVAILD_REQUEST
=
(
403
,
'invaild request'
)
HTTP_SERVER_ERROR
=
(
500
,
"server error"
)
PARAMETER_ERROR
=
(
4001
,
'parameter error'
)
PARAMETER_NULL
=
(
4002
,
'parameter is null'
)
PASSWORD_ERROR
=
(
4003
,
'password error'
)
# 用户模块
EXISTS_ERROR
=
(
4004
,
'record exists'
)
USER_NOT_EXISTS
=
(
1010001
,
'user not exists'
)
INVAILD_ROLE_ERROR
=
(
4005
,
'invaild role error'
)
USER_EXISTS
=
(
1010002
,
'user already exists'
)
ACCOUNT_DISABLED
=
(
4006
,
'account is disabled'
)
USER_PASSWORD_ERROR
=
(
1010003
,
'password error'
)
SERVER_ERROR
=
(
500
,
'server error'
)
DB_ERROR
=
(
5001
,
'database error'
)
UNKNOWN_ERROR
=
(
5003
,
'unknown error'
)
def
response_result
(
response
,
msg
=
None
,
data
=
None
,
**
kwargs
):
c
,
m
=
response
def
response_result
(
code
,
msg
=
None
,
data
=
None
,
**
kwargs
):
if
msg
==
None
:
if
msg
is
None
:
msg
=
m
msg
=
code
[
1
]
result
=
{
'code'
:
code
[
0
],
'msg'
:
msg
,
'data'
:
data
}
result
=
{
'code'
:
c
,
'msg'
:
msg
,
'data'
:
data
}
result
.
update
(
kwargs
)
result
.
update
(
kwargs
)
return
result
return
result
\ No newline at end of file
tools/build_out/webcreator/utils/__init__.py
View file @
a36af83d
...
@@ -13,154 +13,6 @@ from typing import (
...
@@ -13,154 +13,6 @@ from typing import (
Sequence
,
Sequence
,
)
)
#!/usr/bin/env python
# -*- coding: utf_8 -*-
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
)
print
(
"=====>"
,
jsonData
)
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
:
class
Klass
:
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
...
@@ -185,7 +37,4 @@ class ObjectDict(Dict[str, Any]):
...
@@ -185,7 +37,4 @@ class ObjectDict(Dict[str, Any]):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
d
=
{
'a'
:
1
,
'b'
:
2
}
d
=
{
'a'
:
1
,
'b'
:
2
}
print
(
dict2obj
(
d
))
print
(
dict2obj
(
d
))
\ No newline at end of file
print
(
os
.
path
.
abspath
(
__file__
))
print
(
random_string
(
7
))
tools/resources/webcreator/utils/__init__.py
View file @
a36af83d
...
@@ -13,136 +13,6 @@ from typing import (
...
@@ -13,136 +13,6 @@ from typing import (
Sequence
,
Sequence
,
)
)
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import
shutil
import
time
import
re
import
os
import
json
import
functools
import
hashlib
import
random
import
string
import
datetime
import
threading
import
decimal
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_salt
(
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
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
:
class
Klass
:
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
...
@@ -167,7 +37,4 @@ class ObjectDict(Dict[str, Any]):
...
@@ -167,7 +37,4 @@ class ObjectDict(Dict[str, Any]):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
d
=
{
'a'
:
1
,
'b'
:
2
}
d
=
{
'a'
:
1
,
'b'
:
2
}
print
(
dict2obj
(
d
))
print
(
dict2obj
(
d
))
\ No newline at end of file
print
(
os
.
path
.
abspath
(
__file__
))
print
(
random_string
(
7
))
\ No newline at end of file
tools/resources/webcreator/utils/ccode.py
0 → 100644
View file @
a36af83d
'''
Author: your name
Date: 2021-04-29 12:12:01
LastEditTime: 2021-07-12 00:56:10
LastEditors: your name
Description: In User Settings Edit
FilePath:
\
evm-store
\b
ackend
\
utils
\
ccode.py
'''
# -*- 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/resources/webcreator/utils/epk.py
0 → 100644
View file @
a36af83d
#-*- 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/resources/webcreator/utils/epk_2.0.py
0 → 100644
View file @
a36af83d
#-*- 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/resources/webcreator/utils/lib/eheatshrink.dll
0 → 100644
View file @
a36af83d
File added
tools/resources/webcreator/utils/lib/libeheatshrink.so
0 → 100644
View file @
a36af83d
File added
tools/resources/webcreator/utils/tools_epk_1.0.py
0 → 100644
View file @
a36af83d
#-*- 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
])
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