util_create_file.py 570 B

12345678910111213141516171819
  1. from TestLaboratory.settings import SOFTWARE_ROOT
  2. import os
  3. def create_version_file(file, software_name, version_num):
  4. file_dir = SOFTWARE_ROOT + software_name + "/" + version_num
  5. if not os.path.exists(file_dir):
  6. os.makedirs(file_dir)
  7. file_path = file_dir + "/" + file.name
  8. try:
  9. with open(file_path, 'wb') as f:
  10. f.write(file.read())
  11. except FileNotFoundError:
  12. return {'code': 500, 'msg': "文件上传错误,未找到该文件"}
  13. finally:
  14. f.close()
  15. return {'code': 200, 'file_path': file_path}