Skip to content

Add the option to ignore errors when getting windows updates #20

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 2 commits into from
Dec 3, 2024
Merged
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
41 changes: 33 additions & 8 deletions windows_tools/updates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
__build__ = "2023050601"

import re
import logging
from win32com import client
import dateutil.parser
from windows_tools import wmi_queries
from windows_tools import registry


logger = logging.getLogger(__intname__)

# As of 2021, KB numbers go up to 7 digits
KB_REGEX = re.compile(r"KB[0-9]{5,7}", re.IGNORECASE)

Expand Down Expand Up @@ -216,7 +219,9 @@ def get_windows_updates_reg(


def get_windows_updates(
filter_duplicates: bool = True, include_all_states: bool = False
filter_duplicates: bool = True,
include_all_states: bool = False,
allow_errors: bool = False,
):
"""
Let's get windows updates from multiple sources
Expand All @@ -225,13 +230,33 @@ def get_windows_updates(
WMI method has some info
REG method has only install date and KB number info
"""
wmi_update_list = get_windows_updates_wmi()
com_update_list = get_windows_updates_com(
filter_duplicates=filter_duplicates, include_all_states=include_all_states
)
reg_update_list = get_windows_updates_reg(
filter_duplicates=filter_duplicates, include_all_states=include_all_states
)
try:
wmi_update_list = get_windows_updates_wmi()
except Exception as e:
if not allow_errors:
raise e
logger.warning("Failed to get WMI updates: %s", str(e))
wmi_update_list = []

try:
com_update_list = get_windows_updates_com(
filter_duplicates=filter_duplicates, include_all_states=include_all_states
)
except Exception as e:
if not allow_errors:
raise e
logger.warning("Failed to get COM updates: %s", str(e))
com_update_list = []

try:
reg_update_list = get_windows_updates_reg(
filter_duplicates=filter_duplicates, include_all_states=include_all_states
)
except Exception as e:
if not allow_errors:
raise e
logger.warning("Failed to get REG updates: %s", str(e))
reg_update_list = []

updates = com_update_list
if filter_duplicates:
Expand Down