get_backup_images.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import os, sys
  4. import shutil
  5. from os.path import abspath, join
  6. PROJECT_ROOT = abspath(os.path.split(os.path.realpath(__file__))[0] + "/..")
  7. sys.path.insert(0, PROJECT_ROOT)
  8. def touch(file_name):
  9. if os.path.exists(file_name):
  10. print("file exist! {}".format(file_name))
  11. else:
  12. print("creating %s" % file_name)
  13. fid = open(file_name, 'w')
  14. fid.close()
  15. backup_path = 'E://todo//2019'
  16. dest_path = 'e://images'
  17. with open('e://images//www.washpayer.com-error.log', 'r') as f:
  18. all = f.read().split()
  19. for item in all:
  20. back_file = os.path.abspath(os.path.join(backup_path, item))
  21. tokens = item.split('/')
  22. dest_dir = os.path.abspath(os.path.join(dest_path, tokens[0]))
  23. dest_file = os.path.abspath(os.path.join(dest_path, item))
  24. if not os.path.exists(dest_dir):
  25. os.makedirs(dest_dir)
  26. if os.path.exists(back_file):
  27. try:
  28. shutil.copyfile(back_file, dest_file)
  29. except Exception as e:
  30. print('copy failure.')
  31. else:
  32. touch(dest_file)