Project

General

Profile

« Previous | Next » 

Revision 928

ch_root: Ignore empty lines

View differences:

bin/ch_root
33 33
        config['in_root_re'] = r'^'+re.escape(config['in_root'])+r'(?=\b|\W|$)'
34 34
    writer.writerow(cols)
35 35
    for row in reader:
36
        for i in xrange(len(configs)): row[i] = configs[i]['root']+row[i]
37 36
        def sub(i):
38
            row[i], n = re.subn(configs[i]['in_root_re'], r'', row[i])
37
            row[i], n = re.subn(configs[i]['in_root_re'], r'',
38
                configs[i]['root']+row[i])
39 39
            return n > 0
40
        if sub(0):
41
            if not sub(1): raise SystemExit('Map error: Root "'
40
        if row[0] != '' and sub(0):
41
            if row[1] != '' and not sub(1): raise SystemExit('Map error: Root "'
42 42
                +configs[1]['in_root']+'" is not contained in output mapping: '
43 43
                +row[1])
44 44
            writer.writerow(row)

Also available in: Unified diff