update 文件生成器

This commit is contained in:
P3ngSaM 2022-08-08 21:45:13 +08:00
parent f138fcb5b7
commit b9e6e70921
2 changed files with 16 additions and 9 deletions

View File

@ -1,4 +1,5 @@
import os
import shutil
import sys
import zipfile
@ -18,7 +19,7 @@ class FileObjImpl(object):
"""根据包名创建包"""
path = self.get_project_abs_path(name=path)
if os.path.exists(path):
return r"E:\TFSE\wide_rating_v0.21\Modules\File\static\TestFile\{}".format(path)
return False
os.makedirs(path)
# 将__init__.py文件
init_path = os.path.join(path, '__init__.py')
@ -165,7 +166,8 @@ class FileObjImpl(object):
impl_name = package_data['impl_name']
# 创建包
self.create_package(package_name, route_name, obj_name, impl_name)
package_path = r"E:\TFSE\wide_rating_v0.21\Modules\File\static\{}".format(package_name)
# package_path = r"E:\TFSE\wide_rating_v0.21\Modules\File\static\{}".format(package_name)
package_path = self.get_project_abs_path(name=package_name)
return package_path
@staticmethod
@ -181,10 +183,14 @@ class FileObjImpl(object):
z.write(os.path.join(dirpath, filename), fpath + filename)
z.close()
@staticmethod
def return_file_data(**kwargs):
def return_file_data(self, **kwargs):
"""返回文件数据流"""
package_name = kwargs['package_name']
zip_path = r"E:\TFSE\wide_rating_v0.21\Modules\File\static\{}.zip".format(package_name)
package_name = '{}.zip'.format(kwargs['package_name'])
zip_path = self.get_project_abs_path(name=package_name)
zip_name = open(zip_path, 'rb').read()
return zip_name
return zip_name
def delete_all_file(self):
"""删除临时文件夹"""
file_path = self.get_project_abs_path(name='')
shutil.rmtree(file_path)

View File

@ -1,4 +1,4 @@
from flask import Blueprint, request, Response
from flask import Blueprint, request, Response, make_response
from Modules.File.FileImpl import FileObjImpl
from Utils.ErrorUtil import APIReturnError
@ -29,7 +29,8 @@ def new_file_package_route():
impl = FileObjImpl()
src_dir = impl.new_file_package(data=data)
impl.write_file_to_zip(src_dir=src_dir)
response = Response(impl.return_file_data(package_name=data['package_name']), content_type='zip')
response = Response(impl.return_file_data(package_name=data['package_name']), content_type='application/zip')
impl.delete_all_file()
return response
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code