Source code for hwtBuildsystem.common.cmdResult
import re
from typing import List
[docs]class TclCmdResult():
"""
Parsed result of comand over cli
"""
ANY_COLOR = '((\033\[0m)?(\033\[0;(\d+)m)?\s*)?'
OPT_MSG_NUMBER = '(\s*\(\d+\))?'
regex_invalidCmd = re.compile("(invalid command name \".*\")")
regex_err = re.compile(f"{ANY_COLOR:s}ERROR{OPT_MSG_NUMBER:s}: (.*)")
regex_critWarn = re.compile(f"{ANY_COLOR:s}CRITICAL WARNING{OPT_MSG_NUMBER:s}: (.*)")
regex_warn = re.compile(f"{ANY_COLOR:s}WARNING{OPT_MSG_NUMBER:s}: (.*)")
regex_info = re.compile(f"{ANY_COLOR:s}INFO{OPT_MSG_NUMBER:s}: (.*)")
def __init__(self, cmd, resultText, errors, criticalWarnings, warnings, infos):
self.cmd = cmd
self.resultText = resultText
self.errors = errors
self.criticalWarnings = criticalWarnings
self.warnings = warnings
self.infos = infos
[docs] @classmethod
def fromStdoutStr(cls, cmd, text):
resultText = text
errors = []
criticalWarnings = []
warnings = []
infos = []
resultText = TclCmdResult.extractMsgs(resultText, TclCmdResult.regex_invalidCmd, 1, errors)
resultText = TclCmdResult.extractMsgs(resultText, TclCmdResult.regex_err, 6, errors)
resultText = TclCmdResult.extractMsgs(resultText, TclCmdResult.regex_critWarn, 6, criticalWarnings)
resultText = TclCmdResult.extractMsgs(resultText, TclCmdResult.regex_warn, 6, warnings)
resultText = TclCmdResult.extractMsgs(resultText, TclCmdResult.regex_info, 6, infos)
return cls(cmd, resultText.strip(), errors, criticalWarnings, warnings, infos)
[docs] def raiseOnErrors(self):
if self.errors:
raise TclToolErr(self)