Exemplo n.º 1
0
def summarise_junit(file_path: str) -> bool:
    """Parse jUnit output and show a summary.

    Preprocesses input to increase the chances of getting valid XML.
    Returns True if there were no failures or errors, raises exception
    on IOError or XML parse errors."""

    with open(file_path, 'r') as file:
        # Skip log text before and after the XML, escape some of the test output to get valid XML
        lines = StringIO()
        take = False
        for line in file:
            if line.strip() == '<testsuite>':
                take = True
            if take:
                lines.write(line.replace('<<', '&lt;&lt;'))
            if line.strip() == "</testsuite>":
                break

        xml = JUnitXml.fromstring(strip_ansi(lines.getvalue()))

        print("")
        print("Test summary")
        print("------------")
        print(f"tests:    {xml.tests}")
        print(f"skipped:  {xml.skipped}")
        print(f"failures: {xml.failures}")
        print(f"errors:   {xml.errors}\n")

        return xml.failures == 0 and xml.errors == 0
Exemplo n.º 2
0
def main():
    # ファイル選択ダイアログの表示
    root = tkinter.Tk()
    root.withdraw()

    fTyp = [("", "*")]

    iDir = os.path.abspath(os.path.dirname(__file__))
    filename = tkinter.filedialog.askopenfilename(filetypes=fTyp,
                                                  initialdir=iDir)

    target = []
    plain = []
    with open(filename, "r", encoding="utf8") as fobj:
        for i, l in enumerate(fobj, 1):
            str = strip_ansi(l)
            if '"patientList"' not in str and '"queryList"' not in str:
                plain.append(str)
            if 'ERROR' in str and not 'The Network Adapter could not establish the connection' in str:
                target.append(i)
    target = reduce(
        lambda acc, n: acc + [n]
        if not any(e < n + 1000 and e > n - 1000 for e in acc) else acc,
        target, [])
    dirname = filename.split('/').pop()
    os.makedirs(dirname, exist_ok=True)
    for i, t in enumerate(target):
        with open(f'/out/{dirname}/result{i:02}.log', "w",
                  encoding="utf8") as wf:
            start = t - 1000 if t - 1000 > 0 else 0
            end = t + 1000 if t + 1000 <= len(plain) else len(plain)
            for s in plain[start:end]:
                wf.write(s)
Exemplo n.º 3
0
def main():
    cmd = 'top -n 2'
    child = pexpect.spawn(cmd,
                          timeout=2,
                          encoding='utf-8',
                          env={"TERM": "dumb"})
    child.send('2')
    info = child.read()
    a = info.split('\n')
    numacpunodes = []
    for line in a:
        if (line.find("%Node") == 0):
            #print(strip_ansi(line))
            newline = strip_ansi(line).split()
            numacpunodes.append(strip_ansi(newline[0]).strip('%'))

    data = [{"{#NUMACPUNODENAME}": cpunode} for cpunode in numacpunodes]
    print(json.dumps({"data": data}, indent=4))
Exemplo n.º 4
0
def generate_packet(hostname):
    packet = []
    cmd = 'top -n 2 -d 10'
    child = pexpect.spawn(cmd,
                          timeout=10,
                          encoding='utf-8',
                          env={"TERM": "dumb"})
    child.send('2')
    time.sleep(1)
    info = child.read()
    #logger.info('%s!', info)
    child.close()
    a = info.split('\n')
    for line in a:
        if (line.find("%Node") == 0):
            newline = re.split(r':|,', strip_ansi(line))
            #logger.info('%s!', newline)
            cpunode = newline[0].strip().strip('%')
            packet.append(
                ZabbixMetric(hostname, "cpu.numa.us.[%s]" % cpunode,
                             newline[1].strip().split()[0]))
            packet.append(
                ZabbixMetric(hostname, "cpu.numa.sy.[%s]" % cpunode,
                             newline[2].strip().split()[0]))
            packet.append(
                ZabbixMetric(hostname, "cpu.numa.ni.[%s]" % cpunode,
                             newline[3].strip().split()[0]))
            packet.append(
                ZabbixMetric(hostname, "cpu.numa.id.[%s]" % cpunode,
                             newline[4].strip().split()[0]))
            packet.append(
                ZabbixMetric(hostname, "cpu.numa.wa.[%s]" % cpunode,
                             newline[5].strip().split()[0]))
            packet.append(
                ZabbixMetric(hostname, "cpu.numa.hi.[%s]" % cpunode,
                             newline[6].strip().split()[0]))
            packet.append(
                ZabbixMetric(hostname, "cpu.numa.si.[%s]" % cpunode,
                             newline[7].strip().split()[0]))
            packet.append(
                ZabbixMetric(hostname, "cpu.numa.st.[%s]" % cpunode,
                             newline[8].strip().split()[0]))
    #logger.info('%s!', packet)
    return packet
Exemplo n.º 5
0
 def write_to_Serial_Output_Edit(self, data):
     cleaned_text = strip_ansi(data.decode('ascii')).strip()
     if (self.filterEnabled and self.filterString not in cleaned_text) or not self.filterEnabled:
         self.serialOutputEdit.appendPlainText(cleaned_text)
Exemplo n.º 6
0
 def write(self, data):
     self.stream.write(strip_ansi(data))
Exemplo n.º 7
0
def strwidth(o: str) -> int:
    return wcswidth(strip_ansi(o))