add_unused_files.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. #添加垃圾文件
  3. import os
  4. import sys
  5. import random
  6. py_path = sys.argv[0][::-1].split('/',1)[1][::-1]+'/'
  7. os.chdir(py_path)
  8. #
  9. out_file_path = sys.argv[1]
  10. class_files_list = []
  11. class_key_list = ["Class","Def","Layer","Unit","Component","Pic","Manager","Data"]
  12. with open('FileNames') as file:
  13. content = file.read()
  14. class_files_list = content.split("\n")
  15. def del_files(dir_path):
  16. for root, dirs, files in os.walk(dir_path, topdown=False):
  17. for name in files:
  18. os.remove(os.path.join(root, name)) # 删除文件
  19. for name in dirs:
  20. os.rmdir(os.path.join(root, name)) # 删除一个空目录
  21. def mk_sub_file(file_prefix, buf):
  22. dst_file_path = out_file_path + '/' + file_prefix
  23. with open(dst_file_path,'wb') as fout:
  24. fout.write(buf)
  25. def add_files():
  26. if not os.path.exists(out_file_path):
  27. os.mkdir(out_file_path)
  28. del_files(out_file_path)
  29. repeat_times = 10
  30. while repeat_times>0:
  31. for x in xrange(1,random.randint(2,4)):
  32. lenght = len(class_files_list)
  33. class_name = class_files_list[random.randint(0,lenght)]
  34. key = class_key_list[random.randint(0,len(class_key_list) - 1)]
  35. rep_str = class_name[random.randint(0,len(class_name) - 1)]
  36. class_name = class_name.replace(rep_str,key)
  37. mk_sub_file(class_name,class_name + key + rep_str + class_name)
  38. pass
  39. repeat_times = repeat_times - 1
  40. print("add unused files ok")
  41. if __name__=="__main__":
  42. add_files()