Skip to content

Commit 38d63b2

Browse files
committed
Add the option to ignore errors when getting windows updates
Signed-off-by: Amir Rossert <[email protected]>
1 parent fa5f6b8 commit 38d63b2

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

windows_tools/updates/__init__.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
__build__ = "2023050601"
2424

2525
import re
26+
import logging
2627
from win32com import client
2728
import dateutil.parser
2829
from windows_tools import wmi_queries
2930
from windows_tools import registry
3031

3132

33+
logger = logging.getLogger(__intname__)
34+
3235
# As of 2021, KB numbers go up to 7 digits
3336
KB_REGEX = re.compile(r"KB[0-9]{5,7}", re.IGNORECASE)
3437

@@ -216,7 +219,7 @@ def get_windows_updates_reg(
216219

217220

218221
def get_windows_updates(
219-
filter_duplicates: bool = True, include_all_states: bool = False
222+
filter_duplicates: bool = True, include_all_states: bool = False, allow_errors: bool =False
220223
):
221224
"""
222225
Let's get windows updates from multiple sources
@@ -225,13 +228,33 @@ def get_windows_updates(
225228
WMI method has some info
226229
REG method has only install date and KB number info
227230
"""
228-
wmi_update_list = get_windows_updates_wmi()
229-
com_update_list = get_windows_updates_com(
230-
filter_duplicates=filter_duplicates, include_all_states=include_all_states
231-
)
232-
reg_update_list = get_windows_updates_reg(
233-
filter_duplicates=filter_duplicates, include_all_states=include_all_states
234-
)
231+
try:
232+
wmi_update_list = get_windows_updates_wmi()
233+
except Exception as e:
234+
if not allow_errors:
235+
raise e
236+
logger.warning("Failed to get WMI updates: %s", str(e))
237+
wmi_update_list = []
238+
239+
try:
240+
com_update_list = get_windows_updates_com(
241+
filter_duplicates=filter_duplicates, include_all_states=include_all_states
242+
)
243+
except Exception as e:
244+
if not allow_errors:
245+
raise e
246+
logger.warning("Failed to get COM updates: %s", str(e))
247+
com_update_list = []
248+
249+
try:
250+
reg_update_list = get_windows_updates_reg(
251+
filter_duplicates=filter_duplicates, include_all_states=include_all_states
252+
)
253+
except Exception as e:
254+
if not allow_errors:
255+
raise e
256+
logger.warning("Failed to get REG updates: %s", str(e))
257+
reg_update_list = []
235258

236259
updates = com_update_list
237260
if filter_duplicates:

0 commit comments

Comments
 (0)