-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_diff_ssr2_osm_wrapper.py
executable file
·69 lines (53 loc) · 2.56 KB
/
git_diff_ssr2_osm_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#/usr/bin/env python
import sys
import logging
logger = logging.getLogger('utility_to_osm.ssr2.git_diff')
import utility_to_osm.file_util as file_util
from osmapis_stedsnr import OSMstedsnr
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
# diff is called by git with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode
new_file, old_file = sys.argv[1], sys.argv[2]
logger.info('Reading %s', old_file)
content = file_util.read_file(old_file)
old_osm = OSMstedsnr.from_xml(content)
logger.info('Reading %s', new_file)
content = file_util.read_file(new_file)
new_osm = OSMstedsnr.from_xml(content)
print('\n=== Missing stedsnr ===\n')
old_stedsnr = sorted(old_osm.stedsnr.keys())
new_stedsnr = sorted(new_osm.stedsnr.keys())
for key in old_stedsnr:
if key not in new_stedsnr:
print('Diff, %s missing in old' % key)
print(old_osm.stedsnr[key][0])
for key in new_stedsnr:
if key not in old_stedsnr:
print('Diff, %s missing in new' % key)
print(new_osm.stedsnr[key][0])
print('\n=== Tagging differences ===\n')
stedsnr = set(old_stedsnr).intersection(new_stedsnr)
for key in stedsnr:
old = old_osm.stedsnr[key][0]
new = new_osm.stedsnr[key][0]
limit_distance = 1e-5 # FIXME: resonable?
old_lat, old_lon = float(old.attribs['lat']), float(old.attribs['lon'])
new_lat, new_lon = float(new.attribs['lat']), float(new.attribs['lon'])
if abs(old_lat - new_lat) > limit_distance or abs(old_lon - new_lon) > limit_distance:
print('Diff in position %s old [%s, %s] != new [%s, %s]' % (key, old_lat, old_lon, new_lat, new_lon))
for tag_key in old.tags:
if tag_key not in new.tags:
print('Diff %s, %s missing in new:' % (key, tag_key))
print(' old[%s] = %s\n' % (tag_key, old.tags[tag_key]))
for tag_key in new.tags:
if tag_key not in old.tags:
print('Diff %s, %s missing in old:' % (key, tag_key))
print(' new[%s] = %s\n' % (tag_key, new.tags[tag_key]))
common_tags = set(old.tags.keys()).intersection(new.tags.keys())
for tag_key in common_tags:
if tag_key in ('ssr:date', ):
continue # don't care
o, n = new.tags[tag_key], old.tags[tag_key]
if o != n:
print('Diff %s:\n old[%s] = %s\n new[%s] = %s\n' % (key, tag_key, o, tag_key, n))