Project

General

Profile

« Previous | Next » 

Revision 67

Moved env usage string creation to opts.py. Changed db config var names to use in/out instead of from/to.

View differences:

scripts/lib/opts.py
16 16
        else: has_all = False
17 17
    if has_all: return vars_
18 18
    else: return None
19

  
20
def env_usage(env_names, optional=False):
21
    str_ = 'env'
22
    for name in env_names:
23
        str_ += ' '
24
        if optional: str_ += '['
25
        str_ += name+'=...'
26
        if optional: str_ += ']'
27
    return str_
scripts/map
18 18
    env_names = []
19 19
    def get_db_config(prefix):
20 20
        return opts.get_env_vars(db_config_names, prefix, env_names)
21
    from_db_config = get_db_config('from')
22
    to_db_config = get_db_config('to')
23
    in_is_db = from_db_config != None
24
    out_is_db = to_db_config != None
21
    in_db_config = get_db_config('in')
22
    out_db_config = get_db_config('out')
23
    in_is_db = in_db_config != None
24
    out_is_db = out_db_config != None
25 25
    uses_map = in_is_db or not out_is_db
26 26
    
27 27
    # Parse args
28
    prog_name = sys.argv[0]
29
    try: prog_name, map_path = sys.argv
28
    try: _prog_name, map_path = sys.argv
30 29
    except ValueError:
31
        if uses_map: raise SystemExit('Usage: env'+''.join(map(lambda name:
32
            ' ['+name+'=...]', env_names))+' [commit=1] '+prog_name
33
            +' [map_path] [<input] [>output]')
30
        if uses_map: raise SystemExit('Usage: '+opts.env_usage(env_names, True)
31
            +' [commit=1] '+sys.argv[0]+' [map_path] [<input] [>output]')
34 32
    commit = opts.env_flag('commit')
35 33
    
36 34
    # Load map header
......
45 43
        map_reader = csv.reader(map_stream)
46 44
        src, dest = map_reader.next()[:2]
47 45
        def split_col_name(name):
48
            name, sep, prefix = name.partition('/')
49
            return name, sep != '', sep+prefix
50
        src, in_is_xml, src_prefix = split_col_name(src)
51
        dest, out_is_xml, dest_prefix = split_col_name(dest)
46
            name, sep, root = name.partition('/')
47
            return name, sep != '', sep+root
48
        src, in_is_xml, src_root = split_col_name(src)
49
        dest, out_is_xml, dest_root = split_col_name(dest)
52 50
        assert out_is_xml
53
        has_types = dest_prefix.startswith('/*s/') # outer elements are types
51
        has_types = dest_root.startswith('/*s/') # outer elements are types
54 52
    
55 53
    # Input datasource to XML tree, mapping if needed
56 54
    if in_is_xml: doc = xml.dom.minidom.parse(sys.stdin)
......
62 60
        for row in map_reader:
63 61
            in_, out = row[:2]
64 62
            if out != '':
65
                try: out = xpath.parse(dest_prefix+out)
63
                try: out = xpath.parse(dest_root+out)
66 64
                except SyntaxException, ex: raise SystemExit(str(ex))
67 65
                if in_is_xml: pass # TODO: process the mapping
68 66
                elif in_is_db: pass # TODO: process the mapping
......
89 87
        doc = out_doc
90 88
    
91 89
    # Output XML tree
92
    if to_db_config != None: # output is database
90
    if out_db_config != None: # output is database
93 91
        import psycopg2
94 92
        from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE
95 93
        
96 94
        import db_xml
97 95
        
98
        db = psycopg2.connect(**to_db_config)
96
        db = psycopg2.connect(**out_db_config)
99 97
        db.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE)
100 98
        try:
101 99
            row_ct_ref = [0]
scripts/map2vegbank
3 3

  
4 4
selfDir="$(dirname -- "$0")"
5 5

  
6
export to_host=localhost to_user=vegbank to_password=vegbank to_database=vegbank
6
export out_host=localhost out_user=vegbank out_password=vegbank \
7
out_database=vegbank
7 8

  
8 9
"$selfDir/map"
scripts/util/join_maps
5 5
import sys
6 6

  
7 7
def main():
8
    prog_name = sys.argv[0]
9
    try: prog_name, map_1_path = sys.argv
8
    try: _prog_name, map_1_path = sys.argv
10 9
    except ValueError:
11
        raise SystemExit('Usage: '+prog_name+' map_1 <map_0 >joined_map')
10
        raise SystemExit('Usage: '+sys.argv[0]+' map_1 <map_0 >joined_map')
12 11
    
13 12
    # Get map 1
14 13
    map_1 = {}

Also available in: Unified diff