Skip to content

Commit

Permalink
baby step to 'registering' well
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebig committed Oct 30, 2022
1 parent 61b464f commit 6647cda
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 5 deletions.
2 changes: 1 addition & 1 deletion winpython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
OTHER DEALINGS IN THE SOFTWARE.
"""

__version__ = '5.0.20221023'
__version__ = '5.1.20221030'
__license__ = __doc__
__project_url__ = 'http://winpython.github.io/'
89 changes: 85 additions & 4 deletions winpython/wppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from winpython.py3compat import configparser as cp

# from former wppm separate script launcher
from argparse import ArgumentParser
import textwrap
from argparse import ArgumentParser, HelpFormatter, RawTextHelpFormatter
from winpython import py3compat

from winpython import piptree
Expand Down Expand Up @@ -113,6 +114,7 @@ def get_package_metadata(database, name, gotoWWW=False, update=False):
except:
pass
return my_metadata


class BasePackage(object):
def __init__(self, fname):
Expand Down Expand Up @@ -828,16 +830,45 @@ def main(test=False):
# dist.install(pack)
# dist.uninstall(pack)
else:
bold = "\033[1m"
unbold = "\033[0m"
registerWinPythonHelp = f'''Register distribution
({bold}experimental{unbold})
This will associate file extensions, icons and
Windows explorer's context menu entries ('Edit with IDLE', ...)
with selected Python distribution in Windows registry.
Shortcuts for all WinPython launchers will be installed
in {unbold}WinPython{unbold} Start menu group (replacing existing
shortcuts).
{bold}Note{unbold}: these actions are similar to those performed
when installing old Pythons with the official installer before 'py'
.
'''

unregisterWinPythonHelp = '''Unregister distribution
({bold}experimental{unbold})
This will remove file extensions associations, icons and
Windows explorer's context menu entries ('Edit with IDLE', ...)
with selected Python distribution in Windows registry.
Shortcuts for all WinPython launchers will be removed
from {bold}WinPython{unbold} Start menu group."
.'''

parser = ArgumentParser(
description="WinPython Package Manager: view, install, "
"uninstall or upgrade Python packages on a Windows "
"Python distribution like WinPython."
"Python distribution like WinPython.",
formatter_class=RawTextHelpFormatter
)
parser.add_argument(
'fname',
metavar='package',
type=str if py3compat.PY3 else unicode,
nargs='?',
default='',
type=str,
help='path to a Python package, or package name',
)
parser.add_argument(
Expand Down Expand Up @@ -891,13 +922,33 @@ def main(test=False):
type=int, default=2,
help='show l levels_of_depth',
)
parser.add_argument(
'--register',
dest='registerWinPython',
action='store_const',
const=True,
default=False,
help=registerWinPythonHelp,
)
parser.add_argument(
'--unregister',
dest='unregisterWinPython',
action='store_const',
const=True,
default=False,
help=unregisterWinPythonHelp,
)

args = parser.parse_args()

if args.install and args.uninstall:
raise RuntimeError(
"Incompatible arguments: --install and --uninstall"
)
if args.registerWinPython and args.unregisterWinPython:
raise RuntimeError(
"Incompatible arguments: --install and --uninstall"
)
if args.pipdown:
pip = piptree.pipdata()
pack, extra, *other =(args.fname +"[").replace(']','[').split("[")
Expand All @@ -908,10 +959,40 @@ def main(test=False):
pack, extra, *other =(args.fname +"[").replace(']','[').split("[")
pip.up(pack, extra, args.levels_of_depth)
sys.exit()
if args.registerWinPython:
print(registerWinPythonHelp)
if utils.is_python_distribution(args.target):
dist = Distribution(args.target)
else:
raise WindowsError("Invalid Python distribution {args.target}")
print(f'registering {args.target}')
print('continue ? Y/N')
theAnswer=input()
if theAnswer=='Y':
from winpython import associate
associate.register(dist.target)
sys.exit()
if args.unregisterWinPython:
print(unregisterWinPythonHelp)
if utils.is_python_distribution(args.target):
dist = Distribution(args.target)
else:
raise WindowsError("Invalid Python distribution {args.target}")
print(f'unregistering {args.target}')
print('continue ? Y/N')
theAnswer=input()
if theAnswer=='Y':
from winpython import associate
associate.unregister(dist.target)
sys.exit()
elif not args.install and not args.uninstall:
args.install = True
if not osp.isfile(args.fname) and args.install:
raise IOError("File not found: %s" % args.fname)
if args.fname=="":
parser.print_help()
sys.exit()
else:
raise IOError("File not found: %s" % args.fname)
if utils.is_python_distribution(args.target):
dist = Distribution(args.target)
try:
Expand Down

0 comments on commit 6647cda

Please sign in to comment.