scheme_resolve.py
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding=utf-8
#author: 4N
#createtime: 2021/9/16
#email: nheweijun@sina.com
from app.util.component.ApiTemplate import ApiTemplate
import os
from app.util.component.FileProcess import FileProcess
from app.util.component.SliceScheme import SliceScheme
import shutil
from app.util.component.StructuredPrint import StructurePrint
class Api(ApiTemplate):
api_name = "解析方案"
def process(self):
# 返回结果
res = {}
store_file = ""
try:
# 业务逻辑
parent = os.path.dirname(os.path.realpath(__file__))
dir_path, store_file = FileProcess.save(parent)
scheme = SliceScheme(store_file)
data = {
"crs_wkt": scheme.parameter.get("wkt"),
"top_left": "{},{}".format(scheme.parameter.get("x"),scheme.parameter.get("y")),
"dpi": scheme.parameter.get("dpi"),
"rows": scheme.parameter.get("rows"),
"cols": scheme.parameter.get("cols"),
"levels": scheme.levels,
# "parameter":scheme.parameter
}
res["data"] = data
res["result"] = True
except Exception as e:
raise e
finally:
try:
file_tmp_path = os.path.join(store_file.split("file_tmp")[0],"file_tmp")
dir_path = os.path.dirname(store_file)
i=0
while not os.path.dirname(dir_path).__eq__(file_tmp_path) and i<30:
dir_path = os.path.dirname(dir_path)
i+=1
if i<30:
shutil.rmtree(dir_path,True)
StructurePrint().print("删除文件成功!")
else:
raise Exception("找不到文件!")
except Exception as e:
StructurePrint().print("删除文件失败!","ERROR")
return res
api_doc = {
"tags": ["方案接口"],
"parameters": [
{"name": "file",
"in": "formData",
"type": "file",
"description": "切片方案"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}