|
2 | 2 | from __future__ import annotations |
3 | 3 |
|
4 | 4 | import argparse |
| 5 | +import contextlib |
5 | 6 | import importlib.resources |
6 | 7 | import importlib.util |
7 | 8 | import os |
@@ -378,19 +379,15 @@ def refresh_desktop_database(self) -> None: |
378 | 379 | command = shutil.which("update-desktop-database") |
379 | 380 | if not command: |
380 | 381 | return |
381 | | - try: |
| 382 | + with contextlib.suppress(OSError): |
382 | 383 | subprocess.run([command, str(self.applications_dir)], check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
383 | | - except OSError: |
384 | | - pass |
385 | 384 |
|
386 | 385 | def apply_xdg_default(self, mime: str) -> None: |
387 | 386 | command = shutil.which("xdg-mime") |
388 | 387 | if not command: |
389 | 388 | return |
390 | | - try: |
| 389 | + with contextlib.suppress(OSError): |
391 | 390 | subprocess.run([command, "default", DESKTOP_ID, mime], check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
392 | | - except OSError: |
393 | | - pass |
394 | 391 |
|
395 | 392 | def write_bridge_files(self, definitions: Iterable[ProtocolDef]) -> None: |
396 | 393 | self.check_expected_runtime() |
@@ -686,10 +683,8 @@ def delete_handler_registration(self, definition: ProtocolDef) -> None: |
686 | 683 | def delete_expected_key(self, root, path: str, root_path: str) -> None: # noqa: ANN001 - winreg root type is platform-only |
687 | 684 | if not self.safe_delete_path(root, path, root_path): |
688 | 685 | return |
689 | | - try: |
| 686 | + with contextlib.suppress(OSError): |
690 | 687 | self.winreg.DeleteKey(root, path) |
691 | | - except OSError: |
692 | | - pass |
693 | 688 |
|
694 | 689 | def safe_delete_path(self, root, path: str, root_path: str) -> bool: # noqa: ANN001 - winreg root type is platform-only |
695 | 690 | if root != self.winreg.HKEY_CURRENT_USER: |
@@ -949,19 +944,15 @@ def register_app_bundle(self) -> None: |
949 | 944 | command = self.lsregister_command() |
950 | 945 | if not command or not self.app_bundle.exists(): |
951 | 946 | return |
952 | | - try: |
| 947 | + with contextlib.suppress(OSError): |
953 | 948 | subprocess.run([command, "-f", str(self.app_bundle)], check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
954 | | - except OSError: |
955 | | - pass |
956 | 949 |
|
957 | 950 | def unregister_app_bundle(self) -> None: |
958 | 951 | command = self.lsregister_command() |
959 | 952 | if not command or not self.app_bundle.exists(): |
960 | 953 | return |
961 | | - try: |
| 954 | + with contextlib.suppress(OSError): |
962 | 955 | subprocess.run([command, "-u", str(self.app_bundle)], check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
963 | | - except OSError: |
964 | | - pass |
965 | 956 |
|
966 | 957 | class _LaunchServices: |
967 | 958 | ENCODING_UTF8 = 0x08000100 |
|
0 commit comments