You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
827 B

  1. #funcs
  2. import pip._internal as pip
  3. def from_pack(file):
  4. file = open(file)
  5. packages = set(file.read().split('\n')) - set(package.key for package in pip.get_installed_distributions())
  6. file.close()
  7. for package in packages:
  8. pip.main(['install',package])
  9. def to_pack(file):
  10. file = open(file,'w')
  11. s = '\n'.join(map(lambda p: p.key,pip.get_installed_distributions()))
  12. file.write(s)
  13. file.close()
  14. #arguments
  15. if __name__ == "__main__":
  16. import argparse
  17. parser = argparse.ArgumentParser()
  18. parser.add_argument("mode",metavar = "action",help="what you wanna do")
  19. parser.add_argument("path",metavar = "dir",help="fullpath to pack")
  20. args = parser.parse_args()
  21. if args.mode == "to_pack":
  22. to_pack(args.path)
  23. elif args.mode == "from_pack":
  24. from_pack(args.path)