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
Show 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数据库迁移框架可以保证数据库结构在发生变化时,改变数据库结构不至于丢失数据库的数据。
...
...
@@ -76,6 +68,4 @@ python manager.py db migrate
python manager.py db upgrade
```
详情参考:
+
https://zhuanlan.zhihu.com/p/307612189
+
https://file-manager.webmai.ru/
\ No newline at end of file
详情参考:https://zhuanlan.zhihu.com/p/307612189
\ 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
# -*- coding: utf_8 -*-
...
...
@@ -7,14 +15,7 @@ from .app import appManager
from
.package
import
packageManager
from
.user
import
userManager
from
.login
import
loginManager
from
.device
import
deviceManager
from
.annex
import
annexManager
from
.monitorWatch
import
monitorWatchManager
from
.monitorSystem
import
monitorSystemManager
from
.monitorLvgl
import
monitorLvglManager
from
.monitorImage
import
monitorImageManager
from
.monitorEvm
import
monitorEvmManager
from
.file
import
fileManager
from
.file_manager
import
fileManager
def
initConnect
():
signalManager
.
actionPostArea
.
connect
(
areaManager
.
post
)
...
...
@@ -37,28 +38,5 @@ def initConnect():
signalManager
.
actionPostLogin
.
connect
(
loginManager
.
post
)
signalManager
.
actionGetListLogin
.
connect
(
loginManager
.
getList
)
signalManager
.
actionGetLogin
.
connect
(
loginManager
.
get
)
signalManager
.
actionPostDevice
.
connect
(
deviceManager
.
post
)
signalManager
.
actionDeleteDevice
.
connect
(
deviceManager
.
delete
)
signalManager
.
actionGetListDevice
.
connect
(
deviceManager
.
getList
)
signalManager
.
actionGetDevice
.
connect
(
deviceManager
.
get
)
signalManager
.
actionPutDevice
.
connect
(
deviceManager
.
put
)
signalManager
.
actionDeleteAnnex
.
connect
(
annexManager
.
delete
)
signalManager
.
actionGetListAnnex
.
connect
(
annexManager
.
getList
)
signalManager
.
actionGetAnnex
.
connect
(
annexManager
.
get
)
signalManager
.
actionGetListMonitorWatch
.
connect
(
monitorWatchManager
.
getList
)
signalManager
.
actionGetMonitorWatch
.
connect
(
monitorWatchManager
.
get
)
signalManager
.
actionGetListMonitorSystem
.
connect
(
monitorSystemManager
.
getList
)
signalManager
.
actionGetMonitorSystem
.
connect
(
monitorSystemManager
.
get
)
signalManager
.
actionGetListMonitorLvgl
.
connect
(
monitorLvglManager
.
getList
)
signalManager
.
actionGetMonitorLvgl
.
connect
(
monitorLvglManager
.
get
)
signalManager
.
actionGetListMonitorImage
.
connect
(
monitorImageManager
.
getList
)
signalManager
.
actionGetMonitorImage
.
connect
(
monitorImageManager
.
get
)
signalManager
.
actionGetListMonitorEvm
.
connect
(
monitorEvmManager
.
getList
)
signalManager
.
actionGetMonitorEvm
.
connect
(
monitorEvmManager
.
get
)
# file manager api
signalManager
.
actionGetFileContent
.
connect
(
fileManager
.
content
)
signalManager
.
actionGetFileDisk
.
connect
(
fileManager
.
disk
)
signalManager
.
actionGetFileDown
.
connect
(
fileManager
.
download
)
signalManager
.
actionGetFileInit
.
connect
(
fileManager
.
initialize
)
signalManager
.
actionGetFilePreview
.
connect
(
fileManager
.
preview
)
signalManager
.
actionGetFileTree
.
connect
(
fileManager
.
tree
)
# signalManager.actionGEt
\ No newline at end of file
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
sqlalchemy
import
func
,
distinct
from
application.app
import
db
from
models.package
import
PackageModel
from
models.annex
import
AnnexModel
from
models.user
import
UserModel
from
models.app
import
AppModel
from
application.config
import
config
from
webcreator.utils.epk
import
EpkApp
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
# from webcreator.response import ResponseCode, response_result
class
AppResource
(
object
):
def
__init__
(
self
):
...
...
@@ -24,74 +11,10 @@ class AppResource(object):
def
get
(
self
,
uuid
,
params
):
# handle business
filters
=
[
AppModel
.
is_delete
==
False
,
AppModel
.
uuid
==
uuid
]
app
=
AppModel
.
query
.
filter
(
*
filters
)
.
one_or_none
()
if
not
app
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
user
=
UserModel
.
query
.
filter
(
UserModel
.
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
result
=
AppModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
(
True
,
result
)
return
(
False
,
result
)
def
getList
(
self
,
params
):
# handle business
...
...
@@ -99,178 +22,52 @@ class AppResource(object):
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
)
if
not
result
:
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
return
(
True
,
result
.
items
,
result
.
total
)
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
# 应用打包
# 插入一条打包记录
user
=
UserModel
.
query
.
filter
(
UserModel
.
id
==
params
.
get
(
'user'
))
.
one_or_none
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
# 判断下app是否存在
# result = Apps.select(app_name=data.get("app_name"), is_delete=False).count()
# if result < 1:
# return False, "app_name has been exists."
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
()
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
,
None
)
elif
result
and
result
.
is_delete
==
False
:
return
(
False
,
"record code exists"
)
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
())
db
.
session
.
add
(
package
)
result
=
AppModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
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
return
(
True
,
None
)
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
app
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
uuid
)
.
first
()
if
not
app
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
result
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
(
False
,
"record not exists"
)
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
():
if
value
!=
None
:
setattr
(
app
,
key
,
value
)
app
.
update_by
=
jwt
.
get
(
"id"
,
""
)
app
.
update_date
=
datetime
.
now
()
if
value
!=
None
:
setattr
(
result
,
key
,
value
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
AppModel
.
query
.
filter
(
AppModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
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
application.app
import
db
from
models.area
import
AreaModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
# from webcreator.response import ResponseCode, response_result
class
AreaResource
(
object
):
def
__init__
(
self
):
...
...
@@ -21,8 +13,8 @@ class AreaResource(object):
filters
=
[
AreaModel
.
is_delete
==
False
,
AreaModel
.
uuid
==
uuid
]
result
=
AreaModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
result
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
True
,
result
)
return
(
False
,
result
)
def
getList
(
self
,
params
):
# handle business
...
...
@@ -30,9 +22,7 @@ class AreaResource(object):
filters
=
[
AreaModel
.
is_delete
==
False
]
result
=
AreaModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AreaModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
True
,
result
.
items
,
result
.
total
)
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
...
...
@@ -42,9 +32,9 @@ class AreaResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"record code exists"
)
result
=
AreaModel
(
**
params
)
db
.
session
.
add
(
result
)
...
...
@@ -55,7 +45,7 @@ class AreaResource(object):
# handle business
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
if
params
:
for
key
,
value
in
params
.
items
():
...
...
@@ -63,21 +53,21 @@ class AreaResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
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
flask_jwt_extended
import
(
create_access_token
,)
from
application.app
import
db
from
models.login
import
LoginModel
from
models.user
import
UserModel
from
webcreator.log
import
logger
from
webcreator
import
utils
from
webcreator.response
import
ResponseCode
@
utils
.
ThreadMaker
def
update_login_information
(
ip
,
log_id
):
try
:
jsonData
=
utils
.
get_location_by_ip
(
ip
)
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
)
# from webcreator.response import ResponseCode, response_result
class
LoginResource
(
object
):
def
__init__
(
self
):
...
...
@@ -35,8 +13,8 @@ class LoginResource(object):
filters
=
[
LoginModel
.
is_delete
==
False
,
LoginModel
.
uuid
==
uuid
]
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
True
,
result
)
return
(
False
,
result
)
def
getList
(
self
,
params
):
# handle business
...
...
@@ -44,43 +22,30 @@ class LoginResource(object):
filters
=
[
LoginModel
.
is_delete
==
False
]
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
order_by
(
LoginModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
True
,
result
.
items
,
result
.
total
)
def
post
(
self
,
params
,
jwt
=
{}):
# handle business
user
=
UserModel
.
query
.
filter
(
UserModel
.
account
==
params
.
get
(
"account"
))
.
first
()
if
not
user
:
return
False
,
ResponseCode
.
USER_NOT_EXISTS
logger
.
info
(
params
)
if
user
.
password
!=
utils
.
md5_encryption
(
params
.
get
(
"password"
)):
return
False
,
ResponseCode
.
USER_PASSWORD_ERROR
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
user
==
params
.
get
(
'user'
))
.
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
,
None
)
elif
result
and
result
.
is_delete
==
False
:
return
(
False
,
"record code exists"
)
# 插入一条登录记录
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
=
""
result
=
LoginModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
# 获取当前登录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
return
(
True
,
None
)
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
if
params
:
for
key
,
value
in
params
.
items
():
...
...
@@ -88,21 +53,21 @@ class LoginResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
LoginModel
.
query
.
filter
(
LoginModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
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
application.app
import
db
,
config
from
models.annex
import
AnnexModel
from
models.app
import
AppModel
from
models.user
import
UserModel
from
application.app
import
db
from
models.package
import
PackageModel
from
webcreator.utils.epk
import
EpkApp
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
# from webcreator.response import ResponseCode, response_result
class
PackageResource
(
object
):
def
__init__
(
self
):
...
...
@@ -31,8 +13,8 @@ class PackageResource(object):
filters
=
[
PackageModel
.
is_delete
==
False
,
PackageModel
.
uuid
==
uuid
]
result
=
PackageModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
True
,
result
)
return
(
False
,
result
)
def
getList
(
self
,
params
):
# handle business
...
...
@@ -40,113 +22,30 @@ class PackageResource(object):
filters
=
[
PackageModel
.
is_delete
==
False
]
result
=
PackageModel
.
query
.
filter
(
*
filters
)
.
order_by
(
PackageModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
user
=
UserModel
.
query
.
filter
(
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
return
(
True
,
result
.
items
,
result
.
total
)
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
#
result = PackageModel.query.filter(PackageModel.app == params.get('app')).first()
#
if result and result.is_delete:
#
result.is_delete = False
#
result.update_by = jwt.get("id", "")
#
result.update_date = datetime.now()
#
db.session.commit()
# return True, ResponseCode.HTTP_SUCCESS
#
elif result and result.is_delete == False:
# return False, ResponseCode.HTTP_INVAILD_REQUEST
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
app
==
params
.
get
(
'app'
))
.
first
()
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
(
True
,
None
)
elif
result
and
result
.
is_delete
==
False
:
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
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
# handle business
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
if
params
:
for
key
,
value
in
params
.
items
():
...
...
@@ -154,21 +53,21 @@ class PackageResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
PackageModel
.
query
.
filter
(
PackageModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
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
application.app
import
db
from
models.user
import
UserModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
# from webcreator.response import ResponseCode, response_result
class
UserResource
(
object
):
def
__init__
(
self
):
...
...
@@ -16,8 +13,8 @@ class UserResource(object):
filters
=
[
UserModel
.
is_delete
==
False
,
UserModel
.
uuid
==
uuid
]
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
first
()
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
True
,
result
)
return
(
False
,
result
)
def
getList
(
self
,
params
):
# handle business
...
...
@@ -25,37 +22,30 @@ class UserResource(object):
filters
=
[
UserModel
.
is_delete
==
False
]
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
order_by
(
UserModel
.
create_at
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
if
result
:
return
result
,
ResponseCode
.
HTTP_SUCCESS
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
True
,
result
.
items
,
result
.
total
)
def
post
(
self
,
params
,
jwt
=
{}):
# 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
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
elif
result
and
result
.
is_delete
==
False
:
return
False
,
ResponseCode
.
USER_EXISTS
# 密码使用md5加密,可以使用元编程模式劫持,不用手动一个个修改了
# params.update({ "password": utils.md5_encryption(params.get("password")) })
return
(
False
,
"record code exists"
)
result
=
UserModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
def
put
(
self
,
uuid
,
params
,
jwt
=
{}):
logger
.
info
(
uuid
)
logger
.
info
(
params
)
# handle business
result
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
None
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
if
params
:
for
key
,
value
in
params
.
items
():
...
...
@@ -63,21 +53,21 @@ class UserResource(object):
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
else
:
return
False
,
ResponseCode
.
HTTP_INVAILD_REQUEST
return
(
False
,
"params is null"
)
def
delete
(
self
,
uuid
,
jwt
=
{}):
# handle business
result
=
UserModel
.
query
.
filter
(
UserModel
.
uuid
==
uuid
)
.
first
()
if
not
result
:
return
False
,
ResponseCode
.
HTTP_NOT_FOUND
return
(
False
,
"record not exists"
)
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
result
.
is_delete
=
True
db
.
session
.
delete
(
result
)
db
.
session
.
commit
()
return
True
,
ResponseCode
.
HTTP_SUCCESS
return
(
True
,
None
)
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 -*-
from
tornado.wsgi
import
WSGIContainer
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
.base
import
PrimaryModel
...
...
@@ -11,20 +10,20 @@ class AppModel(PrimaryModel):
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
app_icon
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
category
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
category_2th
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
developer
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
download_url
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
,
default
=
''
)
app_file_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
app_screen_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
app_arch
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
,
default
=
''
)
app_review
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
,
default
=
''
)
category
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
category_2th
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
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__ = (
# 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_icon
=
app_icon
self
.
app_version
=
app_version
...
...
@@ -40,7 +39,7 @@ class AppModel(PrimaryModel):
def
__repr__
(
self
):
return
'<AppModel
%
r>'
%
(
self
.
app_name
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
'app_name'
:
self
.
app_name
,
'app_icon'
:
self
.
app_icon
,
...
...
tools/build_out/models/area.py
View file @
a36af83d
...
...
@@ -31,7 +31,7 @@ class AreaModel(PrimaryModel):
def
__repr__
(
self
):
return
'<AreaModel
%
r>'
%
(
self
.
areaCode
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
'areaCode'
:
self
.
areaCode
,
'areaName'
:
self
.
areaName
,
...
...
tools/build_out/models/base.py
View file @
a36af83d
#!/usr/bin/env python
# -*- coding: utf_8 -*-
# -*- coding: utf-8 -*-
import
uuid
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
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
from
webcreator.log
import
logger
class
LoginModel
(
PrimaryModel
):
__tablename__
=
'evm_login'
...
...
@@ -29,19 +26,10 @@ class LoginModel(PrimaryModel):
self
.
geo_location
=
geo_location
self
.
operator
=
operator
# def __getattr__(self, key):
# return self.__dict__[key]
# def __getitem__(self, key):
# return self.get(key)
# def __getattribute__(self, value):
# return value
def
__repr__
(
self
):
return
'<LoginModel
%
r>'
%
(
self
.
user
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
'login_at'
:
self
.
login_at
,
'user_agent'
:
self
.
user_agent
,
...
...
@@ -70,12 +58,12 @@ class GetListLoginSchema(ma.SQLAlchemySchema):
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
user
=
fields
.
Integer
(
required
=
False
)
login_at
=
fields
.
String
(
required
=
False
)
user_agent
=
fields
.
String
(
required
=
False
)
ip
=
fields
.
String
(
required
=
False
)
geo_location
=
fields
.
String
(
required
=
False
)
operator
=
fields
.
String
(
required
=
False
)
user
=
ma
.
auto_field
(
)
login_at
=
ma
.
auto_field
(
)
user_agent
=
ma
.
auto_field
(
)
ip
=
ma
.
auto_field
(
)
geo_location
=
ma
.
auto_field
(
)
operator
=
ma
.
auto_field
(
)
getListLoginSchema
=
GetListLoginSchema
()
getListLoginsSchema
=
GetListLoginSchema
(
many
=
True
)
...
...
@@ -86,11 +74,11 @@ class GetLoginSchema(ma.SQLAlchemySchema):
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
LoginModel
user
=
fields
.
Integer
(
required
=
False
)
login_at
=
fields
.
String
(
required
=
False
)
user_agent
=
fields
.
String
(
required
=
False
)
ip
=
fields
.
String
(
required
=
False
)
geo_location
=
fields
.
String
(
required
=
False
)
operator
=
fields
.
String
(
required
=
False
)
user
=
ma
.
auto_field
(
)
login_at
=
ma
.
auto_field
(
)
user_agent
=
ma
.
auto_field
(
)
ip
=
ma
.
auto_field
(
)
geo_location
=
ma
.
auto_field
(
)
operator
=
ma
.
auto_field
(
)
getLoginSchema
=
GetLoginSchema
()
tools/build_out/models/package.py
View file @
a36af83d
'''
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 -*-
# -*- coding: utf-8 -*-
from
application.app
import
db
,
ma
from
.base
import
PrimaryModel
...
...
@@ -31,7 +22,7 @@ class PackageModel(PrimaryModel):
# 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_version
=
app_version
self
.
package_info
=
package_info
...
...
@@ -42,15 +33,11 @@ class PackageModel(PrimaryModel):
self
.
ip
=
ip
self
.
geo_location
=
geo_location
self
.
operator
=
operator
self
.
create_by
=
create_by
self
.
create_at
=
create_at
self
.
update_by
=
update_by
self
.
update_at
=
update_at
def
__repr__
(
self
):
return
'<PackageModel
%
r>'
%
(
self
.
app
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
'app_version'
:
self
.
app_version
,
'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
.base
import
PrimaryModel
from
marshmallow
import
Schema
,
fields
,
INCLUDE
,
EXCLUDE
from
webcreator
import
utils
from
webcreator.log
import
logger
class
UserModel
(
PrimaryModel
):
__tablename__
=
'evm_user'
username
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
account
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
password
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
role
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
email
=
db
.
Column
(
db
.
String
,
nullable
=
False
,
default
=
''
)
phone
=
db
.
Column
(
db
.
String
,
nullable
=
False
,
default
=
''
)
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
app_icon
=
db
.
Column
(
db
.
String
(
200
),
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
)
category
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
category_2th
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
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__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def
__init__
(
self
,
username
,
account
,
password
,
role
=
0
,
email
=
''
,
phone
=
''
):
self
.
username
=
username
self
.
account
=
account
self
.
password
=
password
self
.
role
=
role
self
.
email
=
email
self
.
phone
=
phone
def
__setattr__
(
self
,
key
,
value
):
# logger.info(f"execute __setattr__:key={key}, value={value}")
if
key
==
'password'
:
self
.
__dict__
[
key
]
=
utils
.
md5_encryption
(
value
)
else
:
self
.
__dict__
[
key
]
=
value
def
__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_icon
=
app_icon
self
.
app_version
=
app_version
self
.
category
=
category
self
.
category_2th
=
category_2th
self
.
developer
=
developer
self
.
download_url
=
download_url
self
.
app_file_size
=
app_file_size
self
.
app_screen_size
=
app_screen_size
self
.
app_arch
=
app_arch
self
.
app_review
=
app_review
def
__repr__
(
self
):
return
'<UserModel
%
r>'
%
(
self
.
user
name
)
return
'<UserModel
%
r>'
%
(
self
.
app_
name
)
def
to_
dict
(
self
):
def
to_
json
(
self
):
return
{
'username'
:
self
.
username
,
'account'
:
self
.
account
,
'password'
:
self
.
password
,
'role'
:
self
.
role
,
'email'
:
self
.
email
,
'phone'
:
self
.
phone
,
'app_name'
:
self
.
app_name
,
'app_icon'
:
self
.
app_icon
,
'app_version'
:
self
.
app_version
,
'category'
:
self
.
category
,
'category_2th'
:
self
.
category_2th
,
'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):
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
username
=
ma
.
auto_field
()
account
=
ma
.
auto_field
()
password
=
ma
.
auto_field
()
app_name
=
ma
.
auto_field
()
app_icon
=
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
()
...
...
@@ -77,9 +88,13 @@ class GetListUserSchema(ma.SQLAlchemySchema):
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
uuid
=
ma
.
auto_field
()
username
=
ma
.
auto_field
()
account
=
ma
.
auto_field
()
page
=
fields
.
Integer
(
required
=
False
)
pageSize
=
fields
.
Integer
(
required
=
False
)
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
()
getListUsersSchema
=
GetListUserSchema
(
many
=
True
)
...
...
@@ -90,8 +105,11 @@ class GetUserSchema(ma.SQLAlchemySchema):
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
username
=
ma
.
auto_field
()
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
()
getUserSchema
=
GetUserSchema
()
...
...
@@ -101,8 +119,13 @@ class PutUserSchema(ma.SQLAlchemySchema):
unknown
=
EXCLUDE
# 未知字段默认排除
model
=
UserModel
account
=
fields
.
String
(
required
=
False
,
allow_none
=
True
)
username
=
fields
.
String
(
required
=
False
,
allow_none
=
True
)
password
=
fields
.
String
(
required
=
False
,
allow_none
=
True
)
app_name
=
ma
.
auto_field
()
app_icon
=
ma
.
auto_field
()
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
()
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_restful
import
Api
...
...
@@ -8,14 +7,6 @@ from . import app
from
.
import
package
from
.
import
user
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__
)
...
...
@@ -36,31 +27,3 @@ api.add_resource(user.UserResourceList, '/user')
api
.
add_resource
(
login
.
LoginResource
,
'/login/<string:uuid>'
)
api
.
add_resource
(
login
.
LoginResourceList
,
'/login'
)
api
.
add_resource
(
device
.
DeviceResource
,
'/device/<string:uuid>'
)
api
.
add_resource
(
device
.
DeviceResourceList
,
'/device'
)
api
.
add_resource
(
annex
.
AnnexResource
,
'/annex/<string:uuid>'
)
api
.
add_resource
(
annex
.
AnnexResourceList
,
'/annex'
)
api
.
add_resource
(
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_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
...
...
@@ -26,29 +23,31 @@ class AppResourceList(Resource):
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListAppSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetListApp
.
emit
(
data
)
result
=
signalManager
.
actionGetListApp
.
emit
(
data
)
json_dumps
=
getListAppSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListAppsSchema
.
dump
(
result
.
items
)
if
result
[
0
]
:
json_dumps
=
getListAppsSchema
.
dump
(
result
[
1
]
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
]
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
except
Exception
as
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
):
try
:
json_payload
=
request
.
json
data
=
postAppSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPostApp
.
emit
(
data
)
logger
.
info
(
result
)
logger
.
warn
(
message
)
return
response_result
(
message
)
result
=
signalManager
.
actionPostApp
.
emit
(
data
)
if
result
[
0
]
==
False
:
# json_dumps = postAppSchema.dump(result)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
logger
.
warn
(
result
)
return
response_result
(
ResponseCode
.
OK
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
class
AppResource
(
Resource
):
...
...
@@ -68,14 +67,14 @@ class AppResource(Resource):
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getAppSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetApp
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getAppSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
result
=
signalManager
.
actionGetApp
.
emit
(
uuid
,
data
)
if
result
[
0
]
:
json_dumps
=
getAppSchema
.
dump
(
result
[
1
]
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
...
...
@@ -84,13 +83,14 @@ class AppResource(Resource):
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
putAppSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPutApp
.
emit
(
uuid
,
data
)
logger
.
info
(
result
)
logger
.
info
(
message
)
return
response_result
(
message
,
data
=
result
)
result
=
signalManager
.
actionPutApp
.
emit
(
uuid
,
data
)
if
result
[
0
]
==
True
:
# json_dumps = putAppSchema.dump(result)
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
NOTHING_CHANGE
,
msg
=
result
[
1
])
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
...
...
@@ -99,8 +99,10 @@ class AppResource(Resource):
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
# data = deleteAppSchema.load(json_payload)
result
,
message
=
signalManager
.
actionDeleteApp
.
emit
(
uuid
)
return
response_result
(
message
,
data
=
result
)
result
=
signalManager
.
actionDeleteApp
.
emit
(
uuid
)
if
result
[
0
]
==
True
:
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
except
Exception
as
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):
if
result
[
0
]:
json_dumps
=
getListAreasSchema
.
dump
(
result
[
1
])
logger
.
warn
(
json_dumps
)
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
json_dumps
,
count
=
result
[
2
])
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
])
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
except
Exception
as
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
):
...
...
@@ -42,12 +42,12 @@ class AreaResourceList(Resource):
result
=
signalManager
.
actionPostArea
.
emit
(
data
)
if
result
[
0
]
==
False
:
# 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
)
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
)
return
response_result
(
ResponseCode
.
OK
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
class
AreaResource
(
Resource
):
...
...
@@ -70,11 +70,11 @@ class AreaResource(Resource):
result
=
signalManager
.
actionGetArea
.
emit
(
uuid
,
data
)
if
result
[
0
]:
json_dumps
=
getAreaSchema
.
dump
(
result
[
1
])
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
HTTP_NOT_FOUND
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
...
...
@@ -86,11 +86,11 @@ class AreaResource(Resource):
result
=
signalManager
.
actionPutArea
.
emit
(
uuid
,
data
)
if
result
[
0
]
==
True
:
# 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
])
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
...
...
@@ -101,8 +101,8 @@ class AreaResource(Resource):
# data = deleteAreaSchema.load(json_payload)
result
=
signalManager
.
actionDeleteArea
.
emit
(
uuid
)
if
result
[
0
]
==
True
:
return
response_result
(
ResponseCode
.
HTTP_SUCCESS
)
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
msg
=
result
[
1
])
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
except
Exception
as
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_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
from
flask_jwt_extended
import
(
jwt_required
,
get_jwt_identity
)
from
marshmallow.exceptions
import
ValidationError
from
application.signal_manager
import
signalManager
from
models.login
import
postLoginSchema
,
getListLoginSchema
,
getListLoginsSchema
,
getLoginSchema
from
webcreator.log
import
logger
...
...
@@ -27,37 +23,30 @@ class LoginResourceList(Resource):
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListLoginSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetListLogin
.
emit
(
data
)
result
=
signalManager
.
actionGetListLogin
.
emit
(
data
)
json_dumps
=
getListLoginSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListLoginsSchema
.
dump
(
result
.
items
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
if
result
[
0
]:
json_dumps
=
getListLoginsSchema
.
dump
(
result
[
1
])
logger
.
warn
(
json_dumps
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
])
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
return
response_result
(
ResponseCode
.
DB_ERROR
)
def
post
(
self
):
try
:
json_payload
=
request
.
json
data
=
postLoginSchema
.
load
(
json_payload
)
# 更新data,插入ip信息,如果没有转发ip,那么则获取请求ip
data
.
update
({
"ip"
:
request
.
headers
.
get
(
'X-Forwarded-For'
,
request
.
remote_addr
),
"user_agent"
:
request
.
headers
.
get
(
'User-Agent'
,
""
)
})
result
,
message
=
signalManager
.
actionPostLogin
.
emit
(
data
)
return
response_result
(
message
,
data
=
result
)
except
ValidationError
as
e
:
return
response_result
(
ResponseCode
.
HTTP_INVAILD_REQUEST
,
data
=
e
.
messages
)
result
=
signalManager
.
actionPostLogin
.
emit
(
data
)
if
result
[
0
]
==
False
:
# json_dumps = postLoginSchema.dump(result
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
]
)
logger
.
warn
(
result
)
return
response_result
(
ResponseCode
.
OK
)
except
Exception
as
e
:
data
=
None
if
hasattr
(
e
,
'args'
):
data
=
e
.
args
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER_ERROR
,
data
=
data
)
return
response_result
(
ResponseCode
.
DB_ERROR
)
class
LoginResource
(
Resource
):
...
...
@@ -77,11 +66,11 @@ class LoginResource(Resource):
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getLoginSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetLogin
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getLoginSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
result
=
signalManager
.
actionGetLogin
.
emit
(
uuid
,
data
)
if
result
[
0
]
:
json_dumps
=
getLoginSchema
.
dump
(
result
[
1
]
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
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_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
...
...
@@ -26,16 +23,16 @@ class PackageResourceList(Resource):
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListPackageSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetListPackage
.
emit
(
data
)
result
=
signalManager
.
actionGetListPackage
.
emit
(
data
)
json_dumps
=
getListPackageSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListPackagesSchema
.
dump
(
result
.
items
)
if
result
[
0
]
:
json_dumps
=
getListPackagesSchema
.
dump
(
result
[
1
]
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
]
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
class
PackageResource
(
Resource
):
def
__init__
(
self
):
...
...
@@ -54,11 +51,11 @@ class PackageResource(Resource):
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getPackageSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetPackage
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getPackageSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
result
=
signalManager
.
actionGetPackage
.
emit
(
uuid
,
data
)
if
result
[
0
]
:
json_dumps
=
getPackageSchema
.
dump
(
result
[
1
]
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
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_restful
import
Resource
from
flask_restful.reqparse
import
RequestParser
...
...
@@ -26,28 +23,31 @@ class UserResourceList(Resource):
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetListUser
.
emit
(
data
)
result
=
signalManager
.
actionGetListUser
.
emit
(
data
)
json_dumps
=
getListUserSchema
.
dump
(
result
)
if
result
:
json_dumps
=
getListUsersSchema
.
dump
(
result
.
items
)
if
result
[
0
]
:
json_dumps
=
getListUsersSchema
.
dump
(
result
[
1
]
)
logger
.
warn
(
json_dumps
)
return
response_result
(
message
,
data
=
json_dumps
,
count
=
result
.
total
)
return
response_result
(
message
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
,
count
=
result
[
2
]
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
)
except
Exception
as
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
):
try
:
json_payload
=
request
.
json
data
=
postUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPostUser
.
emit
(
data
)
logger
.
info
(
result
)
logger
.
warn
(
message
)
return
response_result
(
message
)
result
=
signalManager
.
actionPostUser
.
emit
(
data
)
if
result
[
0
]
==
False
:
# json_dumps = postUserSchema.dump(result)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
logger
.
warn
(
result
)
return
response_result
(
ResponseCode
.
OK
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
class
UserResource
(
Resource
):
...
...
@@ -67,26 +67,30 @@ class UserResource(Resource):
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
getUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionGetUser
.
emit
(
uuid
,
data
)
if
result
:
json_dumps
=
getUserSchema
.
dump
(
result
)
return
response_result
(
message
,
data
=
json_dumps
)
return
response_result
(
message
)
result
=
signalManager
.
actionGetUser
.
emit
(
uuid
,
data
)
if
result
[
0
]
:
json_dumps
=
getUserSchema
.
dump
(
result
[
1
]
)
return
response_result
(
ResponseCode
.
OK
,
data
=
json_dumps
)
return
response_result
(
ResponseCode
.
NO_DATA
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
def
put
(
self
,
uuid
):
try
:
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
data
=
putUserSchema
.
load
(
json_payload
)
result
,
message
=
signalManager
.
actionPutUser
.
emit
(
uuid
,
data
)
return
response_result
(
message
,
data
=
result
)
result
=
signalManager
.
actionPutUser
.
emit
(
uuid
,
data
)
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
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
HTTP_SERVER
_ERROR
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
@
jwt_required
(
locations
=
[
"headers"
])
...
...
@@ -95,8 +99,10 @@ class UserResource(Resource):
json_payload
=
request
.
json
print
(
"========>"
,
uuid
,
json_payload
)
# data = deleteUserSchema.load(json_payload)
result
,
message
=
signalManager
.
actionDeleteUser
.
emit
(
uuid
)
return
response_result
(
message
,
data
=
result
)
result
=
signalManager
.
actionDeleteUser
.
emit
(
uuid
)
if
result
[
0
]
==
True
:
return
response_result
(
ResponseCode
.
OK
)
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
except
Exception
as
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 -*-
############################
# 信号槽
############################
class
PySignal
(
object
):
"""
Simple event class used to provide hooks for different types of events in Locust.
...
...
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 -*-
############################
# Log
# 日志
############################
import
os
import
logging
from
logging.handlers
import
RotatingFileHandler
...
...
tools/build_out/webcreator/response.py
View file @
a36af83d
# -*- coding: utf_8 -*-
'''
请求方法:
OPTION : 用于获取资源支持的所有 HTTP 方法
HEAD : 用于只获取请求某个资源返回的头信息
GET : 用于从服务器获取资源信息
完成请求后返回状态码 200 OK
POST : 用于创建新资源
创建完成后返回状态码 201 Created
PUT : 用于完整的替换资源或者创建指定身份的资源
如果是创建了资源,则返回 201 Created
如果是替换了资源,则返回 200 OK
DELETE : 用于删除某个资源
完成请求后返回状态码 204 No Content
PATCH : 用于局部更新资源
完成请求后返回状态码 200 OK
================================================================================
状态码:
请求成功
200:请求执行成功并返回相应数据
201:创建成功并返回相应资源数据
202:接受请求,但无法立即完成创建行为
204:请求执行成功,不返回相应资源数据
重定向
301:被请求的资源已永久移动到新位置
302:请求的资源现在临时从不通的URI响应请求
303:对应当前请求的响应可以在另一个 URI 上被找到,客户端应该使用 GET 方法进行请求
307:对应当前请求的响应可以在另一个 URI 上被找到,客户端应该保持原有的请求方法进行请求
条件请求
304:资源自从上次请求后没有再次发生变化,主要使用场景在于实现数据缓存
409:请求操作和资源的当前状态存在冲突。主要使用场景在于实现并发控制
412:服务器在验证请求的头字段中给出先决条件时,没能满足其中的一个或多个。主要使用场景在于实现并发控制
客户端错误
400 : 请求体包含语法错误
401 : 需要验证用户身份
403 : 服务器拒绝执行
404 : 找不到目标资源
405 : 不允许执行目标方法,响应中应该带有 Allow 头,内容为对该资源有效的 HTTP 方法
406 : 服务器不支持客户端请求的内容格式
410 : 被请求的资源已被删除
413 : POST 或者 PUT 请求的消息实体过大
415 : 服务器不支持请求中提交的数据的格式
422 : 请求格式正确,但是由于含有语义错误,无法响应
428 : 要求先决条件,如果想要请求能成功必须满足一些预设的条件要求先决条件
服务端错误
500 : 服务器遇到了一个未曾预料的状况,导致了它无法完成对请求的处理
502 : 作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应
501 : 服务器不支持当前请求所需要的某个功能
503 : 由于临时的服务器维护或者过载,服务器当前无法处理请求
'''
############################
# Response
# 响应
############################
class
ResponseCode
(
object
):
# 通用状态码
HTTP_SUCCESS
=
(
200
,
"success"
)
HTTP_NO_DATA
=
(
204
,
"no data"
)
HTTP_NO_CHANGE
=
(
304
,
'nothing change'
)
HTTP_AUTH_FAIL
=
(
401
,
'authentication failed'
)
HTTP_INVAILD_REQUEST
=
(
403
,
'invaild request'
)
HTTP_NOT_FOUND
=
(
404
,
"not found"
)
HTTP_SERVER_ERROR
=
(
500
,
"server error"
)
# 用户模块
USER_NOT_EXISTS
=
(
1010001
,
'user not exists'
)
USER_EXISTS
=
(
1010002
,
'user already exists'
)
USER_PASSWORD_ERROR
=
(
1010003
,
'password error'
)
def
response_result
(
response
,
msg
=
None
,
data
=
None
,
**
kwargs
):
c
,
m
=
response
if
msg
==
None
:
msg
=
m
result
=
{
'code'
:
c
,
'msg'
:
msg
,
'data'
:
data
}
OK
=
(
200
,
'ok'
)
NO_DATA
=
(
204
,
'no data'
)
NOT_FOUND
=
(
404
,
'not found'
)
NOTHING_CHANGE
=
(
304
,
'nothing change'
)
REQUEST_ERROR
=
(
400
,
'request error'
)
AUTHORIZATION_ERROR
=
(
401
,
'authentication error'
)
INVAILD_REQUEST
=
(
403
,
'invaild request'
)
PARAMETER_ERROR
=
(
4001
,
'parameter error'
)
PARAMETER_NULL
=
(
4002
,
'parameter is null'
)
PASSWORD_ERROR
=
(
4003
,
'password error'
)
EXISTS_ERROR
=
(
4004
,
'record exists'
)
INVAILD_ROLE_ERROR
=
(
4005
,
'invaild role error'
)
ACCOUNT_DISABLED
=
(
4006
,
'account is disabled'
)
SERVER_ERROR
=
(
500
,
'server error'
)
DB_ERROR
=
(
5001
,
'database error'
)
UNKNOWN_ERROR
=
(
5003
,
'unknown error'
)
def
response_result
(
code
,
msg
=
None
,
data
=
None
,
**
kwargs
):
if
msg
is
None
:
msg
=
code
[
1
]
result
=
{
'code'
:
code
[
0
],
'msg'
:
msg
,
'data'
:
data
}
result
.
update
(
kwargs
)
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 (
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
:
def
__init__
(
self
):
pass
...
...
@@ -186,6 +38,3 @@ class ObjectDict(Dict[str, Any]):
if
__name__
==
"__main__"
:
d
=
{
'a'
:
1
,
'b'
:
2
}
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 (
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
:
def
__init__
(
self
):
pass
...
...
@@ -168,6 +38,3 @@ class ObjectDict(Dict[str, Any]):
if
__name__
==
"__main__"
:
d
=
{
'a'
:
1
,
'b'
:
2
}
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