aboutsummaryrefslogtreecommitdiff
path: root/upload/diffpatch.py
diff options
context:
space:
mode:
authorAndrew Harvey <andrew@alantgeo.com.au>2021-07-04 20:48:39 +1000
committerAndrew Harvey <andrew@alantgeo.com.au>2021-07-04 20:48:39 +1000
commitdeffe3e80b786f5782c6915e3adabf855bd54ac4 (patch)
tree23bd569e18dc64b07ce9204eb67a929776d57e2f /upload/diffpatch.py
parent7f59a0a9a9a8d3a739a08bbb0336fbf9aaf8b85d (diff)
directly commit upload.py as some local changes were made
Diffstat (limited to 'upload/diffpatch.py')
-rwxr-xr-xupload/diffpatch.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/upload/diffpatch.py b/upload/diffpatch.py
new file mode 100755
index 0000000..e95e7dd
--- /dev/null
+++ b/upload/diffpatch.py
@@ -0,0 +1,76 @@
+#! /usr/bin/python2
+# vim: fileencoding=utf-8 encoding=utf-8 et sw=4
+
+# Copyright (C) 2009 Jacek Konieczny <jajcus@jajcus.net>
+# 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
+
+
+"""
+Patches .osc files with .diff.xml files resulting from an upload of
+a previous chunk of a multipart upload.
+"""
+
+__version__ = "$Revision: 21 $"
+
+import os
+import subprocess
+import sys
+import traceback
+import codecs
+import locale
+
+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")
+
+if len(sys.argv) < 2 or sys.argv[1] == "--help":
+ print >>sys.stderr, u"Synopsis:"
+ print >>sys.stderr, u" %s <file.diff.xml> [osm-files-to-patch...]"
+ sys.exit(1)
+
+dd = {}
+
+diff = open(sys.argv[1], "r")
+sys.stdout.write("Parsing diff\n")
+for line in diff:
+ oldpos = line.find("old_id=\"")
+ newpos = line.find("new_id=\"")
+ if oldpos < 0 or newpos < 0:
+ continue
+
+ # For the moment assume every element is operated on only
+ # once in a changeset (TODO)
+ old = line[oldpos + 8:]
+ new = line[newpos + 8:]
+ old = old[:old.find("\"")]
+ new = new[:new.find("\"")]
+ dd[old] = new
+
+for f in sys.argv[2:]:
+ sys.stdout.write("Parsing " + f + "\n")
+ change = open(f, "r")
+ newchange = open(f + ".diffed", "w")
+ for line in change:
+ refpos = line.find("ref=\"")
+ if refpos > -1:
+ ref = line[refpos + 5:]
+ ref = ref[:ref.find("\"")]
+ if ref in dd:
+ line = line.replace("ref=\"" + ref + "\"", "ref=\"" + dd[ref] + "\"")
+ newchange.write(line)
+ newchange.close()