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
3cb3d82a
Commit
3cb3d82a
authored
Nov 10, 2021
by
wanli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🧪 test: 修复读文件编码格式错误问题
parent
99d0ccd3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
16 deletions
+16
-16
backend/start.sh
backend/start.sh
+1
-12
backend/view/api.py
backend/view/api.py
+15
-4
No files found.
backend/start.sh
View file @
3cb3d82a
#!/usr/bin/env bash
#!/usr/bin/env bash
###
# @Author: your name
# @Date: 2021-07-15 09:33:39
# @LastEditTime: 2021-07-21 14:25:13
# @LastEditors: your name
# @Description: In User Settings Edit
# @FilePath: \evm-store\backend\start.sh
###
Cur_Dir
=
$(
pwd
)
pip
install
-i
https://mirrors.aliyun.com/pypi/simple
-r
requirements.txt
--trusted-host
\ No newline at end of file
source
venv/bin/activate
nohup
${
Cur_Dir
}
/venv/bin/python3
${
Cur_Dir
}
/start.py
>
running.log 2>&1 &
backend/view/api.py
View file @
3cb3d82a
...
@@ -8,6 +8,7 @@ import traceback
...
@@ -8,6 +8,7 @@ import traceback
import
uuid
import
uuid
import
time
import
time
import
zipfile
import
zipfile
import
chardet
from
pathlib
import
Path
from
pathlib
import
Path
from
datetime
import
datetime
from
datetime
import
datetime
from
flask
import
Blueprint
,
request
,
json
from
flask
import
Blueprint
,
request
,
json
...
@@ -31,6 +32,13 @@ api = Blueprint("api", __name__, url_prefix="/api/v1/%s" % config['NAME'])
...
@@ -31,6 +32,13 @@ api = Blueprint("api", __name__, url_prefix="/api/v1/%s" % config['NAME'])
logger
.
info
(
"/api/v1/
%
s"
%
config
[
'NAME'
])
logger
.
info
(
"/api/v1/
%
s"
%
config
[
'NAME'
])
# 获取文件编码类型
def
get_encoding
(
file
):
# 二进制方式读取,获取字节数据,检测类型
with
open
(
file
,
'rb'
)
as
f
:
data
=
f
.
read
()
return
chardet
.
detect
(
data
)[
'encoding'
]
def
stopApp
():
def
stopApp
():
fpath
=
os
.
sep
.
join
([
os
.
getcwd
(),
"restart.json"
])
fpath
=
os
.
sep
.
join
([
os
.
getcwd
(),
"restart.json"
])
with
open
(
fpath
,
"w+"
)
as
f
:
with
open
(
fpath
,
"w+"
)
as
f
:
...
@@ -398,7 +406,8 @@ def parse_header_files():
...
@@ -398,7 +406,8 @@ def parse_header_files():
config_file
=
"typeconfig.json"
config_file
=
"typeconfig.json"
typeconfig
=
{}
typeconfig
=
{}
if
os
.
path
.
exists
(
config_file
):
if
os
.
path
.
exists
(
config_file
):
with
open
(
config_file
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
encode_type
=
get_encoding
(
config_file
)
with
open
(
config_file
,
"r"
,
encoding
=
encode_type
)
as
f
:
typeconfig
=
json
.
loads
(
f
.
read
())
typeconfig
=
json
.
loads
(
f
.
read
())
if
len
(
typeconfig
.
keys
())
>
0
:
if
len
(
typeconfig
.
keys
())
>
0
:
...
@@ -411,7 +420,7 @@ def parse_header_files():
...
@@ -411,7 +420,7 @@ def parse_header_files():
for
file
in
files
:
for
file
in
files
:
result
=
parse_header_file
(
file
.
resolve
()
.
as_posix
(),
undefined_type
,
error_tips
)
result
=
parse_header_file
(
file
.
resolve
()
.
as_posix
(),
undefined_type
,
error_tips
)
if
result
!=
None
:
if
result
!=
None
:
target
=
target_path
.
joinpath
(
".json"
.
format
(
file
.
name
))
target
=
target_path
.
joinpath
(
"
{}
.json"
.
format
(
file
.
name
))
with
open
(
target
.
resolve
()
.
as_posix
(),
"w+"
,
encoding
=
"utf-8"
)
as
f
:
with
open
(
target
.
resolve
()
.
as_posix
(),
"w+"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
json
.
dumps
(
result
))
f
.
write
(
json
.
dumps
(
result
))
result_list
.
append
(
result
)
result_list
.
append
(
result
)
...
@@ -451,8 +460,10 @@ def process_parse():
...
@@ -451,8 +460,10 @@ def process_parse():
# 加载系统内置类型映射文件
# 加载系统内置类型映射文件
config_file
=
"typeconfig.json"
config_file
=
"typeconfig.json"
typeconfig
=
{}
typeconfig
=
{}
encode_type
=
"utf-8"
if
os
.
path
.
exists
(
config_file
):
if
os
.
path
.
exists
(
config_file
):
with
open
(
config_file
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
encode_type
=
get_encoding
(
config_file
)
with
open
(
config_file
,
"r"
,
encoding
=
encode_type
)
as
f
:
typeconfig
=
json
.
loads
(
f
.
read
())
typeconfig
=
json
.
loads
(
f
.
read
())
if
not
typeconfig
:
if
not
typeconfig
:
typeconfig
=
{}
typeconfig
=
{}
...
@@ -462,7 +473,7 @@ def process_parse():
...
@@ -462,7 +473,7 @@ def process_parse():
if
len
(
typeconfig
.
keys
())
>
0
:
if
len
(
typeconfig
.
keys
())
>
0
:
conf
=
update_mark_type
(
typeconfig
)
conf
=
update_mark_type
(
typeconfig
)
with
open
(
config_file
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
with
open
(
config_file
,
"w"
,
encoding
=
encode_type
)
as
f
:
f
.
write
(
json
.
dumps
(
conf
))
f
.
write
(
json
.
dumps
(
conf
))
try
:
try
:
...
...
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