Project

General

Profile

1 1778 aaronmk
#!/usr/bin/env python
2
# Makes a source map spreadsheet from a CSV header
3
4
import csv
5
import os.path
6
import sys
7
8
sys.path.append(os.path.dirname(__file__)+"/../lib")
9
10
import csvs
11
import opts
12
13 4979 aaronmk
new_term_prefix = '*'
14
15 1778 aaronmk
def main():
16
    # Usage
17
    env_names = []
18
    def usage_err():
19
        raise SystemExit('Usage: '+opts.env_usage(env_names)+' '+sys.argv[0]
20
            +' <header >src_map')
21
22
    # Get config from env vars
23
    datasrc = opts.get_env_var('datasrc', None, env_names)
24 3569 aaronmk
    out_root = opts.get_env_var('out_root', None, env_names)
25
    in_root_suffix = opts.get_env_var('in_root_suffix', '', env_names)
26
    if datasrc == None or out_root == None: usage_err()
27 1778 aaronmk
28
    # Get col names
29 7653 aaronmk
    reader, col_names = csvs.reader_and_header(open('/dev/stdin', 'rU'))
30 1778 aaronmk
31
    # Write map spreadsheet
32
    writer = csv.writer(sys.stdout)
33 4673 aaronmk
    writer.writerow([datasrc+in_root_suffix, out_root, 'Filter', 'Comments'])
34 1778 aaronmk
    for col_name in col_names:
35 4979 aaronmk
        writer.writerow([col_name, new_term_prefix+col_name, '', ''])
36 1778 aaronmk
37
main()