-
Notifications
You must be signed in to change notification settings - Fork 0
/
conflict-view.py
executable file
·78 lines (68 loc) · 2.59 KB
/
conflict-view.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
70
71
72
73
74
75
76
77
78
#! /usr/bin/python
# vim: fileencoding=utf-8 encoding=utf-8 et sw=4
# Copyright (C) 2009 Andrzej Zaborowski <balrogg@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
import sys
import math
import codecs
import locale
import httplib
import xml.etree.cElementTree as ElementTree
import locale, codecs
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
encoding = locale.getlocale()[1]
sys.stdout = codecs.getwriter(encoding)(sys.stdout, errors = "replace")
sys.stderr = codecs.getwriter(encoding)(sys.stderr, errors = "replace")
def osmparse(filename):
tree = ElementTree.parse(filename).getroot()
elems = {}
if tree.tag == "osm" and tree.attrib.get("version") == "0.6":
for element in tree:
if not "id" in element.attrib:
continue
id = element.attrib["id"]
if "version" in element.attrib:
v = element.attrib["version"]
else:
v = "0"
if "action" in element.attrib:
elems[id] = (element.attrib["action"], v, element)
elif tree.tag == "osmChange" and \
tree.attrib.get("version") in [ "0.3", "0.6" ]:
for op in tree:
for element in op:
id = element.attrib["id"]
if "version" in element.attrib:
v = element.attrib["version"]
else:
v = "0"
elems[id] = (op.tag, v, element)
else:
print >>sys.stderr, u"File %s is in unknown format %s v%s!" % \
(filename, tree.tag, tree.attrib["version"])
sys.exit(1)
return elems
if len(sys.argv) != 3:
print >>sys.stderr, u"Synopsis:"
print >>sys.stderr, u" %s <osm-or-osc-file> <osm-or-osc-file>"
sys.exit(1)
a = osmparse(sys.argv[1])
b = osmparse(sys.argv[2])
for id in a:
if id in b:
print a[id][2].tag + " " + id + ":", \
"A:", a[id][0], "(v" + a[id][1] + ")", \
"B:", b[id][0], "(v" + b[id][1] + ")"