Skip to content

Commit c8d6b36

Browse files
committed
updates
1 parent 87663f9 commit c8d6b36

File tree

2 files changed

+48
-30
lines changed

2 files changed

+48
-30
lines changed

getjobs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,17 @@ def printEnvInfoNoDataAPI(ManageProjectName, printData = True, printEnvType = Fa
232232

233233
def printEnvironmentInfo(ManageProjectName, printData = True, printEnvType = False):
234234
try:
235+
235236
from vector.apps.DataAPI.vcproject_api import VCProjectApi
236-
with VCProjectApi(ManageProjectName) as vcproj:
237-
ret_info = printEnvInfoDataAPI(vcproj, printData, printEnvType)
238-
237+
api = VCProjectApi(ManageProjectName)
238+
ret_info = printEnvInfoDataAPI(api, printData, printEnvType)
239+
api.close()
239240
return ret_info
241+
240242

241-
except Exception as e:
242-
print(e)
243+
except:
243244
return printEnvInfoNoDataAPI(ManageProjectName, printData, printEnvType)
244-
245-
245+
246246
if __name__ == "__main__":
247247
import argparse
248248
parser = argparse.ArgumentParser()

incremental_build_report_aggregator.py

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,30 @@ def log(msg, level="info"):
177177

178178
# Parse with fallback encodings
179179
try:
180-
main_soup = BeautifulSoup(raw, features="lxml", from_encoding=encFmt)
181-
except Exception as e1:
182-
log("[WARN] Parsing with {} failed: {}".format(encFmt, e1))
180+
# First attempt: use lxml if available, else let BS pick
183181
try:
184-
main_soup = BeautifulSoup(raw, features="lxml", from_encoding="utf-8")
185-
log("[INFO] Parsed successfully with UTF-8 fallback.")
186-
except Exception as e2:
187-
log("[ERROR] UTF-8 parse also failed: {}".format(e2))
188-
main_soup = BeautifulSoup(raw, features="lxml", from_encoding=encFmt)
189-
log("[INFO] Retrying parse with original encoding fallback.")
182+
import lxml # noqa
183+
parser = "lxml"
184+
except ImportError:
185+
parser = "html.parser"
186+
187+
main_soup = BeautifulSoup(raw, features=parser)
188+
189+
except Exception:
190+
try:
191+
# Fallback to UTF-8
192+
main_soup = BeautifulSoup(
193+
raw.encode("utf-8", "replace"),
194+
features=parser
195+
)
196+
except Exception:
197+
# Final fallback: use whatever parser is available, no feature string
198+
main_soup = BeautifulSoup(
199+
raw.encode(encFmt, "replace")
200+
)
190201

191202
if len(main_soup.find_all('table')) < 1:
192-
raise Exception("No <table> elements found in {}".format(current_file))
203+
raise LookupError("No <table> elements found in {}".format(current_file))
193204

194205
if main_soup.find(id="report-title"):
195206
main_manage_api_report = True
@@ -250,20 +261,27 @@ def log(msg, level="info"):
250261

251262
soup = None
252263
try:
253-
soup = BeautifulSoup(raw, features="lxml", from_encoding=encFmt)
254-
except Exception as e1:
255-
log("[WARN] Parsing with {} failed: {}".format(encFmt, e1))
264+
# First attempt: use lxml if available, else let BS pick
256265
try:
257-
soup = BeautifulSoup(raw, features="lxml", from_encoding="utf-8")
258-
log("[INFO] Parsed successfully with UTF-8 fallback.")
259-
except Exception as e2:
260-
log("[ERROR] UTF-8 parse failed: {}".format(e2))
261-
try:
262-
soup = BeautifulSoup(raw, features="lxml", from_encoding=encFmt)
263-
log("[INFO] Retried parse with {} encoding.".format(encFmt))
264-
except Exception as e3:
265-
log("[FATAL] Could not parse report '{}': {}".format(file, e3))
266-
continue
266+
import lxml # noqa
267+
parser = "lxml"
268+
except ImportError:
269+
parser = "html.parser"
270+
271+
soup = BeautifulSoup(raw, features=parser)
272+
273+
except Exception:
274+
try:
275+
# Fallback to UTF-8
276+
soup = BeautifulSoup(
277+
raw.encode("utf-8", "replace"),
278+
features=parser
279+
)
280+
except Exception:
281+
# Final fallback: use whatever parser is available, no feature string
282+
soup = BeautifulSoup(
283+
raw.encode(encFmt, "replace")
284+
)
267285

268286
try:
269287
if soup.find(id="report-title"):

0 commit comments

Comments
 (0)