26
26
from winpython .py3compat import configparser as cp
27
27
28
28
# from former wppm separate script launcher
29
- from argparse import ArgumentParser
29
+ import textwrap
30
+ from argparse import ArgumentParser , HelpFormatter , RawTextHelpFormatter
30
31
from winpython import py3compat
31
32
32
33
from winpython import piptree
@@ -113,6 +114,7 @@ def get_package_metadata(database, name, gotoWWW=False, update=False):
113
114
except :
114
115
pass
115
116
return my_metadata
117
+
116
118
117
119
class BasePackage (object ):
118
120
def __init__ (self , fname ):
@@ -828,16 +830,45 @@ def main(test=False):
828
830
# dist.install(pack)
829
831
# dist.uninstall(pack)
830
832
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
+ .'''
831
859
832
860
parser = ArgumentParser (
833
861
description = "WinPython Package Manager: view, install, "
834
862
"uninstall or upgrade Python packages on a Windows "
835
- "Python distribution like WinPython."
863
+ "Python distribution like WinPython." ,
864
+ formatter_class = RawTextHelpFormatter
836
865
)
837
866
parser .add_argument (
838
867
'fname' ,
839
868
metavar = 'package' ,
840
- type = str if py3compat .PY3 else unicode ,
869
+ nargs = '?' ,
870
+ default = '' ,
871
+ type = str ,
841
872
help = 'path to a Python package, or package name' ,
842
873
)
843
874
parser .add_argument (
@@ -891,13 +922,33 @@ def main(test=False):
891
922
type = int , default = 2 ,
892
923
help = 'show l levels_of_depth' ,
893
924
)
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
+ )
894
941
895
942
args = parser .parse_args ()
896
943
897
944
if args .install and args .uninstall :
898
945
raise RuntimeError (
899
946
"Incompatible arguments: --install and --uninstall"
900
947
)
948
+ if args .registerWinPython and args .unregisterWinPython :
949
+ raise RuntimeError (
950
+ "Incompatible arguments: --install and --uninstall"
951
+ )
901
952
if args .pipdown :
902
953
pip = piptree .pipdata ()
903
954
pack , extra , * other = (args .fname + "[" ).replace (']' ,'[' ).split ("[" )
@@ -908,10 +959,40 @@ def main(test=False):
908
959
pack , extra , * other = (args .fname + "[" ).replace (']' ,'[' ).split ("[" )
909
960
pip .up (pack , extra , args .levels_of_depth )
910
961
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 ()
911
988
elif not args .install and not args .uninstall :
912
989
args .install = True
913
990
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 )
915
996
if utils .is_python_distribution (args .target ):
916
997
dist = Distribution (args .target )
917
998
try :
0 commit comments