feat: 缓存队列
This commit is contained in:
parent
ebb0dafc82
commit
7fc844b27c
|
@ -11,6 +11,28 @@ from ...libs.tools import read_file, write_json, read_json_file, make_dir
|
||||||
|
|
||||||
api = RedPrint('anno')
|
api = RedPrint('anno')
|
||||||
|
|
||||||
|
waiting_list_dic = {}
|
||||||
|
|
||||||
|
def create_anno_2_file(project_name, anno_cont, all_anno=None):
|
||||||
|
|
||||||
|
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
|
||||||
|
|
||||||
|
# 判断路径是否存在
|
||||||
|
if not os.path.exists(anno_output_path):
|
||||||
|
write_json(anno_output_path, [anno_cont])
|
||||||
|
else:
|
||||||
|
output_anno = OutputAnno()
|
||||||
|
output_anno.all_anno = read_json_file(anno_output_path)
|
||||||
|
output_anno.add_anno(anno_cont)
|
||||||
|
|
||||||
|
write_json(anno_output_path, output_anno.all_anno)
|
||||||
|
|
||||||
|
waiting_list_dic[project_name] = waiting_list_dic[project_name][1:]
|
||||||
|
if len(waiting_list_dic[project_name]) > 0:
|
||||||
|
create_anno_2_file(project_name, waiting_list_dic[project_name][0], all_anno)
|
||||||
|
return True
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,19 +51,11 @@ def create_anno():
|
||||||
anno_cont.annoDetails = anno_details
|
anno_cont.annoDetails = anno_details
|
||||||
anno_cont.isAnno = True
|
anno_cont.isAnno = True
|
||||||
|
|
||||||
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
|
if project_name not in waiting_list_dic:
|
||||||
|
waiting_list_dic[project_name] = []
|
||||||
# 判断路径是否存在
|
waiting_list_dic[project_name].append(anno_cont)
|
||||||
if not os.path.exists(anno_output_path):
|
if (len(waiting_list_dic[project_name]) == 1): # 自己位于第一个才处理,其他在第一个结束时处理
|
||||||
write_json(anno_output_path, [anno_cont])
|
create_anno_2_file(project_name, waiting_list_dic[project_name][0])
|
||||||
ret_info.errCode = 0
|
|
||||||
else:
|
|
||||||
output_anno = OutputAnno()
|
|
||||||
output_anno.all_anno = read_json_file(anno_output_path)
|
|
||||||
output_anno.add_anno(anno_cont)
|
|
||||||
|
|
||||||
write_json(anno_output_path, output_anno.all_anno)
|
|
||||||
ret_info.errCode = 0
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
|
@ -30,6 +30,8 @@ def query_file():
|
||||||
file_names.remove('anno.json')
|
file_names.remove('anno.json')
|
||||||
|
|
||||||
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
|
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
|
||||||
|
if not os.path.exists(anno_output_path):
|
||||||
|
open(anno_output_path, 'w', encoding='utf-8').write('[]').close()
|
||||||
|
|
||||||
# 判断路径是否存在
|
# 判断路径是否存在
|
||||||
if not os.path.exists(anno_output_path):
|
if not os.path.exists(anno_output_path):
|
||||||
|
@ -116,7 +118,10 @@ def get_json():
|
||||||
project_file_list = get_project_file(project_path)
|
project_file_list = get_project_file(project_path)
|
||||||
anno_data_set = set()
|
anno_data_set = set()
|
||||||
download_json = []
|
download_json = []
|
||||||
anno_data = read_json_file(PROJECT_PATH.format(project_name) + '/anno.json')
|
anno_file_path = PROJECT_PATH.format(project_name) + '/anno.json'
|
||||||
|
if not os.path.exists(anno_file_path):
|
||||||
|
open(anno_file_path, 'w', encoding='utf-8').write('[]').close()
|
||||||
|
anno_data = read_json_file(anno_file_path)
|
||||||
for item in anno_data:
|
for item in anno_data:
|
||||||
item_dict = {}
|
item_dict = {}
|
||||||
item_dict['file'] = item['fileName']
|
item_dict['file'] = item['fileName']
|
||||||
|
|
|
@ -22,9 +22,11 @@ def make_dir(path):
|
||||||
if not folder:
|
if not folder:
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
|
|
||||||
|
json_cache_dic = {}
|
||||||
|
|
||||||
# 将json数据写入.json文件
|
# 将json数据写入.json文件
|
||||||
def write_json(json_file_path, data):
|
def write_json(json_file_path, data):
|
||||||
|
json_cache_dic[json_file_path] = data
|
||||||
with open(json_file_path, 'w', encoding='utf-8') as f:
|
with open(json_file_path, 'w', encoding='utf-8') as f:
|
||||||
json.dump(data, f, ensure_ascii=False, default=lambda o: o.__dict__)
|
json.dump(data, f, ensure_ascii=False, default=lambda o: o.__dict__)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue