Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (c) 2019~2999 - Cologler <skyoflw@gmail.com>
  4. # ----------
  5. # remove virtualenvs if project has being removed.
  6. # ----------
  7.  
  8. import os
  9. import sys
  10. import traceback
  11. import pathlib
  12. import shutil
  13.  
  14. HONE = pathlib.Path(os.path.expandvars('%userprofile%'))
  15. VIRTUAL_ENVS = HONE / '.virtualenvs'
  16.  
  17. def main(argv=None):
  18. if argv is None:
  19. argv = sys.argv
  20. try:
  21. if VIRTUAL_ENVS.is_dir():
  22. for venv in VIRTUAL_ENVS.iterdir():
  23. proj = venv / '.project'
  24. if proj.is_file():
  25. path = proj.read_text()
  26. if not os.path.isdir(path):
  27. print(f'remove {venv} since {path} has being removed.')
  28. shutil.rmtree(venv)
  29. except Exception: # pylint: disable=W0703
  30. traceback.print_exc()
  31.  
  32. if __name__ == '__main__':
  33. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement