judgement_function.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. def judge_filepath(file_type):
  2. img_list = ['bmp', 'jpg', 'png', 'tif', 'gif', 'pcx', 'tga', 'exif', 'fpx', 'svg', 'psd', 'cdr', 'pcd', 'dxf',
  3. 'ufo', 'eps', 'ai', 'raw', 'WMF', 'webp']
  4. doc_list = ['txt', 'doc', 'xls', 'ppt', 'docx', 'xlsx', 'pptx', 'lrc', 'wps', 'zip', 'rar', '7z', 'torrent', 'pdf']
  5. video_list = ['cd', 'ogg', 'mp3', 'asf', 'wma', 'wav', 'mp3pro', 'rm', 'mp4', 'real', 'ape', 'module', 'midi',
  6. 'vqf']
  7. procedure_list = ['exe', 'py', 'java', 'class', 'pyc', 'app', 'apk', 'bat']
  8. if file_type in img_list:
  9. file_path = 'img'
  10. elif file_type in doc_list:
  11. file_path = 'doc'
  12. elif file_type in video_list:
  13. file_path = 'video'
  14. elif file_type in procedure_list:
  15. file_path = 'procedure'
  16. else:
  17. file_path = 'others'
  18. return file_path
  19. def format_size(old_size):
  20. if 1024 < old_size < 1024 * 1024:
  21. new_size = round(old_size / 1024, 2)
  22. return str(new_size) + 'KB'
  23. elif 1024 * 1024 < old_size < 1024 * 1024 * 1024:
  24. new_size = round(old_size / (1024 * 1024), 2)
  25. return str(new_size) + 'MB'
  26. elif old_size > 1024 * 1024 * 1024:
  27. new_size = round(old_size / (1024 * 1024 * 1024), 2)
  28. return str(new_size) + 'GB'