diff --git a/parser/parser-octopus/octopus_logfile_parser.py b/parser/parser-octopus/octopus_logfile_parser.py index 72569b06b2ca2daaffa0c3cf8998779b020e515b..46c0496bf7974fcf35ba7666f92781bd1d5ebcda 100644 --- a/parser/parser-octopus/octopus_logfile_parser.py +++ b/parser/parser-octopus/octopus_logfile_parser.py @@ -32,8 +32,9 @@ def parse_logfile(meta_info_env, pew, fname): # XXX this is just a hack until we decide to do more maxlines = 100 with open(fname) as fd: - for i in range(maxlines): - line = next(fd) + for i, line in enumerate(fd): + if i > maxlines: + break if line.startswith('Version'): version = line.split()[-1] pew.addValue('program_version', version) diff --git a/parser/parser-octopus/parser_octopus.py b/parser/parser-octopus/parser_octopus.py index 53eb0432c7fa577909be0b18db88df9e58ed52bd..e1a084a29e6a139fa6085bd8f04811bbe1d60719 100644 --- a/parser/parser-octopus/parser_octopus.py +++ b/parser/parser-octopus/parser_octopus.py @@ -106,8 +106,9 @@ def read_input_file(path): def is_octopus_logfile(fname): fd = open(fname) - for lineno in range(20): - line = next(fd) + for n, line in enumerate(fd): + if n > 20: + break if '|0) ~ (0) |' in line: # Eyes from Octopus logo return True return False @@ -210,6 +211,13 @@ def register_octopus_keywords(pew, category, kwargs): def parse(fname, fd): + # Look for files before we create some of our own files for logging etc.: + staticdirname, _basefname = os.path.split(fname) + dirname, _static = os.path.split(staticdirname) + inp_path = os.path.join(dirname, 'inp') + parser_log_path = os.path.join(dirname, 'exec', 'parser.log') + logfile = find_octopus_logfile(dirname) + # fname refers to the static/info file. pew = JsonParseEventsWriterBackend(metaInfoEnv) pew.startedParsingSession(fname, parser_info) @@ -227,11 +235,6 @@ def parse(fname, fd): pew.addValue('program_name', 'Octopus') print(file=fd) - staticdirname, _basefname = os.path.split(fname) - dirname, _static = os.path.split(staticdirname) - inp_path = os.path.join(dirname, 'inp') - parser_log_path = os.path.join(dirname, 'exec', 'parser.log') - print('Read Octopus keywords from input file %s' % inp_path, file=fd) kwargs = read_input_file(inp_path) @@ -263,13 +266,12 @@ def parse(fname, fd): nspins = calc.get_number_of_spins() nkpts = len(calc.get_k_point_weights()) - logfile = find_octopus_logfile(dirname) if logfile is None: print('No stdout logfile found', file=fd) else: print('Found stdout logfile %s' % logfile, file=fd) - #print('Parse logfile using SimpleMatcher', file=fd) - #parse_logfile(metaInfoEnv, pew, logfile) + print('Parse logfile %s' % logfile, file=fd) + parse_logfile(metaInfoEnv, pew, logfile) print('Add parsed values', file=fd) with open_section('section_system'): @@ -289,8 +291,8 @@ def parse(fname, fd): np.array(atoms.pbc)) with open_section('section_single_configuration_calculation'): - #print('Parse info file using SimpleMatcher', file=fd) - #parse_infofile(metaInfoEnv, pew, fname) + print('Parse info file %s' % fname, file=fd) + parse_infofile(metaInfoEnv, pew, fname) with open_section('section_method'): pew.addValue('number_of_spin_channels', nspins)