From 4cfdba76911ad0c438a4137626b8e42f0a2368bc Mon Sep 17 00:00:00 2001 From: Ask Hjorth Larsen <asklarsen@gmail.com> Date: Wed, 6 Jul 2016 19:30:06 +0200 Subject: [PATCH] probably fix errors --- .../parser-octopus/octopus_logfile_parser.py | 5 ++-- parser/parser-octopus/parser_octopus.py | 26 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/parser/parser-octopus/octopus_logfile_parser.py b/parser/parser-octopus/octopus_logfile_parser.py index 72569b0..46c0496 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 53eb043..e1a084a 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) -- GitLab