Project

General

Profile

« Previous | Next » 

Revision 1123

union: Check if two maps can be combined based on whether map 0 column 0 label contains map 1 column 0 label instead of being equal. This allows map 0's input 0 root to contain the datasource name as well as a format that allows it to be combined with a more general map. Added ignore flag to not print an error if column labels don't match.

View differences:

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

  
10 10
import maps
11
import opts
11 12

  
13
def col_label(col_name): return col_name.partition(':')[0]
14

  
12 15
def main():
16
    ignore = opts.env_flag('ignore')
13 17
    try: _prog_name, map_1_path = sys.argv
14 18
    except ValueError:
15
        raise SystemExit('Usage: '+sys.argv[0]+' <map_0 map_1 [| '+sys.argv[0]
16
            +' map_2]... >union_map')
19
        raise SystemExit('Usage: env [ignore=1] '+sys.argv[0]
20
            +' <map_0 map_1 [| '+sys.argv[0]+' map_2]... >union_map')
17 21
    
18 22
    map_ = {}
19 23
    def add_map(reader):
......
34 38
    # Add map 0 to map 1, overwriting existing entries
35 39
    reader = csv.reader(sys.stdin)
36 40
    map_0_cols = reader.next()
37
    if map_0_cols[0] != map_1_cols[0]: raise SystemExit('Map error: '
38
        'Map 1 column 0 name doesn\'t match map 0 column 0 name')
41
    if not col_label(map_0_cols[0]).find(col_label(map_1_cols[0])) >= 0:
42
        if ignore: sys.exit()
43
        else: raise SystemExit('Map error: Map 0 column 0 label doesn\'t '
44
            'contain map 1 column 0 label')
39 45
    add_map(reader)
40 46
    
41 47
    # Write combined map

Also available in: Unified diff