register_python 1.0 KB

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python
  2. import sys
  3. from winpython import associate, utils
  4. from argparse import ArgumentParser
  5. parser = ArgumentParser(description="Register Python file extensions, icons "\
  6. "and Windows explorer context menu to a target "\
  7. "Python distribution.")
  8. try:
  9. str_type = unicode
  10. except NameError:
  11. str_type = str
  12. parser.add_argument('--target', metavar='path', type=str,
  13. default=sys.prefix,
  14. help='path to the target Python distribution')
  15. parser.add_argument('--all', dest='all', action='store_const',
  16. const=True, default=False,
  17. help='register to all users, requiring administrative '\
  18. 'privileges (default: register to current user only)')
  19. args = parser.parse_args()
  20. print(args.target)
  21. if utils.is_python_distribution(args.target):
  22. associate.register(args.target, current=not args.all)
  23. else:
  24. raise WindowsError("Invalid Python distribution %s" % args.target)