8000 a less verbose --register and --unregister by stonebig · Pull Request #1310 · winpython/winpython · GitHub
[go: up one dir, main page]

Skip to content

a less verbose --register and --unregister #1310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__ = '7.5.20240401'
__version__ = '7.5.20240410'
__license__ = __doc__
__project_url__ = 'http://winpython.github.io/'
19 changes: 13 additions & 6 deletions winpython/associate.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ def _get_shortcut_data(target, current=True):
return data


def register(target, current=True):
def register(target, current=True, verbose=True):
"""Register a Python distribution in Windows registry"""
root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE

# Creating Registry entries
print(f'Creating WinPython registry entries for {target}')
# Extensions
winreg.SetValueEx(
winreg.CreateKey(root, KEY_C % ".py"),
Expand Down Expand Up @@ -333,13 +335,15 @@ def register(target, current=True):
)

# Create start menu entries for all WinPython launchers
print(f'Creating WinPython menu for all icons in {target}')
for path, desc, fname in _get_shortcut_data(target, current=current):
utils.create_shortcut(path, desc, fname)
utils.create_shortcut(path, desc, fname, verbose=verbose)


def unregister(target, current=True):
def unregister(target, current=True, verbose=True):
"""Unregister a Python distribution in Windows registry"""
# Registry entries
# Removing Registry entries
print(f'Removing WinPython registry entries for {target}')
root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
short_version = utils.get_python_infos(target)[0]
key_core = (KEY_S1 % short_version) + r"\%s"
Expand Down Expand Up @@ -391,15 +395,18 @@ def unregister(target, current=True):
KEY_S,
):
try:
print(key)
if verbose:
print(key)
winreg.DeleteKey(root, key)
except WindowsError:
rootkey = "HKEY_CURRENT_USER" if current else "HKEY_LOCAL_MACHINE"
print(
if verbose:
print(
r"Unable to remove %s\%s" % (rootkey, key),
file=sys.stderr,
)
# remove menu shortcuts
print(f'Removing WinPython menu for all icons in {target}')
_remove_start_menu_folder(target, current=current)

#for path, desc, fname in _get_shortcut_data(target, current=current):
Expand Down
8 changes: 5 additions & 3 deletions winpython/utils.py
Expand Down Expand Up
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_winpython_start_menu_folder(current=True):
return str(Path(folder) / 'WinPython')

def remove_winpython_start_menu_folder(current=True):
"""Create WinPython Start menu folder -- remove it if it already exists"""
"""Remove WinPython Start menu folder -- remove it if it already exists"""
path = get_winpython_start_menu_folder(current=current)
if Path(path).is_dir():
try:
@@ -249,6 +249,7 @@ def create_shortcut(
workdir="",
iconpath="",
iconindex=0,
verbose=True,
):
"""Create Windows shortcut (.lnk file)"""
import pythoncom
Expand All @@ -272,7 +273,8 @@ def create_shortcut(
ipf = ilink.QueryInterface(pythoncom.IID_IPersistFile)
if not filename.endswith('.lnk'):
filename += '.lnk'
print(f'ipf.save *{filename}*')
if verbose:
print(f'create menu *{filename}*')
try:
ipf.Save(filename, 0)
except:
Expand Down Expand Up @@ -386,7 +388,7 @@ def python_query(cmd, path):
"""Execute Python command using the Python interpreter located in *path*"""
the_exe = get_python_executable(path)
# debug2021-09-12
print(f'"{the_exe}" -c "{cmd}"', ' * ', path)
# print(f'"{the_exe}" -c "{cmd}"', ' * ', path)
return exec_shell_cmd(f'"{the_exe}" -c "{cmd}"', path).splitlines()[0]

def python_execmodule(cmd, path):
Expand Down
4 changes: 2 additions & 2 deletions winpython/wppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ def main(test=False):
if theAnswer == "Y":
from winpython import associate

associate.register(dist.target)
associate.register(dist.target, verbose=args.verbose)
sys.exit()
if args.unregisterWinPython:
print(unregisterWinPythonHelp)
Expand All @@ -908,7 +908,7 @@ def main(test=False):
if theAnswer == "Y":
from winpython import associate

associate.unregister(dist.target)
associate.unregister(dist.target, verbose=args.verbose)
sys.exit()
elif not args.install and not args.uninstall:
args.install = True
Expand Down
0