2626from winpython .py3compat import configparser as cp
2727
2828# from former wppm separate script launcher
29- from argparse import ArgumentParser
29+ import textwrap
30+ from argparse import ArgumentParser , HelpFormatter , RawTextHelpFormatter
3031from winpython import py3compat
3132
3233from winpython import piptree
@@ -113,6 +114,7 @@ def get_package_metadata(database, name, gotoWWW=False, update=False):
113114 except :
114115 pass
115116 return my_metadata
117+
116118
117119class BasePackage (object ):
118120 def __init__ (self , fname ):
@@ -828,16 +830,45 @@ def main(test=False):
828830 # dist.install(pack)
829831 # dist.uninstall(pack)
830832 else :
833+ bold = "\033 [1m"
834+ unbold = "\033 [0m"
835+ registerWinPythonHelp = f'''Register distribution
836+ ({ bold } experimental{ unbold } )
837+ This will associate file extensions, icons and
838+ Windows explorer's context menu entries ('Edit with IDLE', ...)
839+ with selected Python distribution in Windows registry.
840+
841+ Shortcuts for all WinPython launchers will be installed
842+ in { unbold } WinPython{ unbold } Start menu group (replacing existing
843+ shortcuts).
844+
845+ { bold } Note{ unbold } : these actions are similar to those performed
846+ when installing old Pythons with the official installer before 'py'
847+ .
848+ '''
849+
850+ unregisterWinPythonHelp = '''Unregister distribution
851+ ({bold}experimental{unbold})
852+ This will remove file extensions associations, icons and
853+ Windows explorer's context menu entries ('Edit with IDLE', ...)
854+ with selected Python distribution in Windows registry.
855+
856+ Shortcuts for all WinPython launchers will be removed
857+ from {bold}WinPython{unbold} Start menu group."
858+ .'''
831859
832860 parser = ArgumentParser (
833861 description = "WinPython Package Manager: view, install, "
834862 "uninstall or upgrade Python packages on a Windows "
835- "Python distribution like WinPython."
863+ "Python distribution like WinPython." ,
864+ formatter_class = RawTextHelpFormatter
836865 )
837866 parser .add_argument (
838867 'fname' ,
839868 metavar = 'package' ,
840- type = str if py3compat .PY3 else unicode ,
869+ nargs = '?' ,
870+ default = '' ,
871+ type = str ,
841872 help = 'path to a Python package, or package name' ,
842873 )
843874 parser .add_argument (
@@ -891,13 +922,33 @@ def main(test=False):
891922 type = int , default = 2 ,
892923 help = 'show l levels_of_depth' ,
893924 )
925+ parser .add_argument (
926+ '--register' ,
927+ dest = 'registerWinPython' ,
928+ action = 'store_const' ,
929+ const = True ,
930+ default = False ,
931+ help = registerWinPythonHelp ,
932+ )
933+ parser .add_argument (
934+ '--unregister' ,
935+ dest = 'unregisterWinPython' ,
936+ action = 'store_const' ,
937+ const = True ,
938+ default = False ,
939+ help = unregisterWinPythonHelp ,
940+ )
894941
895942 args = parser .parse_args ()
896943
897944 if args .install and args .uninstall :
898945 raise RuntimeError (
899946 "Incompatible arguments: --install and --uninstall"
900947 )
948+ if args .registerWinPython and args .unregisterWinPython :
949+ raise RuntimeError (
950+ "Incompatible arguments: --install and --uninstall"
951+ )
901952 if args .pipdown :
902953 pip = piptree .pipdata ()
903954 pack , extra , * other = (args .fname + "[" ).replace (']' ,'[' ).split ("[" )
@@ -908,10 +959,40 @@ def main(test=False):
908959 pack , extra , * other = (args .fname + "[" ).replace (']' ,'[' ).split ("[" )
909960 pip .up (pack , extra , args .levels_of_depth )
910961 sys .exit ()
962+ if args .registerWinPython :
963+ print (registerWinPythonHelp )
964+ if utils .is_python_distribution (args .target ):
965+ dist = Distribution (args .target )
966+ else :
967+ raise WindowsError ("Invalid Python distribution {args.target}" )
968+ print (f'registering { args .target } ' )
969+ print ('continue ? Y/N' )
970+ theAnswer = input ()
971+ if theAnswer == 'Y' :
972+ from winpython import associate
973+ associate .register (dist .target )
974+ sys .exit ()
975+ if args .unregisterWinPython :
976+ print (unregisterWinPythonHelp )
977+ if utils .is_python_distribution (args .target ):
978+ dist = Distribution (args .target )
979+ else :
980+ raise WindowsError ("Invalid Python distribution {args.target}" )
981+ print (f'unregistering { args .target } ' )
982+ print ('continue ? Y/N' )
983+ theAnswer = input ()
984+ if theAnswer == 'Y' :
985+ from winpython import associate
986+ associate .unregister (dist .target )
987+ sys .exit ()
911988 elif not args .install and not args .uninstall :
912989 args .install = True
913990 if not osp .isfile (args .fname ) and args .install :
914- raise IOError ("File not found: %s" % args .fname )
991+ if args .fname == "" :
992+ parser .print_help ()
993+ sys .exit ()
994+ else :
995+ raise IOError ("File not found: %s" % args .fname )
915996 if utils .is_python_distribution (args .target ):
916997 dist = Distribution (args .target )
917998 try :
0 commit comments