Project

General

Profile

« Previous | Next » 

Revision 1503

subtract: Use new maps.combinable() to compare column headers, which allows more flexibility in combining maps

View differences:

bin/subtract
7 7

  
8 8
sys.path.append(os.path.dirname(__file__)+"/../lib")
9 9

  
10
import maps
10 11
import opts
11 12
import util
12 13

  
......
23 24
    
24 25
    def compare_on(row): return tuple(util.list_subset(row, compare_col_nums))
25 26
    
27
    headers = [None]*2
28
    
26 29
    # Get map 1
27 30
    compare_cols = set()
28 31
    stream = open(map_1_path, 'rb')
29 32
    reader = csv.reader(stream)
30
    map_1_cols = reader.next()
33
    headers[1] = reader.next()
31 34
    for row in reader:
32 35
        if row[0] != '': compare_cols.add(compare_on(row))
33 36
    stream.close()
34 37
    
35 38
    # Open map 0
36 39
    reader = csv.reader(sys.stdin)
37
    map_0_cols = reader.next()
38
    if not ignore and map_0_cols[0] != map_1_cols[0]: raise SystemExit(
39
        'Map error: Map 1 column 0 name doesn\'t match map 0 column 0 name')
40
    headers[0] = reader.next()
40 41
    
42
    # Check col labels
43
    if not maps.combinable(*headers) and not ignore:
44
        raise SystemExit('Map error: '
45
        'Map 0 column 0 label doesn\'t contain map 1 column 0 label')
46
    
41 47
    # Subtract map 1 from map 0
42 48
    writer = csv.writer(sys.stdout)
43
    writer.writerow(map_0_cols)
49
    writer.writerow(headers[0])
44 50
    for row in reader:
45 51
        if compare_on(row) not in compare_cols: writer.writerow(row)
46 52

  

Also available in: Unified diff