Revision 130
Added by Aaron Marcuse-Kubitza about 13 years ago
map | ||
---|---|---|
25 | 25 |
return opts.get_env_vars(db_config_names, prefix, env_names) |
26 | 26 |
in_db_config = get_db_config('in') |
27 | 27 |
out_db_config = get_db_config('out') |
28 |
in_is_db = in_db_config != None
|
|
29 |
out_is_db = out_db_config != None
|
|
28 |
in_is_db = in_db_config != {}
|
|
29 |
out_is_db = out_db_config != {}
|
|
30 | 30 |
|
31 | 31 |
# Parse args |
32 | 32 |
map_path = None |
... | ... | |
38 | 38 |
commit = opts.env_flag('commit') |
39 | 39 |
|
40 | 40 |
# Load map header |
41 |
in_is_xml = True
|
|
41 |
in_is_xpaths = True
|
|
42 | 42 |
if map_path != None: |
43 | 43 |
import copy |
44 | 44 |
import csv |
... | ... | |
53 | 53 |
def split_col_name(name): |
54 | 54 |
name, sep, root = name.partition(':') |
55 | 55 |
return name, sep != '', root |
56 |
src, in_is_xml, src_root = split_col_name(src)
|
|
57 |
dest, out_is_xml, dest_root = split_col_name(dest)
|
|
58 |
assert out_is_xml
|
|
56 |
src, in_is_xpaths, src_root = split_col_name(src)
|
|
57 |
dest, out_is_xpaths, dest_root = split_col_name(dest)
|
|
58 |
assert out_is_xpaths
|
|
59 | 59 |
has_types = dest_root.startswith('/*s/') # outer elements are types |
60 | 60 |
for row in reader: |
61 | 61 |
in_, out = row[:2] |
... | ... | |
63 | 63 |
try: mappings.append((in_, xpath.parse(dest_root+out))) |
64 | 64 |
except SyntaxException, ex: raise SystemExit(str(ex)) |
65 | 65 |
stream.close() |
66 |
in_is_xml = in_is_xpaths and not in_is_db |
|
66 | 67 |
|
67 | 68 |
# Input datasource to XML tree, mapping if needed |
68 | 69 |
if in_is_xml: doc0 = xml.dom.minidom.parse(sys.stdin) |
... | ... | |
70 | 71 |
doc1 = xml.dom.minidom.getDOMImplementation().createDocument(None, |
71 | 72 |
dest, None) |
72 | 73 |
if in_is_db: |
73 |
assert in_is_xml
|
|
74 |
assert in_is_xpaths
|
|
74 | 75 |
|
75 | 76 |
import psycopg2 |
76 | 77 |
import db_xml |
... | ... | |
106 | 107 |
else: doc1 = doc0 |
107 | 108 |
|
108 | 109 |
# Output XML tree |
109 |
if out_db_config != None: # output is database
|
|
110 |
if out_is_db:
|
|
110 | 111 |
import psycopg2 |
111 | 112 |
from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE |
112 | 113 |
import db_xml |
Also available in: Unified diff
map: Allow db config vars to be optional. SALVIAS_db test: Changed to use salvias_plots and XPath mapping syntax.