clean.py 866 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. import shutil
  4. from base import *
  5. TESTCASE_DIR = os.path.join(PROJECT_ROOT, 'testcase')
  6. path_joiner = lambda path, filename : os.path.join(path, filename)
  7. testcase_path_joiner = lambda filename : path_joiner(TESTCASE_DIR, filename)
  8. files_to_delete = {'ghostdriver.log', 'geckodriver.log'}
  9. dirs_to_delete = {'.cache', '__pycache__'}
  10. def delete(path):
  11. if os.path.isfile(path):
  12. os.remove(path)
  13. elif os.path.isdir(path):
  14. shutil.rmtree(path)
  15. @click.command()
  16. def clean():
  17. for root, dirs, files in os.walk(PROJECT_ROOT):
  18. matches = ( set(files) & files_to_delete ) | ( set(dirs) & dirs_to_delete )
  19. if len(matches):
  20. map(delete, [ path_joiner(root, _) for _ in matches ])
  21. click.echo('success!')
  22. if __name__ == "__main__":
  23. clean()