#!/usr/bin/env python3 # -*- coding: utf-8 -*- import argparse import pandas as pd from svx_keywords import SvxReader parser = argparse.ArgumentParser(description='extract fixes from a survey tree') parser.add_argument('svxfile', help='input survex file, with or without .svx') args = parser.parse_args() results = [] with SvxReader(args.svxfile) as svx_reader: for record in svx_reader: if record.text.startswith('*fix'): results.append((record.path, record.encoding, record.line, '.'.join(record.context), record.text)) df = pd.DataFrame(results, columns=['path', 'encoding', 'line', 'context', 'text']) df['args'] = df.text.apply(lambda s: ' '.join(s.split()[1:5])) ser = df.apply(lambda row: f'*fix {row.context}.{row.args} ; from line {row.line} in {row.path}', axis=1) print(ser.to_csv(index=False, header=False), end='')