Skip to content

Commit a77b79f

Browse files
authored
Merge pull request #20 from arossert/get_windows_updates_allow_errors
Add the option to ignore errors when getting windows updates
2 parents fa5f6b8 + cb66640 commit a77b79f

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

windows_tools/updates/__init__.py

Lines changed: 33 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,9 @@ 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,
223+
include_all_states: bool = False,
224+
allow_errors: bool = False,
220225
):
221226
"""
222227
Let's get windows updates from multiple sources
@@ -225,13 +230,33 @@ def get_windows_updates(
225230
WMI method has some info
226231
REG method has only install date and KB number info
227232
"""
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-
)
233+
try:
234+
wmi_update_list = get_windows_updates_wmi()
235+
except Exception as e:
236+
if not allow_errors:
237+
raise e
238+
logger.warning("Failed to get WMI updates: %s", str(e))
239+
wmi_update_list = []
240+
241+
try:
242+
com_update_list = get_windows_updates_com(
243+
filter_duplicates=filter_duplicates, include_all_states=include_all_states
244+
)
245+
except Exception as e:
246+
if not allow_errors:
247+
raise e
248+
logger.warning("Failed to get COM updates: %s", str(e))
249+
com_update_list = []
250+
251+
try:
252+
reg_update_list = get_windows_updates_reg(
253+
filter_duplicates=filter_duplicates, include_all_states=include_all_states
254+
)
255+
except Exception as e:
256+
if not allow_errors:
257+
raise e
258+
logger.warning("Failed to get REG updates: %s", str(e))
259+
reg_update_list = []
235260

236261
updates = com_update_list
237262
if filter_duplicates:

0 commit comments

Comments
 (0)