source: subversion/applications/utils/import/bulkupload/diffpatch.py @ 20882

Last change on this file since 20882 was 19989, checked in by balrog-kun, 10 years ago

Set the executable bits on the executables. (this directory still needs a clean-up)

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#! /usr/bin/python2
2# vim: fileencoding=utf-8 encoding=utf-8 et sw=4
3
4# Copyright (C) 2009 Jacek Konieczny <jajcus@jajcus.net>
5# Copyright (C) 2009 Andrzej Zaborowski <balrogg@gmail.com>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20
21"""
22Patches .osc files with .diff.xml files resulting from an upload of
23a previous chunk of a multipart upload.
24"""
25
26__version__ = "$Revision: 21 $"
27
28import os
29import subprocess
30import sys
31import traceback
32import codecs
33import locale
34
35import locale, codecs
36locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
37encoding = locale.getlocale()[1]
38sys.stdout = codecs.getwriter(encoding)(sys.stdout, errors = "replace")
39sys.stderr = codecs.getwriter(encoding)(sys.stderr, errors = "replace")
40
41if len(sys.argv) < 2 or sys.argv[1] == "--help":
42    print >>sys.stderr, u"Synopsis:"
43    print >>sys.stderr, u"    %s <file.diff.xml> [osm-files-to-patch...]"
44    sys.exit(1)
45
46dd = {}
47
48diff = open(sys.argv[1], "r")
49sys.stdout.write("Parsing diff\n")
50for line in diff:
51    oldpos = line.find("old_id=\"")
52    newpos = line.find("new_id=\"")
53    if oldpos < 0 or newpos < 0:
54        continue
55
56    # For the moment assume every element is operated on only
57    # once in a changeset (TODO)
58    old = line[oldpos + 8:]
59    new = line[newpos + 8:]
60    old = old[:old.find("\"")]
61    new = new[:new.find("\"")]
62    dd[old] = new
63
64for f in sys.argv[2:]:
65    sys.stdout.write("Parsing " + f + "\n")
66    change = open(f, "r")
67    newchange = open(f + ".diffed", "w")
68    for line in change:
69        refpos = line.find("ref=\"")
70        if refpos > -1:
71            ref = line[refpos + 5:]
72            ref = ref[:ref.find("\"")]
73            if ref in dd:
74                line = line.replace("ref=\"" + ref + "\"", "ref=\"" + dd[ref] + "\"")
75        newchange.write(line)
76    newchange.close()
Note: See TracBrowser for help on using the repository browser.