Project

General

Profile

« Previous | Next » 

Revision 1505

subtract: Also remove nonexplicit empty mappings whose input col is in map 1

View differences:

bin/subtract
1 1
#!/usr/bin/env python
2
# Subtracts map spreadsheet A1->C from A0->B to A->B
2
# Subtracts map spreadsheet A1->C from A0->B to produce A->B.
3
# A0 entries that are empty and have no comment documenting why they are empty
4
# are subtracted as well if there is a matching entry in A1.
3 5

  
4 6
import csv
5 7
import os.path
......
27 29
    headers = [None]*2
28 30
    
29 31
    # Get map 1
32
    input_cols = set()
30 33
    compare_cols = set()
31 34
    stream = open(map_1_path, 'rb')
32 35
    reader = csv.reader(stream)
33 36
    headers[1] = reader.next()
34 37
    for row in reader:
35
        if row[0] != '': compare_cols.add(compare_on(row))
38
        if row[0] != '':
39
            input_cols.add(row[0])
40
            compare_cols.add(compare_on(row))
36 41
    stream.close()
37 42
    
38 43
    # Open map 0
......
48 53
    writer = csv.writer(sys.stdout)
49 54
    writer.writerow(headers[0])
50 55
    for row in reader:
51
        if compare_on(row) not in compare_cols: writer.writerow(row)
56
        if not (maps.is_nonexplicit_empty_mapping(row) and row[0] in input_cols
57
            or compare_on(row) in compare_cols): # not in map 1
58
            writer.writerow(row)
52 59

  
53 60
main()

Also available in: Unified diff