Revision 59
Added by Aaron Marcuse-Kubitza almost 13 years ago
scripts/lib/xpath.py | ||
---|---|---|
30 | 30 |
def set_value(path, value): path[-1].value = value |
31 | 31 |
|
32 | 32 |
def backward_id(elem): |
33 |
if len(elem.attrs) >= 1 and value(elem.attrs[0]) == None:
|
|
34 |
return elem.attrs[0]
|
|
33 |
if len(elem.attrs) >= 1 and value(elem.attrs[0]) == None and\
|
|
34 |
len(elem.attrs[0]) == 1: return elem.attrs[0]
|
|
35 | 35 |
else: return None |
36 | 36 |
|
37 | 37 |
class XpathParser(Parser): |
scripts/lib/db_xml.py | ||
---|---|---|
54 | 54 |
except KeyError: pass |
55 | 55 |
|
56 | 56 |
# Add fkey to parent |
57 |
if parent_id != None: row[pkey(name_of(node.parentNode))] = parent_id |
|
57 |
if parent_id != None: |
|
58 |
parent_ptr = node.getAttribute('fkey') |
|
59 |
if parent_ptr == '': parent_ptr = pkey(name_of(node.parentNode)) |
|
60 |
row[parent_ptr] = parent_id |
|
58 | 61 |
|
59 | 62 |
# Insert node |
60 | 63 |
for try_num in range(2): |
scripts/README.TXT | ||
---|---|---|
1 |
To see a program's description, read its top-of-file comment |
|
1 | 2 |
map: |
2 | 3 |
To see script usage: ./map |
3 | 4 |
To test: ./util/test_map |
5 |
util/join_maps: |
|
6 |
To see script usage: ./util/join_maps |
|
7 |
util/simplify_xpath: |
|
8 |
To see script usage, read its top-of-file comment |
scripts/map | ||
---|---|---|
41 | 41 |
+' [map_path] [<input] [>output]') |
42 | 42 |
commit = env_flag('commit') |
43 | 43 |
|
44 |
csv_config = dict(delimiter=',', quotechar='"') |
|
45 |
|
|
46 | 44 |
# Load map header |
47 | 45 |
in_is_xml = True |
48 | 46 |
if uses_map: |
... | ... | |
52 | 50 |
import xpath |
53 | 51 |
|
54 | 52 |
map_stream = open(map_path, 'rb') |
55 |
map_reader = csv.reader(map_stream, **csv_config)
|
|
53 |
map_reader = csv.reader(map_stream) |
|
56 | 54 |
src, dest = map_reader.next()[:2] |
57 | 55 |
src, sep, src_base = src.partition('/') |
58 | 56 |
in_is_xml = sep != '' |
... | ... | |
78 | 76 |
dest, None) |
79 | 77 |
if in_is_xml: raise Exception('XML-XML mapping not supported yet') |
80 | 78 |
else: # input is CSV |
81 |
reader = csv.reader(sys.stdin, **csv_config)
|
|
79 |
reader = csv.reader(sys.stdin) |
|
82 | 80 |
fieldnames = reader.next() |
83 | 81 |
row_idx = 0 |
84 | 82 |
for row in reader: |
scripts/util/join_maps | ||
---|---|---|
10 | 10 |
except ValueError: |
11 | 11 |
raise Exception('Usage: '+prog_name+' map_1 <map_0 >joined_map') |
12 | 12 |
|
13 |
csv_config = dict(delimiter=',', quotechar='"') |
|
14 |
|
|
15 | 13 |
# Get map 1 |
16 | 14 |
map_1 = {} |
17 | 15 |
stream = open(map_1_path, 'rb') |
18 |
reader = csv.reader(stream, **csv_config)
|
|
16 |
reader = csv.reader(stream) |
|
19 | 17 |
map_1_in, map_1_out = reader.next()[:2] |
20 | 18 |
for row in reader: |
21 | 19 |
if row[1] != '': map_1[row[0]] = row[1] |
22 | 20 |
stream.close() |
23 | 21 |
|
24 | 22 |
# Join map 1 to map 0 |
25 |
reader = csv.reader(sys.stdin, **csv_config)
|
|
23 |
reader = csv.reader(sys.stdin) |
|
26 | 24 |
map_0_in, map_0_out = reader.next()[:2] |
27 | 25 |
assert map_0_out == map_1_in |
28 |
writer = csv.writer(sys.stdout, **csv_config)
|
|
26 |
writer = csv.writer(sys.stdout) |
|
29 | 27 |
writer.writerow([map_0_in, map_1_out]) |
30 | 28 |
for row in reader: |
31 | 29 |
if row[1] in map_1: writer.writerow([row[0], map_1[row[1]]]) |
scripts/util/simplify_xpath | ||
---|---|---|
1 | 1 |
#!/usr/bin/env python |
2 | 2 |
# Removes duplication from XPath expressions |
3 |
# Filters one XPath per line from stdin to stdout |
|
3 | 4 |
|
4 | 5 |
import re |
5 | 6 |
import sys |
Also available in: Unified diff
map: Added support for custom fkeys to parent in db XML trees. Removed extraneous csv reader/writer config because Excel format is default. Improved documentation.