|
14 | 14 | import os |
15 | 15 | from pathlib import Path |
16 | 16 | import platform |
| 17 | +import importlib |
17 | 18 |
|
18 | 19 | # import subprocess |
19 | 20 |
|
@@ -75,7 +76,8 @@ def register(target, current=True, verbose=True): |
75 | 76 | root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE |
76 | 77 |
|
77 | 78 | # Creating Registry entries |
78 | | - print(f'Creating WinPython registry entries for {target}') |
| 79 | + if verbose: |
| 80 | + print(f'Creating WinPython registry entries for {target}') |
79 | 81 | # Extensions |
80 | 82 | winreg.SetValueEx( |
81 | 83 | winreg.CreateKey(root, KEY_C % ".py"), |
@@ -335,15 +337,20 @@ def register(target, current=True, verbose=True): |
335 | 337 | ) |
336 | 338 |
|
337 | 339 | # Create start menu entries for all WinPython launchers |
338 | | - print(f'Creating WinPython menu for all icons in {target}') |
| 340 | + spec = importlib.util.find_spec('pythoncom') |
| 341 | + if verbose and spec is None: |
| 342 | + print(f"Can't create WinPython menu as pywin32 package is not installed") |
| 343 | + if verbose and spec is not None: |
| 344 | + print(f'Creating WinPython menu for all icons in {target}') |
339 | 345 | for path, desc, fname in _get_shortcut_data(target, current=current): |
340 | 346 | utils.create_shortcut(path, desc, fname, verbose=verbose) |
341 | 347 |
|
342 | 348 |
|
343 | 349 | def unregister(target, current=True, verbose=True): |
344 | 350 | """Unregister a Python distribution in Windows registry""" |
345 | 351 | # Removing Registry entries |
346 | | - print(f'Removing WinPython registry entries for {target}') |
| 352 | + if verbose: |
| 353 | + print(f'Removing WinPython registry entries for {target}') |
347 | 354 | root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE |
348 | 355 | short_version = utils.get_python_infos(target)[0] |
349 | 356 | key_core = (KEY_S1 % short_version) + r"\%s" |
@@ -406,7 +413,11 @@ def unregister(target, current=True, verbose=True): |
406 | 413 | file=sys.stderr, |
407 | 414 | ) |
408 | 415 | # remove menu shortcuts |
409 | | - print(f'Removing WinPython menu for all icons in {target}') |
| 416 | + spec = importlib.util.find_spec('pythoncom') |
| 417 | + if verbose and spec is None: |
| 418 | + print(f"Can't remove WinPython menu as pywin32 package is not installed") |
| 419 | + if verbose and spec is not None: |
| 420 | + print(f'Removing WinPython menu for all icons in {target}') |
410 | 421 | _remove_start_menu_folder(target, current=current) |
411 | 422 |
|
412 | 423 | #for path, desc, fname in _get_shortcut_data(target, current=current): |
|
0 commit comments