SEMAFORInformatik / femagtools

Python API for FEMAG
BSD 2-Clause "Simplified" License
19 stars 13 forks source link

Read values from logfile 'FEMAG-FSL.log' #15

Closed bhzunami closed 7 years ago

bhzunami commented 7 years ago

Read a value from logfile with a given regex/pattern

read_from_log(pattern):
    result=[]
    pat=re.compile(pattern)
    with open(os.path.join(self.workdir, 'FEMAG-FSL.log')) as f:
        for line in f:
            m = pat.search(line)
            if m:
                result.append(float(line.split(':')[-1].split()[0]) )
    return result
ronaldtanner commented 7 years ago

probably as a new member function of Femag-class? As currently needed by femagtest to figure out the model name

  with open(os.path.join(self.workdir,
                        'FEMAG-FSL.log')) as f:
            for l in f:
                if l.startswith('New model') or l.startswith('Load model'):
                    model = l.split()[2].replace('"', '').replace(',', '')
                    break