Status: | Merged |
---|---|
Merged at revision: | 457 |
Proposed branch: | lp:~spud/spud/xmldiff |
Merge into: | lp:spud |
Diff against target: |
2760 lines (+2526/-13) 17 files modified
Makefile.in (+10/-0) debian/control (+10/-1) debian/rules (+4/-1) diamond/bin/diamond (+24/-3) diamond/diamond/diffview.py (+558/-0) diamond/diamond/interface.py (+30/-7) diamond/gui/gui.glade (+15/-1) dxdiff/COPYING (+15/-0) dxdiff/GPL-3 (+676/-0) dxdiff/dxdiff/bimap.py (+49/-0) dxdiff/dxdiff/diff.py (+26/-0) dxdiff/dxdiff/dxdiff (+87/-0) dxdiff/dxdiff/editscript.py (+79/-0) dxdiff/dxdiff/fmes.py (+466/-0) dxdiff/dxdiff/lcs.py (+284/-0) dxdiff/dxdiff/utils.py (+172/-0) dxdiff/setup.py (+21/-0) |
To merge this branch: | bzr merge lp:~spud/spud/xmldiff |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Patrick Farrell | Pending | ||
Review via email:
|
Commit message
Description of the change
Adds xmldiff tool and diff view to Diamond.
To post a comment you must log in.
lp:~spud/spud/xmldiff
updated
- 454. By Patrick Farrell
-
Set some executable flags (how did these get lost?)
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Patrick Farrell (pefarrell) wrote : | # |
lp:~spud/spud/xmldiff
updated
- 455. By Fraser Waters
-
Added xmldiff/
- 456. By Fraser Waters
-
Added diffview.py
- 457. By Fraser Waters
-
Fixing pathing bugs, still more to go.
- 458. By Fraser Waters
-
Fixed more pathing bugs.
- 459. By Fraser Waters
-
Pathing bugs squashed.
- 460. By Fraser Waters
-
Renamed xmldiff to dxdiff (Diamond Xml diff). Added dxdiff to packages.
- 461. By Fraser Waters
-
Can no longer diff against save if no save.
- 462. By Fraser Waters
-
Added diamond -d [FILE] option.
- 463. By Fraser Waters
-
Don't delete text() nodes
- 464. By Fraser Waters
-
remove xpath names, fix __floodfill
- 465. By Fraser Waters
-
Properly fixed __floodfill
- 466. By Fraser Waters
-
Fixed indexing bugs
- 467. By Fraser Waters
-
Diff timed, fixed typo in _match
- 468. By Fraser Waters
-
dxdiff bug fixed
- 469. By Fraser Waters
-
Fixed indent typo, removed debuging code
- 470. By Fraser Waters
-
Removed more debug code
- 471. By Fraser Waters
-
Changed getopt to gnu_getopt
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Makefile.in' | |||
2 | --- Makefile.in 2011-08-04 21:30:53 +0000 | |||
3 | +++ Makefile.in 2011-08-24 16:38:18 +0000 | |||
4 | @@ -101,11 +101,21 @@ | |||
5 | 101 | cd python; for python in $(shell pyversions -r); do $$python setup.py install --prefix=$(DESTDIR)@prefix@ --install-layout=deb; done; cd .. | 101 | cd python; for python in $(shell pyversions -r); do $$python setup.py install --prefix=$(DESTDIR)@prefix@ --install-layout=deb; done; cd .. |
6 | 102 | endif | 102 | endif |
7 | 103 | 103 | ||
8 | 104 | install-dxdiff: | ||
9 | 105 | ifeq ($(origin DESTDIR),undefined) | ||
10 | 106 | cd dxdiff; python setup.py install --prefix=$(DESTDIR)@prefix@; cd .. | ||
11 | 107 | else | ||
12 | 108 | cd dxdiff; for python in $(shell pyversions -r); do $$python setup.py install --prefix=$(DESTDIR)@prefix@ --install-layout=deb; done; cd .. | ||
13 | 109 | endif | ||
14 | 110 | |||
15 | 104 | clean: | 111 | clean: |
16 | 105 | @cd doc; $(MAKE) clean | 112 | @cd doc; $(MAKE) clean |
17 | 106 | rm -f *.o libspud.a libspud.so *.o *.la *.mod *.lo | 113 | rm -f *.o libspud.a libspud.so *.o *.la *.mod *.lo |
18 | 107 | rm -rf .libs | 114 | rm -rf .libs |
19 | 108 | @cd src/tests; $(MAKE) clean | 115 | @cd src/tests; $(MAKE) clean |
20 | 116 | @cd python; rm -rf build; cd .. | ||
21 | 117 | @cd dxdiff; rm -rf build; cd .. | ||
22 | 118 | |||
23 | 109 | 119 | ||
24 | 110 | distclean: clean | 120 | distclean: clean |
25 | 111 | @cd src/tests; $(MAKE) distclean | 121 | @cd src/tests; $(MAKE) distclean |
26 | 112 | 122 | ||
27 | === modified file 'config.guess' (properties changed: +x to -x) | |||
28 | === modified file 'config.sub' (properties changed: +x to -x) | |||
29 | === modified file 'debian/control' | |||
30 | --- debian/control 2011-08-15 20:50:30 +0000 | |||
31 | +++ debian/control 2011-08-24 16:38:18 +0000 | |||
32 | @@ -9,7 +9,7 @@ | |||
33 | 9 | 9 | ||
34 | 10 | Package: diamond | 10 | Package: diamond |
35 | 11 | Architecture: all | 11 | Architecture: all |
37 | 12 | Depends: python-gtk2, python-lxml, libxml2-utils, python, spudtools, python-gtksourceview2 | 12 | Depends: python-gtk2, python-lxml, libxml2-utils, python, spudtools, python-gtksourceview2, python-dxdiff |
38 | 13 | Recommends: python-psyco | 13 | Recommends: python-psyco |
39 | 14 | Suggests: | 14 | Suggests: |
40 | 15 | Conflicts: python-diamond | 15 | Conflicts: python-diamond |
41 | @@ -62,3 +62,12 @@ | |||
42 | 62 | file is generated using a spud-compatible RELAX NG schema and a | 62 | file is generated using a spud-compatible RELAX NG schema and a |
43 | 63 | schema-aware editor such as Diamond. This package contains the Python | 63 | schema-aware editor such as Diamond. This package contains the Python |
44 | 64 | bindings for libspud. | 64 | bindings for libspud. |
45 | 65 | |||
46 | 66 | Package: python-dxdiff | ||
47 | 67 | Section: python | ||
48 | 68 | Architecture: any | ||
49 | 69 | XB-Python-Version: ${python:Versions} | ||
50 | 70 | Depends: ${python:Depends}, ${misc:Depends} | ||
51 | 71 | Description: An XML aware diff tool. | ||
52 | 72 | DXdiff (Diamond Xml diff) is an XML aware diff tool for finding edit scripts | ||
53 | 73 | between two XML files. | ||
54 | 65 | 74 | ||
55 | === modified file 'debian/rules' | |||
56 | --- debian/rules 2011-08-16 22:52:44 +0000 | |||
57 | +++ debian/rules 2011-08-24 16:38:18 +0000 | |||
58 | @@ -83,6 +83,9 @@ | |||
59 | 83 | install-pyspud: | 83 | install-pyspud: |
60 | 84 | $(MAKE) install-pyspud DESTDIR=$(CURDIR)/debian/python-spud | 84 | $(MAKE) install-pyspud DESTDIR=$(CURDIR)/debian/python-spud |
61 | 85 | 85 | ||
62 | 86 | install-dxdiff: | ||
63 | 87 | $(MAKE) install-dxdiff DESTDIR=$(CURDIR)/debian/python-dxdiff | ||
64 | 88 | |||
65 | 86 | binary-arch: build-libspud install-libspud install-spudtools install-pyspud | 89 | binary-arch: build-libspud install-libspud install-spudtools install-pyspud |
66 | 87 | dh_testdir | 90 | dh_testdir |
67 | 88 | dh_testroot | 91 | dh_testroot |
68 | @@ -114,7 +117,7 @@ | |||
69 | 114 | dh_md5sums | 117 | dh_md5sums |
70 | 115 | dh_builddeb | 118 | dh_builddeb |
71 | 116 | 119 | ||
73 | 117 | binary-indep: build-diamond install-diamond build-libspud install-libspud install-spudtools | 120 | binary-indep: build-diamond install-diamond build-libspud install-libspud install-spudtools install-dxdiff |
74 | 118 | dh_testdir -i | 121 | dh_testdir -i |
75 | 119 | dh_testroot -i | 122 | dh_testroot -i |
76 | 120 | DH_PYCENTRAL=include-links dh_pycentral -i | 123 | DH_PYCENTRAL=include-links dh_pycentral -i |
77 | 121 | 124 | ||
78 | === modified file 'diamond/bin/diamond' | |||
79 | --- diamond/bin/diamond 2011-07-05 11:42:44 +0000 | |||
80 | +++ diamond/bin/diamond 2011-08-24 16:38:18 +0000 | |||
81 | @@ -29,6 +29,8 @@ | |||
82 | 29 | # do this right at the start, so we can find the diamond modules | 29 | # do this right at the start, so we can find the diamond modules |
83 | 30 | diamond_path = os.path.join( os.path.realpath(os.path.dirname(__file__)), os.pardir ) | 30 | diamond_path = os.path.join( os.path.realpath(os.path.dirname(__file__)), os.pardir ) |
84 | 31 | sys.path.insert(0, diamond_path) | 31 | sys.path.insert(0, diamond_path) |
85 | 32 | dxdiff_path = os.path.join( os.path.realpath(os.path.dirname(__file__)), os.pardir, os.pardir, "dxdiff" ) | ||
86 | 33 | sys.path.insert(0, dxdiff_path) | ||
87 | 32 | 34 | ||
88 | 33 | import diamond.debug as debug | 35 | import diamond.debug as debug |
89 | 34 | 36 | ||
90 | @@ -48,6 +50,7 @@ | |||
91 | 48 | "-f Forks at startup\n" + \ | 50 | "-f Forks at startup\n" + \ |
92 | 49 | "-s [SCHEMAFILE] Use the supplied schema file *\n" + \ | 51 | "-s [SCHEMAFILE] Use the supplied schema file *\n" + \ |
93 | 50 | "-t [TRONFILE] Use the supplied schematron file for extended validation\n" + \ | 52 | "-t [TRONFILE] Use the supplied schematron file for extended validation\n" + \ |
94 | 53 | "-d [FILE] Diff against the supplied file. (FILE must be specified)\n" + \ | ||
95 | 51 | "-v Verbosity switch - if supplied Diamond prints additional\n" + \ | 54 | "-v Verbosity switch - if supplied Diamond prints additional\n" + \ |
96 | 52 | " debugging information to standard output and standard error\n" + \ | 55 | " debugging information to standard output and standard error\n" + \ |
97 | 53 | "\n" + \ | 56 | "\n" + \ |
98 | @@ -59,7 +62,7 @@ | |||
99 | 59 | def main(): | 62 | def main(): |
100 | 60 | 63 | ||
101 | 61 | try: | 64 | try: |
103 | 62 | opts, args = getopt.getopt(sys.argv[1:], "hvfs:t:") | 65 | opts, args = getopt.gnu_getopt(sys.argv[1:], "hvfs:t:d:") |
104 | 63 | except: | 66 | except: |
105 | 64 | Help() | 67 | Help() |
106 | 65 | sys.exit(1) | 68 | sys.exit(1) |
107 | @@ -99,8 +102,13 @@ | |||
108 | 99 | except IndexError: | 102 | except IndexError: |
109 | 100 | input_filename = None | 103 | input_filename = None |
110 | 101 | 104 | ||
111 | 105 | if sys.platform == "win32" or sys.platform == "win64": | ||
112 | 106 | possible_logofiles = [os.path.join(diamond_path, "gui", "diamond.png")] | ||
113 | 107 | else: | ||
114 | 108 | possible_logofiles = [os.path.join(diamond_path, "gui", "diamond.svg"), "/usr/share/diamond/gui/diamond.svg"] | ||
115 | 109 | |||
116 | 102 | logofile = None | 110 | logofile = None |
118 | 103 | for possible_logofile in [os.path.join(diamond_path, "gui", "diamond.svg"), "/usr/share/diamond/gui/diamond.svg"]: | 111 | for possible_logofile in possible_logofiles: |
119 | 104 | try: | 112 | try: |
120 | 105 | os.stat(possible_logofile) | 113 | os.stat(possible_logofile) |
121 | 106 | logofile = possible_logofile | 114 | logofile = possible_logofile |
122 | @@ -209,7 +217,20 @@ | |||
123 | 209 | 217 | ||
124 | 210 | i.main_window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) | 218 | i.main_window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) |
125 | 211 | i.open_file(schemafile = input_schemafile, filename = input_filename) | 219 | i.open_file(schemafile = input_schemafile, filename = input_filename) |
127 | 212 | i.main_window.window.set_cursor(None) | 220 | i.main_window.window.set_cursor(None) |
128 | 221 | |||
129 | 222 | # see if the user wants to diff against a file | ||
130 | 223 | input_difffile = None | ||
131 | 224 | for opt in opts: | ||
132 | 225 | if opt[0] == "-d": | ||
133 | 226 | input_difffile = opt[1] | ||
134 | 227 | |||
135 | 228 | if input_difffile: | ||
136 | 229 | if input_filename: | ||
137 | 230 | i.on_diff(None, input_difffile) | ||
138 | 231 | else: | ||
139 | 232 | debug.dprint("Cannot diff if against nothing.", 0) | ||
140 | 233 | |||
141 | 213 | 234 | ||
142 | 214 | gtk.main() | 235 | gtk.main() |
143 | 215 | 236 | ||
144 | 216 | 237 | ||
145 | === added file 'diamond/diamond/diffview.py' | |||
146 | --- diamond/diamond/diffview.py 1970-01-01 00:00:00 +0000 | |||
147 | +++ diamond/diamond/diffview.py 2011-08-24 16:38:18 +0000 | |||
148 | @@ -0,0 +1,558 @@ | |||
149 | 1 | #!/usr/bin/env python | ||
150 | 2 | |||
151 | 3 | # This file is part of Diamond. | ||
152 | 4 | # | ||
153 | 5 | # Diamond is free software: you can redistribute it and/or modify | ||
154 | 6 | # it under the terms of the GNU General Public License as published by | ||
155 | 7 | # the Free Software Foundation, either version 3 of the License, or | ||
156 | 8 | # (at your option) any later version. | ||
157 | 9 | # | ||
158 | 10 | # Diamond is distributed in the hope that it will be useful, | ||
159 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
160 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
161 | 13 | # GNU General Public License for more details. | ||
162 | 14 | # | ||
163 | 15 | # You should have received a copy of the GNU General Public License | ||
164 | 16 | # along with Diamond. If not, see <http://www.gnu.org/licenses/>. | ||
165 | 17 | |||
166 | 18 | import os | ||
167 | 19 | import os.path | ||
168 | 20 | import sys | ||
169 | 21 | import cStringIO as StringIO | ||
170 | 22 | |||
171 | 23 | import gobject | ||
172 | 24 | import gtk | ||
173 | 25 | |||
174 | 26 | from lxml import etree | ||
175 | 27 | |||
176 | 28 | import attributewidget | ||
177 | 29 | import databuttonswidget | ||
178 | 30 | import datawidget | ||
179 | 31 | import mixedtree | ||
180 | 32 | |||
181 | 33 | #diff_path = os.path.join( os.path.realpath(os.path.dirname(__file__)), os.pardir, os.pardir, "xmldiff") | ||
182 | 34 | #sys.path.insert(0, diff_path) | ||
183 | 35 | |||
184 | 36 | import dxdiff.diff as xmldiff | ||
185 | 37 | |||
186 | 38 | class DiffView(gtk.Window): | ||
187 | 39 | |||
188 | 40 | def __init__(self, path, tree): | ||
189 | 41 | gtk.Window.__init__(self) | ||
190 | 42 | self.__add_controls() | ||
191 | 43 | |||
192 | 44 | if path and os.path.isfile(path): | ||
193 | 45 | filename = path | ||
194 | 46 | else: | ||
195 | 47 | dialog = gtk.FileChooserDialog(title = "Diff against", | ||
196 | 48 | action = gtk.FILE_CHOOSER_ACTION_OPEN, | ||
197 | 49 | buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) | ||
198 | 50 | if path: | ||
199 | 51 | dialog.set_current_folder(path) | ||
200 | 52 | |||
201 | 53 | response = dialog.run() | ||
202 | 54 | if response != gtk.RESPONSE_OK: | ||
203 | 55 | dialog.destroy() | ||
204 | 56 | self.destroy() | ||
205 | 57 | return | ||
206 | 58 | |||
207 | 59 | filename = dialog.get_filename() | ||
208 | 60 | dialog.destroy() | ||
209 | 61 | |||
210 | 62 | tree1 = etree.parse(filename) | ||
211 | 63 | tree2 = etree.ElementTree(tree.write_core(None)) | ||
212 | 64 | |||
213 | 65 | editscript = xmldiff.diff(tree1, tree2) | ||
214 | 66 | self.__update(tree1, editscript) | ||
215 | 67 | |||
216 | 68 | self.show_all() | ||
217 | 69 | |||
218 | 70 | def __add_controls(self): | ||
219 | 71 | self.set_default_size(800, 600) | ||
220 | 72 | self.set_title("Diff View") | ||
221 | 73 | |||
222 | 74 | mainvbox = gtk.VBox() | ||
223 | 75 | |||
224 | 76 | menubar = gtk.MenuBar() | ||
225 | 77 | edititem = gtk.MenuItem("_Edit") | ||
226 | 78 | menubar.append(edititem) | ||
227 | 79 | |||
228 | 80 | agr = gtk.AccelGroup() | ||
229 | 81 | self.add_accel_group(agr) | ||
230 | 82 | |||
231 | 83 | self.popup = editmenu = gtk.Menu() | ||
232 | 84 | edititem.set_submenu(editmenu) | ||
233 | 85 | copyitem = gtk.MenuItem("Copy") | ||
234 | 86 | copyitem.connect("activate", self.on_copy) | ||
235 | 87 | key, mod = gtk.accelerator_parse("<Control>C") | ||
236 | 88 | copyitem.add_accelerator("activate", agr, key, mod, gtk.ACCEL_VISIBLE) | ||
237 | 89 | editmenu.append(copyitem) | ||
238 | 90 | |||
239 | 91 | mainvbox.pack_start(menubar, expand = False) | ||
240 | 92 | |||
241 | 93 | hpane = gtk.HPaned() | ||
242 | 94 | |||
243 | 95 | self.treeview = gtk.TreeView() | ||
244 | 96 | |||
245 | 97 | self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE) | ||
246 | 98 | self.treeview.get_selection().connect("changed", self.on_select_row) | ||
247 | 99 | |||
248 | 100 | # Node column | ||
249 | 101 | celltext = gtk.CellRendererText() | ||
250 | 102 | column = gtk.TreeViewColumn("Node", celltext) | ||
251 | 103 | column.set_cell_data_func(celltext, self.set_celltext) | ||
252 | 104 | |||
253 | 105 | self.treeview.append_column(column) | ||
254 | 106 | |||
255 | 107 | # 0: The node tag | ||
256 | 108 | # 1: The attributes dict | ||
257 | 109 | # 2: The value of the node if any | ||
258 | 110 | # 3: The old value of the node | ||
259 | 111 | # 4: "insert", "delete", "update", "" | ||
260 | 112 | self.treestore = gtk.TreeStore(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT) | ||
261 | 113 | self.treeview.set_model(self.treestore) | ||
262 | 114 | self.treeview.set_enable_search(False) | ||
263 | 115 | self.treeview.connect("button_press_event", self.on_treeview_button_press) | ||
264 | 116 | self.treeview.connect("popup_menu", self.on_treeview_popup) | ||
265 | 117 | hpane.pack1(self.treeview) | ||
266 | 118 | |||
267 | 119 | vpane = gtk.VPaned() | ||
268 | 120 | frame = gtk.Frame() | ||
269 | 121 | label = gtk.Label() | ||
270 | 122 | label.set_markup("<b>Attributes</b>") | ||
271 | 123 | frame.set_label_widget(label) | ||
272 | 124 | frame.set_shadow_type(gtk.SHADOW_NONE) | ||
273 | 125 | |||
274 | 126 | self.attribview = gtk.TreeView() | ||
275 | 127 | |||
276 | 128 | celltext = gtk.CellRendererText() | ||
277 | 129 | keycolumn = gtk.TreeViewColumn("Key", celltext) | ||
278 | 130 | keycolumn.set_cell_data_func(celltext, self.set_cellkey) | ||
279 | 131 | |||
280 | 132 | self.attribview.append_column(keycolumn) | ||
281 | 133 | |||
282 | 134 | celltext = gtk.CellRendererText() | ||
283 | 135 | valuecolumn = gtk.TreeViewColumn("Value", celltext) | ||
284 | 136 | valuecolumn.set_cell_data_func(celltext, self.set_cellvalue) | ||
285 | 137 | |||
286 | 138 | self.attribview.append_column(valuecolumn) | ||
287 | 139 | |||
288 | 140 | frame.add(self.attribview) | ||
289 | 141 | vpane.pack1(frame) | ||
290 | 142 | |||
291 | 143 | frame = gtk.Frame() | ||
292 | 144 | label = gtk.Label() | ||
293 | 145 | label.set_markup("<b>Data</b>") | ||
294 | 146 | frame.set_label_widget(label) | ||
295 | 147 | frame.set_shadow_type(gtk.SHADOW_NONE) | ||
296 | 148 | |||
297 | 149 | self.dataview = gtk.TextView() | ||
298 | 150 | self.dataview.set_cursor_visible(False) | ||
299 | 151 | self.dataview.set_editable(False) | ||
300 | 152 | self.__create_tags(self.dataview.get_buffer()) | ||
301 | 153 | |||
302 | 154 | frame.add(self.dataview) | ||
303 | 155 | vpane.pack2(frame) | ||
304 | 156 | |||
305 | 157 | hpane.pack2(vpane) | ||
306 | 158 | mainvbox.pack_start(hpane) | ||
307 | 159 | self.add(mainvbox) | ||
308 | 160 | |||
309 | 161 | def on_treeview_button_press(self, treeview, event): | ||
310 | 162 | pathinfo = treeview.get_path_at_pos(int(event.x), int(event.y)) | ||
311 | 163 | if event.button == 3: | ||
312 | 164 | if pathinfo is not None: | ||
313 | 165 | treeview.get_selection().select_path(pathinfo[0]) | ||
314 | 166 | self.show_popup(None, event.button, event.time) | ||
315 | 167 | return True | ||
316 | 168 | |||
317 | 169 | def popup_location(self, widget, user_data): | ||
318 | 170 | column = self.treeview.get_column(0) | ||
319 | 171 | path = self.treeview.get_selection().get_selected()[1] | ||
320 | 172 | area = self.treeview.get_cell_area(path, column) | ||
321 | 173 | tx, ty = area.x, area.y | ||
322 | 174 | x, y = self.treeview.tree_to_widget_coords(tx, ty) | ||
323 | 175 | return (x, y, True) | ||
324 | 176 | |||
325 | 177 | def on_treeview_popup(self, treeview): | ||
326 | 178 | self.show_popup(None, self.popup_location, gtk.get_current_event_time()) | ||
327 | 179 | return | ||
328 | 180 | |||
329 | 181 | def show_popup(self, func, button, time): | ||
330 | 182 | self.popup.popup( None, None, func, button, time) | ||
331 | 183 | return | ||
332 | 184 | |||
333 | 185 | def __update(self, tree, editscript): | ||
334 | 186 | self.__set_treestore(tree.getroot()) | ||
335 | 187 | self.__parse_editscript(editscript) | ||
336 | 188 | self.__floodfill(self.treestore.get_iter_root()) | ||
337 | 189 | |||
338 | 190 | def __set_treestore(self, tree, iter = None): | ||
339 | 191 | |||
340 | 192 | attrib = {} | ||
341 | 193 | for key, value in tree.attrib.iteritems(): | ||
342 | 194 | # (new, old, edit) | ||
343 | 195 | attrib[key] = (value, value, None) | ||
344 | 196 | |||
345 | 197 | child_iter = self.treestore.append(iter, [tree.tag, attrib, tree.text, tree.text, None]) | ||
346 | 198 | for child in tree: | ||
347 | 199 | self.__set_treestore(child, child_iter) | ||
348 | 200 | |||
349 | 201 | def __parse_editscript(self, editscript): | ||
350 | 202 | for edit in editscript: | ||
351 | 203 | iter, key = self.__get_iter(edit["location"]) | ||
352 | 204 | if key: | ||
353 | 205 | attribs = self.treestore.get_value(iter, 1) | ||
354 | 206 | old = attribs[key][1] | ||
355 | 207 | if edit["type"] == "delete": | ||
356 | 208 | attribs[key] = (None, old, "delete") | ||
357 | 209 | elif edit["type"] == "update": | ||
358 | 210 | attribs[key] = (edit["value"], old, "update") | ||
359 | 211 | elif edit["type"] == "move": | ||
360 | 212 | attribs[key] = (None, old, "delete") | ||
361 | 213 | self.__insert(self.__get_iter(edit["value"])[0], key + " " + old, 0) | ||
362 | 214 | |||
363 | 215 | else: | ||
364 | 216 | |||
365 | 217 | if edit["type"] == "insert": | ||
366 | 218 | self.__insert(iter, edit["value"], int(edit["index"])) | ||
367 | 219 | elif edit["type"] == "delete": | ||
368 | 220 | self.treestore.set(iter, 2, None) | ||
369 | 221 | self.treestore.set(iter, 4, "delete") | ||
370 | 222 | elif edit["type"] == "update": | ||
371 | 223 | self.treestore.set(iter, 2, edit["value"]) | ||
372 | 224 | elif edit["type"] == "move": | ||
373 | 225 | self.__move(iter, edit["value"], int(edit["index"])) | ||
374 | 226 | |||
375 | 227 | def __floodfill(self, iter, parentedit = None): | ||
376 | 228 | """ | ||
377 | 229 | Floodfill the tree with the correct edit types. | ||
378 | 230 | If something has changed below you, "subupdate" | ||
379 | 231 | If your value or attrs has changed "update" | ||
380 | 232 | If insert, all below insert | ||
381 | 233 | If delete, all below delete | ||
382 | 234 | """ | ||
383 | 235 | attribs, new, old, edit = self.treestore.get(iter, 1, 2, 3, 4) | ||
384 | 236 | |||
385 | 237 | if parentedit == "insert": | ||
386 | 238 | edit = "insert" | ||
387 | 239 | elif parentedit == "delete": | ||
388 | 240 | edit = "delete" | ||
389 | 241 | |||
390 | 242 | if edit == "insert" or edit == "delete": | ||
391 | 243 | for key, (valuenew, valueold, valueedit) in attribs.iteritems(): | ||
392 | 244 | attribs[key] = (valuenew, valueold, edit) | ||
393 | 245 | |||
394 | 246 | child = self.treestore.iter_children(iter) | ||
395 | 247 | while child is not None: | ||
396 | 248 | self.__floodfill(child, edit) | ||
397 | 249 | child = self.treestore.iter_next(child) | ||
398 | 250 | |||
399 | 251 | self.treestore.set(iter, 4, edit) | ||
400 | 252 | else: | ||
401 | 253 | update = False | ||
402 | 254 | for key in attribs: | ||
403 | 255 | # edit value | ||
404 | 256 | if attribs[key][2] is not None: | ||
405 | 257 | update = True | ||
406 | 258 | break | ||
407 | 259 | if new != old: | ||
408 | 260 | update = True | ||
409 | 261 | |||
410 | 262 | if update: | ||
411 | 263 | self.treestore.set(iter, 4, "update") | ||
412 | 264 | else: | ||
413 | 265 | child = self.treestore.iter_children(iter) | ||
414 | 266 | while child is not None: | ||
415 | 267 | change = self.__floodfill(child, edit) | ||
416 | 268 | if change is not None: | ||
417 | 269 | self.treestore.set(iter, 4, "subupdate") | ||
418 | 270 | child = self.treestore.iter_next(child) | ||
419 | 271 | |||
420 | 272 | return self.treestore.get_value(iter, 4) | ||
421 | 273 | |||
422 | 274 | def __insert(self, iter, value, index): | ||
423 | 275 | if " " in value: | ||
424 | 276 | key, value = value.split(" ") | ||
425 | 277 | attrib = self.treestore.get_value(iter, 1) | ||
426 | 278 | attrib[key] = (value, None, "insert") | ||
427 | 279 | else: | ||
428 | 280 | before = self.__iter_nth_child(iter, index - 1) | ||
429 | 281 | if before: | ||
430 | 282 | self.treestore.insert_before(iter, before, [value, {}, None, None, "insert"]) | ||
431 | 283 | else: | ||
432 | 284 | self.treestore.append(iter, [value, {}, None, None, "insert"]) | ||
433 | 285 | |||
434 | 286 | def __move(self, iter, value, index): | ||
435 | 287 | """ | ||
436 | 288 | Copy the entire subtree at iter to the path at value[index], | ||
437 | 289 | mark all of iter as deleted, and all of the copy inserted. | ||
438 | 290 | """ | ||
439 | 291 | tag, attrib, text = self.treestore.get(iter, 0, 1, 2) | ||
440 | 292 | self.treestore.set(iter, 2, None) | ||
441 | 293 | self.treestore.set(iter, 4, "delete") | ||
442 | 294 | |||
443 | 295 | destiter = self.__get_iter(value)[0] | ||
444 | 296 | |||
445 | 297 | before = self.__iter_nth_child(destiter, index - 1) | ||
446 | 298 | if before: | ||
447 | 299 | destiter = self.treestore.insert_before(destiter, before, [tag, attrib, text, None, "insert"]) | ||
448 | 300 | else: | ||
449 | 301 | destiter = self.treestore.append(destiter, [tag, attrib, text, None, "insert"]) | ||
450 | 302 | |||
451 | 303 | def move(iterfrom, iterto): | ||
452 | 304 | for childfrom in self.__iter_children(iterfrom): | ||
453 | 305 | tag, attrib, text = self.treestore.get(childfrom, 0, 1, 2) | ||
454 | 306 | self.treestore.set(childfrom, 2, None) | ||
455 | 307 | self.treestore.set(childfrom, 4, "delete") | ||
456 | 308 | |||
457 | 309 | childto = self.treestore.append(iterto, [tag, attrib, text, None, "insert"]) | ||
458 | 310 | move(childfrom, childto) | ||
459 | 311 | |||
460 | 312 | move(iter, destiter) | ||
461 | 313 | |||
462 | 314 | def __iter_children(self, iter): | ||
463 | 315 | child = self.treestore.iter_children(iter) | ||
464 | 316 | |||
465 | 317 | while child: | ||
466 | 318 | active = self.treestore.get_value(child, 4) != "delete" | ||
467 | 319 | if active: | ||
468 | 320 | yield child | ||
469 | 321 | child = self.treestore.iter_next(child) | ||
470 | 322 | |||
471 | 323 | def __iter_nth_child(self, iter, n): | ||
472 | 324 | |||
473 | 325 | for child in self.__iter_children(iter): | ||
474 | 326 | if n == 0: | ||
475 | 327 | return child | ||
476 | 328 | else: | ||
477 | 329 | n -= 1 | ||
478 | 330 | return None | ||
479 | 331 | |||
480 | 332 | def __get_iter(self, path, iter = None): | ||
481 | 333 | """ | ||
482 | 334 | Convert the given XML path to an iter into the treestore. | ||
483 | 335 | """ | ||
484 | 336 | |||
485 | 337 | if iter is None: | ||
486 | 338 | iter = self.treestore.get_iter_first() | ||
487 | 339 | |||
488 | 340 | tag, edit = self.treestore.get(iter, 0, 4) | ||
489 | 341 | if edit == "delete": | ||
490 | 342 | return None # don't search deleted paths | ||
491 | 343 | |||
492 | 344 | parentiter = self.treestore.iter_parent(iter) | ||
493 | 345 | if parentiter: | ||
494 | 346 | siblings = [] | ||
495 | 347 | for siblingiter in self.__iter_children(parentiter): | ||
496 | 348 | siblingtag = self.treestore.get_value(siblingiter, 0) | ||
497 | 349 | if siblingtag == tag: | ||
498 | 350 | siblings.append(self.treestore.get_path(siblingiter)) | ||
499 | 351 | |||
500 | 352 | if len(siblings) != 1: | ||
501 | 353 | index = "[" + str(siblings.index(self.treestore.get_path(iter)) + 1) + "]" | ||
502 | 354 | else: | ||
503 | 355 | index = "" | ||
504 | 356 | |||
505 | 357 | tag = "/" + tag + index | ||
506 | 358 | else: | ||
507 | 359 | tag = "/" + tag | ||
508 | 360 | |||
509 | 361 | index = path.find("/", 1) | ||
510 | 362 | if index == -1: | ||
511 | 363 | index = len(path) | ||
512 | 364 | |||
513 | 365 | root = path[:index] | ||
514 | 366 | path = path[index:] | ||
515 | 367 | |||
516 | 368 | #check we match root | ||
517 | 369 | if root != tag: | ||
518 | 370 | return None | ||
519 | 371 | |||
520 | 372 | if path: | ||
521 | 373 | # check for text() | ||
522 | 374 | if path == "/text()": | ||
523 | 375 | return (iter, None) | ||
524 | 376 | |||
525 | 377 | # check attributes | ||
526 | 378 | if path.startswith("/@"): | ||
527 | 379 | attrib = self.treestore.get_value(iter, 1) | ||
528 | 380 | for key in attrib: | ||
529 | 381 | if path == "/@" + key: | ||
530 | 382 | return (iter, key) | ||
531 | 383 | return None | ||
532 | 384 | |||
533 | 385 | # check children | ||
534 | 386 | for iter in self.__iter_children(iter): | ||
535 | 387 | edit = self.treestore.get_value(iter, 4) | ||
536 | 388 | if edit != "delete": | ||
537 | 389 | result = self.__get_iter(path, iter) | ||
538 | 390 | if result: | ||
539 | 391 | return result | ||
540 | 392 | |||
541 | 393 | return None | ||
542 | 394 | else: | ||
543 | 395 | # must be us | ||
544 | 396 | return (iter, None) | ||
545 | 397 | |||
546 | 398 | def on_select_row(self, selection): | ||
547 | 399 | """ | ||
548 | 400 | Called when a row is selected. | ||
549 | 401 | """ | ||
550 | 402 | (model, row) = selection.get_selected() | ||
551 | 403 | if row is None: | ||
552 | 404 | return | ||
553 | 405 | |||
554 | 406 | attrib, new, old, edit = model.get(row, 1, 2, 3, 4) | ||
555 | 407 | |||
556 | 408 | databuffer = self.dataview.get_buffer() | ||
557 | 409 | tag = databuffer.get_tag_table().lookup("tag") | ||
558 | 410 | if new or old: | ||
559 | 411 | self.__set_textdiff(self.dataview.get_buffer(), old, new) | ||
560 | 412 | tag.set_property("background-set", False) | ||
561 | 413 | tag.set_property("foreground", "black") | ||
562 | 414 | else: | ||
563 | 415 | databuffer.set_text("No data") | ||
564 | 416 | self.__set_cell_property(tag, None) | ||
565 | 417 | tag.set_property("foreground", "grey") | ||
566 | 418 | |||
567 | 419 | bounds = databuffer.get_bounds() | ||
568 | 420 | databuffer.apply_tag(tag, bounds[0], bounds[1]) | ||
569 | 421 | |||
570 | 422 | # 0: Key | ||
571 | 423 | # 1: Value | ||
572 | 424 | # 2: Old value | ||
573 | 425 | # 3: "insert", "delete", "update", "" | ||
574 | 426 | |||
575 | 427 | attribstore = gtk.TreeStore(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT) | ||
576 | 428 | |||
577 | 429 | for key, (new, old, diff) in attrib.iteritems(): | ||
578 | 430 | attribstore.append(None, [key, new, old, diff]) | ||
579 | 431 | |||
580 | 432 | self.attribview.set_model(attribstore) | ||
581 | 433 | |||
582 | 434 | def __set_textdiff(self, databuffer, old, new): | ||
583 | 435 | text1 = old.splitlines() if old else [] | ||
584 | 436 | text2 = new.splitlines() if new else [] | ||
585 | 437 | |||
586 | 438 | from difflib import Differ | ||
587 | 439 | differ = Differ() | ||
588 | 440 | result = differ.compare(text1, text2) | ||
589 | 441 | result = [line + "\n" for line in result if not line.startswith("? ")] | ||
590 | 442 | |||
591 | 443 | databuffer.set_text("") | ||
592 | 444 | for line in result: | ||
593 | 445 | iter = databuffer.get_end_iter() | ||
594 | 446 | if line.startswith(" "): | ||
595 | 447 | databuffer.insert(iter, line) | ||
596 | 448 | elif line.startswith("+ "): | ||
597 | 449 | databuffer.insert_with_tags_by_name(iter, line, "add") | ||
598 | 450 | elif line.startswith("- "): | ||
599 | 451 | databuffer.insert_with_tags_by_name(iter, line, "rem") | ||
600 | 452 | |||
601 | 453 | |||
602 | 454 | def __create_tags(self, databuffer): | ||
603 | 455 | databuffer.create_tag("tag") | ||
604 | 456 | add = databuffer.create_tag("add") | ||
605 | 457 | rem = databuffer.create_tag("rem") | ||
606 | 458 | |||
607 | 459 | add.set_property("background", "lightgreen") | ||
608 | 460 | rem.set_property("background", "indianred") | ||
609 | 461 | |||
610 | 462 | def __set_cell_property(self, cell, edit): | ||
611 | 463 | if edit is None: | ||
612 | 464 | cell.set_property("foreground", "black") | ||
613 | 465 | elif edit == "insert": | ||
614 | 466 | cell.set_property("foreground", "green") | ||
615 | 467 | elif edit == "delete": | ||
616 | 468 | cell.set_property("foreground", "red") | ||
617 | 469 | elif edit == "update": | ||
618 | 470 | cell.set_property("foreground", "blue") | ||
619 | 471 | elif edit == "subupdate": | ||
620 | 472 | cell.set_property("foreground", "cornflowerblue") | ||
621 | 473 | |||
622 | 474 | def set_celltext(self, column, cell, model, iter): | ||
623 | 475 | |||
624 | 476 | tag, text, edit = model.get(iter, 0, 2, 4) | ||
625 | 477 | |||
626 | 478 | cell.set_property("text", tag) | ||
627 | 479 | self.__set_cell_property(cell, edit) | ||
628 | 480 | |||
629 | 481 | def set_cellkey(self, column, cell, model, iter): | ||
630 | 482 | |||
631 | 483 | key, edit = model.get(iter, 0, 3) | ||
632 | 484 | cell.set_property("text", key) | ||
633 | 485 | self.__set_cell_property(cell, edit) | ||
634 | 486 | |||
635 | 487 | def set_cellvalue(self, column, cell, model, iter): | ||
636 | 488 | |||
637 | 489 | new, old, edit = model.get(iter, 1, 2, 3) | ||
638 | 490 | if edit == "delete": | ||
639 | 491 | cell.set_property("text", old) | ||
640 | 492 | else: | ||
641 | 493 | cell.set_property("text", new) | ||
642 | 494 | self.__set_cell_property(cell, edit) | ||
643 | 495 | |||
644 | 496 | def _get_focus_widget(self, parent): | ||
645 | 497 | """ | ||
646 | 498 | Gets the widget that is a child of parent with the focus. | ||
647 | 499 | """ | ||
648 | 500 | focus = parent.get_focus_child() | ||
649 | 501 | if focus is None or (focus.flags() & gtk.HAS_FOCUS): | ||
650 | 502 | return focus | ||
651 | 503 | else: | ||
652 | 504 | return self._get_focus_widget(focus) | ||
653 | 505 | |||
654 | 506 | def _handle_clipboard(self, widget, signal): | ||
655 | 507 | """ | ||
656 | 508 | This finds the currently focused widget. | ||
657 | 509 | If no widget is focused or the focused widget doesn't support | ||
658 | 510 | the given clipboard operation use the treeview (False), otherwise | ||
659 | 511 | signal the widget to handel the clipboard operation (True). | ||
660 | 512 | """ | ||
661 | 513 | widget = self._get_focus_widget(self) | ||
662 | 514 | |||
663 | 515 | if widget is None or widget is self.treeview: | ||
664 | 516 | return False | ||
665 | 517 | |||
666 | 518 | if gobject.signal_lookup(signal + "-clipboard", widget): | ||
667 | 519 | widget.emit(signal + "-clipboard") | ||
668 | 520 | return True | ||
669 | 521 | else: | ||
670 | 522 | return False | ||
671 | 523 | |||
672 | 524 | def __get_treestore(self, iter): | ||
673 | 525 | |||
674 | 526 | tag, attrib, text = self.treestore.get(iter, 0, 1, 2) | ||
675 | 527 | |||
676 | 528 | tree = etree.Element(tag) | ||
677 | 529 | |||
678 | 530 | for key, (newvalue, oldvalue, edit) in attrib.iteritems(): | ||
679 | 531 | tree.attrib[key] = newvalue | ||
680 | 532 | |||
681 | 533 | child_iter = self.treestore.iter_children(iter) | ||
682 | 534 | while child_iter: | ||
683 | 535 | child = self.__get_treestore(child_iter) | ||
684 | 536 | tree.append(child) | ||
685 | 537 | child_iter = self.treestore.iter_next(child_iter) | ||
686 | 538 | |||
687 | 539 | return tree | ||
688 | 540 | |||
689 | 541 | def on_copy(self, widget=None): | ||
690 | 542 | if self._handle_clipboard(widget, "copy"): | ||
691 | 543 | return | ||
692 | 544 | |||
693 | 545 | (model, row) = self.treeview.get_selection().get_selected() | ||
694 | 546 | if row is None: | ||
695 | 547 | return | ||
696 | 548 | |||
697 | 549 | tree = etree.ElementTree(self.__get_treestore(row)) | ||
698 | 550 | |||
699 | 551 | ios = StringIO.StringIO() | ||
700 | 552 | tree.write(ios, pretty_print = True, xml_declaration = False, encoding = "utf-8") | ||
701 | 553 | |||
702 | 554 | clipboard = gtk.clipboard_get() | ||
703 | 555 | clipboard.set_text(ios.getvalue()) | ||
704 | 556 | clipboard.store() | ||
705 | 557 | |||
706 | 558 | ios.close() | ||
707 | 0 | 559 | ||
708 | === modified file 'diamond/diamond/interface.py' | |||
709 | --- diamond/diamond/interface.py 2011-08-16 15:22:31 +0000 | |||
710 | +++ diamond/diamond/interface.py 2011-08-24 16:38:18 +0000 | |||
711 | @@ -18,6 +18,7 @@ | |||
712 | 18 | import os | 18 | import os |
713 | 19 | import os.path | 19 | import os.path |
714 | 20 | import re | 20 | import re |
715 | 21 | import time | ||
716 | 21 | import sys | 22 | import sys |
717 | 22 | import tempfile | 23 | import tempfile |
718 | 23 | import cStringIO as StringIO | 24 | import cStringIO as StringIO |
719 | @@ -47,6 +48,7 @@ | |||
720 | 47 | import descriptionwidget | 48 | import descriptionwidget |
721 | 48 | import databuttonswidget | 49 | import databuttonswidget |
722 | 49 | import datawidget | 50 | import datawidget |
723 | 51 | import diffview | ||
724 | 50 | import sliceview | 52 | import sliceview |
725 | 51 | 53 | ||
726 | 52 | from lxml import etree | 54 | from lxml import etree |
727 | @@ -140,6 +142,8 @@ | |||
728 | 140 | "on_copy": self.on_copy, | 142 | "on_copy": self.on_copy, |
729 | 141 | "on_paste": self.on_paste, | 143 | "on_paste": self.on_paste, |
730 | 142 | "on_slice": self.on_slice, | 144 | "on_slice": self.on_slice, |
731 | 145 | "on_diff": self.on_diff, | ||
732 | 146 | "on_diffsave": self.on_diffsave, | ||
733 | 143 | "on_group": self.on_group, | 147 | "on_group": self.on_group, |
734 | 144 | "on_ungroup": self.on_ungroup} | 148 | "on_ungroup": self.on_ungroup} |
735 | 145 | 149 | ||
736 | @@ -601,15 +605,16 @@ | |||
737 | 601 | "You should have received a copy of the GNU General Public License\n"+ | 605 | "You should have received a copy of the GNU General Public License\n"+ |
738 | 602 | "along with Diamond. If not, see http://www.gnu.org/licenses/.") | 606 | "along with Diamond. If not, see http://www.gnu.org/licenses/.") |
739 | 603 | 607 | ||
742 | 604 | logo = gtk.gdk.pixbuf_new_from_file(self.logofile) | 608 | if self.logofile is not None: |
743 | 605 | 609 | logo = gtk.gdk.pixbuf_new_from_file(self.logofile) | |
744 | 610 | about.set_logo(logo) | ||
745 | 611 | |||
746 | 606 | try: | 612 | try: |
747 | 607 | image = about.get_children()[0].get_children()[0].get_children()[0] | 613 | image = about.get_children()[0].get_children()[0].get_children()[0] |
748 | 608 | image.set_tooltip_text("Diamond: it's clearer than GEM") | 614 | image.set_tooltip_text("Diamond: it's clearer than GEM") |
749 | 609 | except: | 615 | except: |
750 | 610 | pass | 616 | pass |
753 | 611 | 617 | ||
752 | 612 | about.set_logo(logo) | ||
754 | 613 | about.show() | 618 | about.show() |
755 | 614 | 619 | ||
756 | 615 | return | 620 | return |
757 | @@ -730,13 +735,31 @@ | |||
758 | 730 | msg += "Warning: added xml attributes:\n" | 735 | msg += "Warning: added xml attributes:\n" |
759 | 731 | for ele in added_attrs: | 736 | for ele in added_attrs: |
760 | 732 | msg += ele + "\n" | 737 | msg += ele + "\n" |
762 | 733 | 738 | ||
763 | 734 | dialogs.long_message(self.main_window, msg) | 739 | dialogs.long_message(self.main_window, msg) |
766 | 735 | 740 | ||
767 | 736 | self.set_saved(False) | 741 | self.set_saved(False) |
768 | 737 | 742 | ||
769 | 738 | return | 743 | return |
770 | 739 | 744 | ||
771 | 745 | def __diff(self, path): | ||
772 | 746 | self.statusbar.set_statusbar("Calculating diff... (this may take a while)") | ||
773 | 747 | start = time.clock() | ||
774 | 748 | diffview.DiffView(path, self.tree) | ||
775 | 749 | seconds = time.clock() - start | ||
776 | 750 | self.statusbar.set_statusbar("Diff calculated (took " + str(seconds) + " seconds)") | ||
777 | 751 | |||
778 | 752 | def on_diff(self, widget = None, path = None): | ||
779 | 753 | if path is None: | ||
780 | 754 | path = os.path.dirname(self.filename) if self.filename else None | ||
781 | 755 | self.__diff(path) | ||
782 | 756 | |||
783 | 757 | def on_diffsave(self, widget = None): | ||
784 | 758 | if self.filename: | ||
785 | 759 | self.__diff(self.filename) | ||
786 | 760 | else: | ||
787 | 761 | dialogs.error(self.main_window, "No save to diff against.") | ||
788 | 762 | |||
789 | 740 | def on_slice(self, widget = None): | 763 | def on_slice(self, widget = None): |
790 | 741 | if not self.selected_node.is_sliceable(): | 764 | if not self.selected_node.is_sliceable(): |
791 | 742 | self.statusbar.set_statusbar("Cannot slice on this element.") | 765 | self.statusbar.set_statusbar("Cannot slice on this element.") |
792 | 743 | 766 | ||
793 | === modified file 'diamond/diamond/triangle_reader.py' (properties changed: +x to -x) | |||
794 | === modified file 'diamond/gui/gui.glade' | |||
795 | --- diamond/gui/gui.glade 2011-07-26 11:06:34 +0000 | |||
796 | +++ diamond/gui/gui.glade 2011-08-24 16:38:18 +0000 | |||
797 | @@ -131,7 +131,7 @@ | |||
798 | 131 | <signal name="activate" handler="on_paste"/> | 131 | <signal name="activate" handler="on_paste"/> |
799 | 132 | <accelerator key="V" signal="activate" modifiers="GDK_CONTROL_MASK"/> | 132 | <accelerator key="V" signal="activate" modifiers="GDK_CONTROL_MASK"/> |
800 | 133 | </widget> | 133 | </widget> |
802 | 134 | </child> | 134 | </child> |
803 | 135 | <child> | 135 | <child> |
804 | 136 | <widget class="GtkMenuItem" id="menuitemGroup"> | 136 | <widget class="GtkMenuItem" id="menuitemGroup"> |
805 | 137 | <property name="visible">True</property> | 137 | <property name="visible">True</property> |
806 | @@ -221,6 +221,20 @@ | |||
807 | 221 | <widget class="GtkMenu" id="menu4"> | 221 | <widget class="GtkMenu" id="menu4"> |
808 | 222 | <property name="visible">True</property> | 222 | <property name="visible">True</property> |
809 | 223 | <child> | 223 | <child> |
810 | 224 | <widget class="GtkMenuItem" id="menuitemDiff"> | ||
811 | 225 | <property name="visible">True</property> | ||
812 | 226 | <property name="label" translatable="yes">Diff</property> | ||
813 | 227 | <signal name="activate" handler="on_diff"/> | ||
814 | 228 | </widget> | ||
815 | 229 | </child> | ||
816 | 230 | <child> | ||
817 | 231 | <widget class="GtkMenuItem" id="menuitemDiffSave"> | ||
818 | 232 | <property name="visible">True</property> | ||
819 | 233 | <property name="label" translatable="yes">Diff against last save</property> | ||
820 | 234 | <signal name="activate" handler="on_diffsave"/> | ||
821 | 235 | </widget> | ||
822 | 236 | </child> | ||
823 | 237 | <child> | ||
824 | 224 | <widget class="GtkCheckMenuItem" id="display_properties"> | 238 | <widget class="GtkCheckMenuItem" id="display_properties"> |
825 | 225 | <property name="visible">True</property> | 239 | <property name="visible">True</property> |
826 | 226 | <property name="tooltip" translatable="yes">Display the option properties on the right hand side of the main window.</property> | 240 | <property name="tooltip" translatable="yes">Display the option properties on the right hand side of the main window.</property> |
827 | 227 | 241 | ||
828 | === modified file 'diamond/tests/plist/plist.py' (properties changed: +x to -x) | |||
829 | === modified file 'diamond/tests/read_xml/find_hidden_xmldata.py' (properties changed: +x to -x) | |||
830 | === modified file 'diamond/tests/schema/test_simple_schema.py' (properties changed: +x to -x) | |||
831 | === added directory 'dxdiff' | |||
832 | === added file 'dxdiff/COPYING' | |||
833 | --- dxdiff/COPYING 1970-01-01 00:00:00 +0000 | |||
834 | +++ dxdiff/COPYING 2011-08-24 16:38:18 +0000 | |||
835 | @@ -0,0 +1,15 @@ | |||
836 | 1 | dxdiff is copyright (C) 2011 Imperial College London and others. | ||
837 | 2 | For a full list of contributors see the AUTHORS file. | ||
838 | 3 | |||
839 | 4 | dxdiff is free software: you can redistribute it and/or modify | ||
840 | 5 | it under the terms of the GNU General Public License as published by | ||
841 | 6 | the Free Software Foundation, either version 3 of the License, or | ||
842 | 7 | (at your option) any later version. | ||
843 | 8 | |||
844 | 9 | This program is distributed in the hope that it will be useful, | ||
845 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
846 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
847 | 12 | GNU General Public License for more details. | ||
848 | 13 | |||
849 | 14 | The complete text of the GNU General Public License can be found | ||
850 | 15 | in the file `GPL-3'. | ||
851 | 0 | 16 | ||
852 | === added file 'dxdiff/GPL-3' | |||
853 | --- dxdiff/GPL-3 1970-01-01 00:00:00 +0000 | |||
854 | +++ dxdiff/GPL-3 2011-08-24 16:38:18 +0000 | |||
855 | @@ -0,0 +1,676 @@ | |||
856 | 1 | |||
857 | 2 | GNU GENERAL PUBLIC LICENSE | ||
858 | 3 | Version 3, 29 June 2007 | ||
859 | 4 | |||
860 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | ||
861 | 6 | Everyone is permitted to copy and distribute verbatim copies | ||
862 | 7 | of this license document, but changing it is not allowed. | ||
863 | 8 | |||
864 | 9 | Preamble | ||
865 | 10 | |||
866 | 11 | The GNU General Public License is a free, copyleft license for | ||
867 | 12 | software and other kinds of works. | ||
868 | 13 | |||
869 | 14 | The licenses for most software and other practical works are designed | ||
870 | 15 | to take away your freedom to share and change the works. By contrast, | ||
871 | 16 | the GNU General Public License is intended to guarantee your freedom to | ||
872 | 17 | share and change all versions of a program--to make sure it remains free | ||
873 | 18 | software for all its users. We, the Free Software Foundation, use the | ||
874 | 19 | GNU General Public License for most of our software; it applies also to | ||
875 | 20 | any other work released this way by its authors. You can apply it to | ||
876 | 21 | your programs, too. | ||
877 | 22 | |||
878 | 23 | When we speak of free software, we are referring to freedom, not | ||
879 | 24 | price. Our General Public Licenses are designed to make sure that you | ||
880 | 25 | have the freedom to distribute copies of free software (and charge for | ||
881 | 26 | them if you wish), that you receive source code or can get it if you | ||
882 | 27 | want it, that you can change the software or use pieces of it in new | ||
883 | 28 | free programs, and that you know you can do these things. | ||
884 | 29 | |||
885 | 30 | To protect your rights, we need to prevent others from denying you | ||
886 | 31 | these rights or asking you to surrender the rights. Therefore, you have | ||
887 | 32 | certain responsibilities if you distribute copies of the software, or if | ||
888 | 33 | you modify it: responsibilities to respect the freedom of others. | ||
889 | 34 | |||
890 | 35 | For example, if you distribute copies of such a program, whether | ||
891 | 36 | gratis or for a fee, you must pass on to the recipients the same | ||
892 | 37 | freedoms that you received. You must make sure that they, too, receive | ||
893 | 38 | or can get the source code. And you must show them these terms so they | ||
894 | 39 | know their rights. | ||
895 | 40 | |||
896 | 41 | Developers that use the GNU GPL protect your rights with two steps: | ||
897 | 42 | (1) assert copyright on the software, and (2) offer you this License | ||
898 | 43 | giving you legal permission to copy, distribute and/or modify it. | ||
899 | 44 | |||
900 | 45 | For the developers' and authors' protection, the GPL clearly explains | ||
901 | 46 | that there is no warranty for this free software. For both users' and | ||
902 | 47 | authors' sake, the GPL requires that modified versions be marked as | ||
903 | 48 | changed, so that their problems will not be attributed erroneously to | ||
904 | 49 | authors of previous versions. | ||
905 | 50 | |||
906 | 51 | Some devices are designed to deny users access to install or run | ||
907 | 52 | modified versions of the software inside them, although the manufacturer | ||
908 | 53 | can do so. This is fundamentally incompatible with the aim of | ||
909 | 54 | protecting users' freedom to change the software. The systematic | ||
910 | 55 | pattern of such abuse occurs in the area of products for individuals to | ||
911 | 56 | use, which is precisely where it is most unacceptable. Therefore, we | ||
912 | 57 | have designed this version of the GPL to prohibit the practice for those | ||
913 | 58 | products. If such problems arise substantially in other domains, we | ||
914 | 59 | stand ready to extend this provision to those domains in future versions | ||
915 | 60 | of the GPL, as needed to protect the freedom of users. | ||
916 | 61 | |||
917 | 62 | Finally, every program is threatened constantly by software patents. | ||
918 | 63 | States should not allow patents to restrict development and use of | ||
919 | 64 | software on general-purpose computers, but in those that do, we wish to | ||
920 | 65 | avoid the special danger that patents applied to a free program could | ||
921 | 66 | make it effectively proprietary. To prevent this, the GPL assures that | ||
922 | 67 | patents cannot be used to render the program non-free. | ||
923 | 68 | |||
924 | 69 | The precise terms and conditions for copying, distribution and | ||
925 | 70 | modification follow. | ||
926 | 71 | |||
927 | 72 | TERMS AND CONDITIONS | ||
928 | 73 | |||
929 | 74 | 0. Definitions. | ||
930 | 75 | |||
931 | 76 | "This License" refers to version 3 of the GNU General Public License. | ||
932 | 77 | |||
933 | 78 | "Copyright" also means copyright-like laws that apply to other kinds of | ||
934 | 79 | works, such as semiconductor masks. | ||
935 | 80 | |||
936 | 81 | "The Program" refers to any copyrightable work licensed under this | ||
937 | 82 | License. Each licensee is addressed as "you". "Licensees" and | ||
938 | 83 | "recipients" may be individuals or organizations. | ||
939 | 84 | |||
940 | 85 | To "modify" a work means to copy from or adapt all or part of the work | ||
941 | 86 | in a fashion requiring copyright permission, other than the making of an | ||
942 | 87 | exact copy. The resulting work is called a "modified version" of the | ||
943 | 88 | earlier work or a work "based on" the earlier work. | ||
944 | 89 | |||
945 | 90 | A "covered work" means either the unmodified Program or a work based | ||
946 | 91 | on the Program. | ||
947 | 92 | |||
948 | 93 | To "propagate" a work means to do anything with it that, without | ||
949 | 94 | permission, would make you directly or secondarily liable for | ||
950 | 95 | infringement under applicable copyright law, except executing it on a | ||
951 | 96 | computer or modifying a private copy. Propagation includes copying, | ||
952 | 97 | distribution (with or without modification), making available to the | ||
953 | 98 | public, and in some countries other activities as well. | ||
954 | 99 | |||
955 | 100 | To "convey" a work means any kind of propagation that enables other | ||
956 | 101 | parties to make or receive copies. Mere interaction with a user through | ||
957 | 102 | a computer network, with no transfer of a copy, is not conveying. | ||
958 | 103 | |||
959 | 104 | An interactive user interface displays "Appropriate Legal Notices" | ||
960 | 105 | to the extent that it includes a convenient and prominently visible | ||
961 | 106 | feature that (1) displays an appropriate copyright notice, and (2) | ||
962 | 107 | tells the user that there is no warranty for the work (except to the | ||
963 | 108 | extent that warranties are provided), that licensees may convey the | ||
964 | 109 | work under this License, and how to view a copy of this License. If | ||
965 | 110 | the interface presents a list of user commands or options, such as a | ||
966 | 111 | menu, a prominent item in the list meets this criterion. | ||
967 | 112 | |||
968 | 113 | 1. Source Code. | ||
969 | 114 | |||
970 | 115 | The "source code" for a work means the preferred form of the work | ||
971 | 116 | for making modifications to it. "Object code" means any non-source | ||
972 | 117 | form of a work. | ||
973 | 118 | |||
974 | 119 | A "Standard Interface" means an interface that either is an official | ||
975 | 120 | standard defined by a recognized standards body, or, in the case of | ||
976 | 121 | interfaces specified for a particular programming language, one that | ||
977 | 122 | is widely used among developers working in that language. | ||
978 | 123 | |||
979 | 124 | The "System Libraries" of an executable work include anything, other | ||
980 | 125 | than the work as a whole, that (a) is included in the normal form of | ||
981 | 126 | packaging a Major Component, but which is not part of that Major | ||
982 | 127 | Component, and (b) serves only to enable use of the work with that | ||
983 | 128 | Major Component, or to implement a Standard Interface for which an | ||
984 | 129 | implementation is available to the public in source code form. A | ||
985 | 130 | "Major Component", in this context, means a major essential component | ||
986 | 131 | (kernel, window system, and so on) of the specific operating system | ||
987 | 132 | (if any) on which the executable work runs, or a compiler used to | ||
988 | 133 | produce the work, or an object code interpreter used to run it. | ||
989 | 134 | |||
990 | 135 | The "Corresponding Source" for a work in object code form means all | ||
991 | 136 | the source code needed to generate, install, and (for an executable | ||
992 | 137 | work) run the object code and to modify the work, including scripts to | ||
993 | 138 | control those activities. However, it does not include the work's | ||
994 | 139 | System Libraries, or general-purpose tools or generally available free | ||
995 | 140 | programs which are used unmodified in performing those activities but | ||
996 | 141 | which are not part of the work. For example, Corresponding Source | ||
997 | 142 | includes interface definition files associated with source files for | ||
998 | 143 | the work, and the source code for shared libraries and dynamically | ||
999 | 144 | linked subprograms that the work is specifically designed to require, | ||
1000 | 145 | such as by intimate data communication or control flow between those | ||
1001 | 146 | subprograms and other parts of the work. | ||
1002 | 147 | |||
1003 | 148 | The Corresponding Source need not include anything that users | ||
1004 | 149 | can regenerate automatically from other parts of the Corresponding | ||
1005 | 150 | Source. | ||
1006 | 151 | |||
1007 | 152 | The Corresponding Source for a work in source code form is that | ||
1008 | 153 | same work. | ||
1009 | 154 | |||
1010 | 155 | 2. Basic Permissions. | ||
1011 | 156 | |||
1012 | 157 | All rights granted under this License are granted for the term of | ||
1013 | 158 | copyright on the Program, and are irrevocable provided the stated | ||
1014 | 159 | conditions are met. This License explicitly affirms your unlimited | ||
1015 | 160 | permission to run the unmodified Program. The output from running a | ||
1016 | 161 | covered work is covered by this License only if the output, given its | ||
1017 | 162 | content, constitutes a covered work. This License acknowledges your | ||
1018 | 163 | rights of fair use or other equivalent, as provided by copyright law. | ||
1019 | 164 | |||
1020 | 165 | You may make, run and propagate covered works that you do not | ||
1021 | 166 | convey, without conditions so long as your license otherwise remains | ||
1022 | 167 | in force. You may convey covered works to others for the sole purpose | ||
1023 | 168 | of having them make modifications exclusively for you, or provide you | ||
1024 | 169 | with facilities for running those works, provided that you comply with | ||
1025 | 170 | the terms of this License in conveying all material for which you do | ||
1026 | 171 | not control copyright. Those thus making or running the covered works | ||
1027 | 172 | for you must do so exclusively on your behalf, under your direction | ||
1028 | 173 | and control, on terms that prohibit them from making any copies of | ||
1029 | 174 | your copyrighted material outside their relationship with you. | ||
1030 | 175 | |||
1031 | 176 | Conveying under any other circumstances is permitted solely under | ||
1032 | 177 | the conditions stated below. Sublicensing is not allowed; section 10 | ||
1033 | 178 | makes it unnecessary. | ||
1034 | 179 | |||
1035 | 180 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. | ||
1036 | 181 | |||
1037 | 182 | No covered work shall be deemed part of an effective technological | ||
1038 | 183 | measure under any applicable law fulfilling obligations under article | ||
1039 | 184 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or | ||
1040 | 185 | similar laws prohibiting or restricting circumvention of such | ||
1041 | 186 | measures. | ||
1042 | 187 | |||
1043 | 188 | When you convey a covered work, you waive any legal power to forbid | ||
1044 | 189 | circumvention of technological measures to the extent such circumvention | ||
1045 | 190 | is effected by exercising rights under this License with respect to | ||
1046 | 191 | the covered work, and you disclaim any intention to limit operation or | ||
1047 | 192 | modification of the work as a means of enforcing, against the work's | ||
1048 | 193 | users, your or third parties' legal rights to forbid circumvention of | ||
1049 | 194 | technological measures. | ||
1050 | 195 | |||
1051 | 196 | 4. Conveying Verbatim Copies. | ||
1052 | 197 | |||
1053 | 198 | You may convey verbatim copies of the Program's source code as you | ||
1054 | 199 | receive it, in any medium, provided that you conspicuously and | ||
1055 | 200 | appropriately publish on each copy an appropriate copyright notice; | ||
1056 | 201 | keep intact all notices stating that this License and any | ||
1057 | 202 | non-permissive terms added in accord with section 7 apply to the code; | ||
1058 | 203 | keep intact all notices of the absence of any warranty; and give all | ||
1059 | 204 | recipients a copy of this License along with the Program. | ||
1060 | 205 | |||
1061 | 206 | You may charge any price or no price for each copy that you convey, | ||
1062 | 207 | and you may offer support or warranty protection for a fee. | ||
1063 | 208 | |||
1064 | 209 | 5. Conveying Modified Source Versions. | ||
1065 | 210 | |||
1066 | 211 | You may convey a work based on the Program, or the modifications to | ||
1067 | 212 | produce it from the Program, in the form of source code under the | ||
1068 | 213 | terms of section 4, provided that you also meet all of these conditions: | ||
1069 | 214 | |||
1070 | 215 | a) The work must carry prominent notices stating that you modified | ||
1071 | 216 | it, and giving a relevant date. | ||
1072 | 217 | |||
1073 | 218 | b) The work must carry prominent notices stating that it is | ||
1074 | 219 | released under this License and any conditions added under section | ||
1075 | 220 | 7. This requirement modifies the requirement in section 4 to | ||
1076 | 221 | "keep intact all notices". | ||
1077 | 222 | |||
1078 | 223 | c) You must license the entire work, as a whole, under this | ||
1079 | 224 | License to anyone who comes into possession of a copy. This | ||
1080 | 225 | License will therefore apply, along with any applicable section 7 | ||
1081 | 226 | additional terms, to the whole of the work, and all its parts, | ||
1082 | 227 | regardless of how they are packaged. This License gives no | ||
1083 | 228 | permission to license the work in any other way, but it does not | ||
1084 | 229 | invalidate such permission if you have separately received it. | ||
1085 | 230 | |||
1086 | 231 | d) If the work has interactive user interfaces, each must display | ||
1087 | 232 | Appropriate Legal Notices; however, if the Program has interactive | ||
1088 | 233 | interfaces that do not display Appropriate Legal Notices, your | ||
1089 | 234 | work need not make them do so. | ||
1090 | 235 | |||
1091 | 236 | A compilation of a covered work with other separate and independent | ||
1092 | 237 | works, which are not by their nature extensions of the covered work, | ||
1093 | 238 | and which are not combined with it such as to form a larger program, | ||
1094 | 239 | in or on a volume of a storage or distribution medium, is called an | ||
1095 | 240 | "aggregate" if the compilation and its resulting copyright are not | ||
1096 | 241 | used to limit the access or legal rights of the compilation's users | ||
1097 | 242 | beyond what the individual works permit. Inclusion of a covered work | ||
1098 | 243 | in an aggregate does not cause this License to apply to the other | ||
1099 | 244 | parts of the aggregate. | ||
1100 | 245 | |||
1101 | 246 | 6. Conveying Non-Source Forms. | ||
1102 | 247 | |||
1103 | 248 | You may convey a covered work in object code form under the terms | ||
1104 | 249 | of sections 4 and 5, provided that you also convey the | ||
1105 | 250 | machine-readable Corresponding Source under the terms of this License, | ||
1106 | 251 | in one of these ways: | ||
1107 | 252 | |||
1108 | 253 | a) Convey the object code in, or embodied in, a physical product | ||
1109 | 254 | (including a physical distribution medium), accompanied by the | ||
1110 | 255 | Corresponding Source fixed on a durable physical medium | ||
1111 | 256 | customarily used for software interchange. | ||
1112 | 257 | |||
1113 | 258 | b) Convey the object code in, or embodied in, a physical product | ||
1114 | 259 | (including a physical distribution medium), accompanied by a | ||
1115 | 260 | written offer, valid for at least three years and valid for as | ||
1116 | 261 | long as you offer spare parts or customer support for that product | ||
1117 | 262 | model, to give anyone who possesses the object code either (1) a | ||
1118 | 263 | copy of the Corresponding Source for all the software in the | ||
1119 | 264 | product that is covered by this License, on a durable physical | ||
1120 | 265 | medium customarily used for software interchange, for a price no | ||
1121 | 266 | more than your reasonable cost of physically performing this | ||
1122 | 267 | conveying of source, or (2) access to copy the | ||
1123 | 268 | Corresponding Source from a network server at no charge. | ||
1124 | 269 | |||
1125 | 270 | c) Convey individual copies of the object code with a copy of the | ||
1126 | 271 | written offer to provide the Corresponding Source. This | ||
1127 | 272 | alternative is allowed only occasionally and noncommercially, and | ||
1128 | 273 | only if you received the object code with such an offer, in accord | ||
1129 | 274 | with subsection 6b. | ||
1130 | 275 | |||
1131 | 276 | d) Convey the object code by offering access from a designated | ||
1132 | 277 | place (gratis or for a charge), and offer equivalent access to the | ||
1133 | 278 | Corresponding Source in the same way through the same place at no | ||
1134 | 279 | further charge. You need not require recipients to copy the | ||
1135 | 280 | Corresponding Source along with the object code. If the place to | ||
1136 | 281 | copy the object code is a network server, the Corresponding Source | ||
1137 | 282 | may be on a different server (operated by you or a third party) | ||
1138 | 283 | that supports equivalent copying facilities, provided you maintain | ||
1139 | 284 | clear directions next to the object code saying where to find the | ||
1140 | 285 | Corresponding Source. Regardless of what server hosts the | ||
1141 | 286 | Corresponding Source, you remain obligated to ensure that it is | ||
1142 | 287 | available for as long as needed to satisfy these requirements. | ||
1143 | 288 | |||
1144 | 289 | e) Convey the object code using peer-to-peer transmission, provided | ||
1145 | 290 | you inform other peers where the object code and Corresponding | ||
1146 | 291 | Source of the work are being offered to the general public at no | ||
1147 | 292 | charge under subsection 6d. | ||
1148 | 293 | |||
1149 | 294 | A separable portion of the object code, whose source code is excluded | ||
1150 | 295 | from the Corresponding Source as a System Library, need not be | ||
1151 | 296 | included in conveying the object code work. | ||
1152 | 297 | |||
1153 | 298 | A "User Product" is either (1) a "consumer product", which means any | ||
1154 | 299 | tangible personal property which is normally used for personal, family, | ||
1155 | 300 | or household purposes, or (2) anything designed or sold for incorporation | ||
1156 | 301 | into a dwelling. In determining whether a product is a consumer product, | ||
1157 | 302 | doubtful cases shall be resolved in favor of coverage. For a particular | ||
1158 | 303 | product received by a particular user, "normally used" refers to a | ||
1159 | 304 | typical or common use of that class of product, regardless of the status | ||
1160 | 305 | of the particular user or of the way in which the particular user | ||
1161 | 306 | actually uses, or expects or is expected to use, the product. A product | ||
1162 | 307 | is a consumer product regardless of whether the product has substantial | ||
1163 | 308 | commercial, industrial or non-consumer uses, unless such uses represent | ||
1164 | 309 | the only significant mode of use of the product. | ||
1165 | 310 | |||
1166 | 311 | "Installation Information" for a User Product means any methods, | ||
1167 | 312 | procedures, authorization keys, or other information required to install | ||
1168 | 313 | and execute modified versions of a covered work in that User Product from | ||
1169 | 314 | a modified version of its Corresponding Source. The information must | ||
1170 | 315 | suffice to ensure that the continued functioning of the modified object | ||
1171 | 316 | code is in no case prevented or interfered with solely because | ||
1172 | 317 | modification has been made. | ||
1173 | 318 | |||
1174 | 319 | If you convey an object code work under this section in, or with, or | ||
1175 | 320 | specifically for use in, a User Product, and the conveying occurs as | ||
1176 | 321 | part of a transaction in which the right of possession and use of the | ||
1177 | 322 | User Product is transferred to the recipient in perpetuity or for a | ||
1178 | 323 | fixed term (regardless of how the transaction is characterized), the | ||
1179 | 324 | Corresponding Source conveyed under this section must be accompanied | ||
1180 | 325 | by the Installation Information. But this requirement does not apply | ||
1181 | 326 | if neither you nor any third party retains the ability to install | ||
1182 | 327 | modified object code on the User Product (for example, the work has | ||
1183 | 328 | been installed in ROM). | ||
1184 | 329 | |||
1185 | 330 | The requirement to provide Installation Information does not include a | ||
1186 | 331 | requirement to continue to provide support service, warranty, or updates | ||
1187 | 332 | for a work that has been modified or installed by the recipient, or for | ||
1188 | 333 | the User Product in which it has been modified or installed. Access to a | ||
1189 | 334 | network may be denied when the modification itself materially and | ||
1190 | 335 | adversely affects the operation of the network or violates the rules and | ||
1191 | 336 | protocols for communication across the network. | ||
1192 | 337 | |||
1193 | 338 | Corresponding Source conveyed, and Installation Information provided, | ||
1194 | 339 | in accord with this section must be in a format that is publicly | ||
1195 | 340 | documented (and with an implementation available to the public in | ||
1196 | 341 | source code form), and must require no special password or key for | ||
1197 | 342 | unpacking, reading or copying. | ||
1198 | 343 | |||
1199 | 344 | 7. Additional Terms. | ||
1200 | 345 | |||
1201 | 346 | "Additional permissions" are terms that supplement the terms of this | ||
1202 | 347 | License by making exceptions from one or more of its conditions. | ||
1203 | 348 | Additional permissions that are applicable to the entire Program shall | ||
1204 | 349 | be treated as though they were included in this License, to the extent | ||
1205 | 350 | that they are valid under applicable law. If additional permissions | ||
1206 | 351 | apply only to part of the Program, that part may be used separately | ||
1207 | 352 | under those permissions, but the entire Program remains governed by | ||
1208 | 353 | this License without regard to the additional permissions. | ||
1209 | 354 | |||
1210 | 355 | When you convey a copy of a covered work, you may at your option | ||
1211 | 356 | remove any additional permissions from that copy, or from any part of | ||
1212 | 357 | it. (Additional permissions may be written to require their own | ||
1213 | 358 | removal in certain cases when you modify the work.) You may place | ||
1214 | 359 | additional permissions on material, added by you to a covered work, | ||
1215 | 360 | for which you have or can give appropriate copyright permission. | ||
1216 | 361 | |||
1217 | 362 | Notwithstanding any other provision of this License, for material you | ||
1218 | 363 | add to a covered work, you may (if authorized by the copyright holders of | ||
1219 | 364 | that material) supplement the terms of this License with terms: | ||
1220 | 365 | |||
1221 | 366 | a) Disclaiming warranty or limiting liability differently from the | ||
1222 | 367 | terms of sections 15 and 16 of this License; or | ||
1223 | 368 | |||
1224 | 369 | b) Requiring preservation of specified reasonable legal notices or | ||
1225 | 370 | author attributions in that material or in the Appropriate Legal | ||
1226 | 371 | Notices displayed by works containing it; or | ||
1227 | 372 | |||
1228 | 373 | c) Prohibiting misrepresentation of the origin of that material, or | ||
1229 | 374 | requiring that modified versions of such material be marked in | ||
1230 | 375 | reasonable ways as different from the original version; or | ||
1231 | 376 | |||
1232 | 377 | d) Limiting the use for publicity purposes of names of licensors or | ||
1233 | 378 | authors of the material; or | ||
1234 | 379 | |||
1235 | 380 | e) Declining to grant rights under trademark law for use of some | ||
1236 | 381 | trade names, trademarks, or service marks; or | ||
1237 | 382 | |||
1238 | 383 | f) Requiring indemnification of licensors and authors of that | ||
1239 | 384 | material by anyone who conveys the material (or modified versions of | ||
1240 | 385 | it) with contractual assumptions of liability to the recipient, for | ||
1241 | 386 | any liability that these contractual assumptions directly impose on | ||
1242 | 387 | those licensors and authors. | ||
1243 | 388 | |||
1244 | 389 | All other non-permissive additional terms are considered "further | ||
1245 | 390 | restrictions" within the meaning of section 10. If the Program as you | ||
1246 | 391 | received it, or any part of it, contains a notice stating that it is | ||
1247 | 392 | governed by this License along with a term that is a further | ||
1248 | 393 | restriction, you may remove that term. If a license document contains | ||
1249 | 394 | a further restriction but permits relicensing or conveying under this | ||
1250 | 395 | License, you may add to a covered work material governed by the terms | ||
1251 | 396 | of that license document, provided that the further restriction does | ||
1252 | 397 | not survive such relicensing or conveying. | ||
1253 | 398 | |||
1254 | 399 | If you add terms to a covered work in accord with this section, you | ||
1255 | 400 | must place, in the relevant source files, a statement of the | ||
1256 | 401 | additional terms that apply to those files, or a notice indicating | ||
1257 | 402 | where to find the applicable terms. | ||
1258 | 403 | |||
1259 | 404 | Additional terms, permissive or non-permissive, may be stated in the | ||
1260 | 405 | form of a separately written license, or stated as exceptions; | ||
1261 | 406 | the above requirements apply either way. | ||
1262 | 407 | |||
1263 | 408 | 8. Termination. | ||
1264 | 409 | |||
1265 | 410 | You may not propagate or modify a covered work except as expressly | ||
1266 | 411 | provided under this License. Any attempt otherwise to propagate or | ||
1267 | 412 | modify it is void, and will automatically terminate your rights under | ||
1268 | 413 | this License (including any patent licenses granted under the third | ||
1269 | 414 | paragraph of section 11). | ||
1270 | 415 | |||
1271 | 416 | However, if you cease all violation of this License, then your | ||
1272 | 417 | license from a particular copyright holder is reinstated (a) | ||
1273 | 418 | provisionally, unless and until the copyright holder explicitly and | ||
1274 | 419 | finally terminates your license, and (b) permanently, if the copyright | ||
1275 | 420 | holder fails to notify you of the violation by some reasonable means | ||
1276 | 421 | prior to 60 days after the cessation. | ||
1277 | 422 | |||
1278 | 423 | Moreover, your license from a particular copyright holder is | ||
1279 | 424 | reinstated permanently if the copyright holder notifies you of the | ||
1280 | 425 | violation by some reasonable means, this is the first time you have | ||
1281 | 426 | received notice of violation of this License (for any work) from that | ||
1282 | 427 | copyright holder, and you cure the violation prior to 30 days after | ||
1283 | 428 | your receipt of the notice. | ||
1284 | 429 | |||
1285 | 430 | Termination of your rights under this section does not terminate the | ||
1286 | 431 | licenses of parties who have received copies or rights from you under | ||
1287 | 432 | this License. If your rights have been terminated and not permanently | ||
1288 | 433 | reinstated, you do not qualify to receive new licenses for the same | ||
1289 | 434 | material under section 10. | ||
1290 | 435 | |||
1291 | 436 | 9. Acceptance Not Required for Having Copies. | ||
1292 | 437 | |||
1293 | 438 | You are not required to accept this License in order to receive or | ||
1294 | 439 | run a copy of the Program. Ancillary propagation of a covered work | ||
1295 | 440 | occurring solely as a consequence of using peer-to-peer transmission | ||
1296 | 441 | to receive a copy likewise does not require acceptance. However, | ||
1297 | 442 | nothing other than this License grants you permission to propagate or | ||
1298 | 443 | modify any covered work. These actions infringe copyright if you do | ||
1299 | 444 | not accept this License. Therefore, by modifying or propagating a | ||
1300 | 445 | covered work, you indicate your acceptance of this License to do so. | ||
1301 | 446 | |||
1302 | 447 | 10. Automatic Licensing of Downstream Recipients. | ||
1303 | 448 | |||
1304 | 449 | Each time you convey a covered work, the recipient automatically | ||
1305 | 450 | receives a license from the original licensors, to run, modify and | ||
1306 | 451 | propagate that work, subject to this License. You are not responsible | ||
1307 | 452 | for enforcing compliance by third parties with this License. | ||
1308 | 453 | |||
1309 | 454 | An "entity transaction" is a transaction transferring control of an | ||
1310 | 455 | organization, or substantially all assets of one, or subdividing an | ||
1311 | 456 | organization, or merging organizations. If propagation of a covered | ||
1312 | 457 | work results from an entity transaction, each party to that | ||
1313 | 458 | transaction who receives a copy of the work also receives whatever | ||
1314 | 459 | licenses to the work the party's predecessor in interest had or could | ||
1315 | 460 | give under the previous paragraph, plus a right to possession of the | ||
1316 | 461 | Corresponding Source of the work from the predecessor in interest, if | ||
1317 | 462 | the predecessor has it or can get it with reasonable efforts. | ||
1318 | 463 | |||
1319 | 464 | You may not impose any further restrictions on the exercise of the | ||
1320 | 465 | rights granted or affirmed under this License. For example, you may | ||
1321 | 466 | not impose a license fee, royalty, or other charge for exercise of | ||
1322 | 467 | rights granted under this License, and you may not initiate litigation | ||
1323 | 468 | (including a cross-claim or counterclaim in a lawsuit) alleging that | ||
1324 | 469 | any patent claim is infringed by making, using, selling, offering for | ||
1325 | 470 | sale, or importing the Program or any portion of it. | ||
1326 | 471 | |||
1327 | 472 | 11. Patents. | ||
1328 | 473 | |||
1329 | 474 | A "contributor" is a copyright holder who authorizes use under this | ||
1330 | 475 | License of the Program or a work on which the Program is based. The | ||
1331 | 476 | work thus licensed is called the contributor's "contributor version". | ||
1332 | 477 | |||
1333 | 478 | A contributor's "essential patent claims" are all patent claims | ||
1334 | 479 | owned or controlled by the contributor, whether already acquired or | ||
1335 | 480 | hereafter acquired, that would be infringed by some manner, permitted | ||
1336 | 481 | by this License, of making, using, or selling its contributor version, | ||
1337 | 482 | but do not include claims that would be infringed only as a | ||
1338 | 483 | consequence of further modification of the contributor version. For | ||
1339 | 484 | purposes of this definition, "control" includes the right to grant | ||
1340 | 485 | patent sublicenses in a manner consistent with the requirements of | ||
1341 | 486 | this License. | ||
1342 | 487 | |||
1343 | 488 | Each contributor grants you a non-exclusive, worldwide, royalty-free | ||
1344 | 489 | patent license under the contributor's essential patent claims, to | ||
1345 | 490 | make, use, sell, offer for sale, import and otherwise run, modify and | ||
1346 | 491 | propagate the contents of its contributor version. | ||
1347 | 492 | |||
1348 | 493 | In the following three paragraphs, a "patent license" is any express | ||
1349 | 494 | agreement or commitment, however denominated, not to enforce a patent | ||
1350 | 495 | (such as an express permission to practice a patent or covenant not to | ||
1351 | 496 | sue for patent infringement). To "grant" such a patent license to a | ||
1352 | 497 | party means to make such an agreement or commitment not to enforce a | ||
1353 | 498 | patent against the party. | ||
1354 | 499 | |||
1355 | 500 | If you convey a covered work, knowingly relying on a patent license, | ||
1356 | 501 | and the Corresponding Source of the work is not available for anyone | ||
1357 | 502 | to copy, free of charge and under the terms of this License, through a | ||
1358 | 503 | publicly available network server or other readily accessible means, | ||
1359 | 504 | then you must either (1) cause the Corresponding Source to be so | ||
1360 | 505 | available, or (2) arrange to deprive yourself of the benefit of the | ||
1361 | 506 | patent license for this particular work, or (3) arrange, in a manner | ||
1362 | 507 | consistent with the requirements of this License, to extend the patent | ||
1363 | 508 | license to downstream recipients. "Knowingly relying" means you have | ||
1364 | 509 | actual knowledge that, but for the patent license, your conveying the | ||
1365 | 510 | covered work in a country, or your recipient's use of the covered work | ||
1366 | 511 | in a country, would infringe one or more identifiable patents in that | ||
1367 | 512 | country that you have reason to believe are valid. | ||
1368 | 513 | |||
1369 | 514 | If, pursuant to or in connection with a single transaction or | ||
1370 | 515 | arrangement, you convey, or propagate by procuring conveyance of, a | ||
1371 | 516 | covered work, and grant a patent license to some of the parties | ||
1372 | 517 | receiving the covered work authorizing them to use, propagate, modify | ||
1373 | 518 | or convey a specific copy of the covered work, then the patent license | ||
1374 | 519 | you grant is automatically extended to all recipients of the covered | ||
1375 | 520 | work and works based on it. | ||
1376 | 521 | |||
1377 | 522 | A patent license is "discriminatory" if it does not include within | ||
1378 | 523 | the scope of its coverage, prohibits the exercise of, or is | ||
1379 | 524 | conditioned on the non-exercise of one or more of the rights that are | ||
1380 | 525 | specifically granted under this License. You may not convey a covered | ||
1381 | 526 | work if you are a party to an arrangement with a third party that is | ||
1382 | 527 | in the business of distributing software, under which you make payment | ||
1383 | 528 | to the third party based on the extent of your activity of conveying | ||
1384 | 529 | the work, and under which the third party grants, to any of the | ||
1385 | 530 | parties who would receive the covered work from you, a discriminatory | ||
1386 | 531 | patent license (a) in connection with copies of the covered work | ||
1387 | 532 | conveyed by you (or copies made from those copies), or (b) primarily | ||
1388 | 533 | for and in connection with specific products or compilations that | ||
1389 | 534 | contain the covered work, unless you entered into that arrangement, | ||
1390 | 535 | or that patent license was granted, prior to 28 March 2007. | ||
1391 | 536 | |||
1392 | 537 | Nothing in this License shall be construed as excluding or limiting | ||
1393 | 538 | any implied license or other defenses to infringement that may | ||
1394 | 539 | otherwise be available to you under applicable patent law. | ||
1395 | 540 | |||
1396 | 541 | 12. No Surrender of Others' Freedom. | ||
1397 | 542 | |||
1398 | 543 | If conditions are imposed on you (whether by court order, agreement or | ||
1399 | 544 | otherwise) that contradict the conditions of this License, they do not | ||
1400 | 545 | excuse you from the conditions of this License. If you cannot convey a | ||
1401 | 546 | covered work so as to satisfy simultaneously your obligations under this | ||
1402 | 547 | License and any other pertinent obligations, then as a consequence you may | ||
1403 | 548 | not convey it at all. For example, if you agree to terms that obligate you | ||
1404 | 549 | to collect a royalty for further conveying from those to whom you convey | ||
1405 | 550 | the Program, the only way you could satisfy both those terms and this | ||
1406 | 551 | License would be to refrain entirely from conveying the Program. | ||
1407 | 552 | |||
1408 | 553 | 13. Use with the GNU Affero General Public License. | ||
1409 | 554 | |||
1410 | 555 | Notwithstanding any other provision of this License, you have | ||
1411 | 556 | permission to link or combine any covered work with a work licensed | ||
1412 | 557 | under version 3 of the GNU Affero General Public License into a single | ||
1413 | 558 | combined work, and to convey the resulting work. The terms of this | ||
1414 | 559 | License will continue to apply to the part which is the covered work, | ||
1415 | 560 | but the special requirements of the GNU Affero General Public License, | ||
1416 | 561 | section 13, concerning interaction through a network will apply to the | ||
1417 | 562 | combination as such. | ||
1418 | 563 | |||
1419 | 564 | 14. Revised Versions of this License. | ||
1420 | 565 | |||
1421 | 566 | The Free Software Foundation may publish revised and/or new versions of | ||
1422 | 567 | the GNU General Public License from time to time. Such new versions will | ||
1423 | 568 | be similar in spirit to the present version, but may differ in detail to | ||
1424 | 569 | address new problems or concerns. | ||
1425 | 570 | |||
1426 | 571 | Each version is given a distinguishing version number. If the | ||
1427 | 572 | Program specifies that a certain numbered version of the GNU General | ||
1428 | 573 | Public License "or any later version" applies to it, you have the | ||
1429 | 574 | option of following the terms and conditions either of that numbered | ||
1430 | 575 | version or of any later version published by the Free Software | ||
1431 | 576 | Foundation. If the Program does not specify a version number of the | ||
1432 | 577 | GNU General Public License, you may choose any version ever published | ||
1433 | 578 | by the Free Software Foundation. | ||
1434 | 579 | |||
1435 | 580 | If the Program specifies that a proxy can decide which future | ||
1436 | 581 | versions of the GNU General Public License can be used, that proxy's | ||
1437 | 582 | public statement of acceptance of a version permanently authorizes you | ||
1438 | 583 | to choose that version for the Program. | ||
1439 | 584 | |||
1440 | 585 | Later license versions may give you additional or different | ||
1441 | 586 | permissions. However, no additional obligations are imposed on any | ||
1442 | 587 | author or copyright holder as a result of your choosing to follow a | ||
1443 | 588 | later version. | ||
1444 | 589 | |||
1445 | 590 | 15. Disclaimer of Warranty. | ||
1446 | 591 | |||
1447 | 592 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY | ||
1448 | 593 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT | ||
1449 | 594 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY | ||
1450 | 595 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, | ||
1451 | 596 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
1452 | 597 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM | ||
1453 | 598 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF | ||
1454 | 599 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | ||
1455 | 600 | |||
1456 | 601 | 16. Limitation of Liability. | ||
1457 | 602 | |||
1458 | 603 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||
1459 | 604 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS | ||
1460 | 605 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY | ||
1461 | 606 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE | ||
1462 | 607 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF | ||
1463 | 608 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD | ||
1464 | 609 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), | ||
1465 | 610 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | ||
1466 | 611 | SUCH DAMAGES. | ||
1467 | 612 | |||
1468 | 613 | 17. Interpretation of Sections 15 and 16. | ||
1469 | 614 | |||
1470 | 615 | If the disclaimer of warranty and limitation of liability provided | ||
1471 | 616 | above cannot be given local legal effect according to their terms, | ||
1472 | 617 | reviewing courts shall apply local law that most closely approximates | ||
1473 | 618 | an absolute waiver of all civil liability in connection with the | ||
1474 | 619 | Program, unless a warranty or assumption of liability accompanies a | ||
1475 | 620 | copy of the Program in return for a fee. | ||
1476 | 621 | |||
1477 | 622 | END OF TERMS AND CONDITIONS | ||
1478 | 623 | |||
1479 | 624 | How to Apply These Terms to Your New Programs | ||
1480 | 625 | |||
1481 | 626 | If you develop a new program, and you want it to be of the greatest | ||
1482 | 627 | possible use to the public, the best way to achieve this is to make it | ||
1483 | 628 | free software which everyone can redistribute and change under these terms. | ||
1484 | 629 | |||
1485 | 630 | To do so, attach the following notices to the program. It is safest | ||
1486 | 631 | to attach them to the start of each source file to most effectively | ||
1487 | 632 | state the exclusion of warranty; and each file should have at least | ||
1488 | 633 | the "copyright" line and a pointer to where the full notice is found. | ||
1489 | 634 | |||
1490 | 635 | <one line to give the program's name and a brief idea of what it does.> | ||
1491 | 636 | Copyright (C) <year> <name of author> | ||
1492 | 637 | |||
1493 | 638 | This program is free software: you can redistribute it and/or modify | ||
1494 | 639 | it under the terms of the GNU General Public License as published by | ||
1495 | 640 | the Free Software Foundation, either version 3 of the License, or | ||
1496 | 641 | (at your option) any later version. | ||
1497 | 642 | |||
1498 | 643 | This program is distributed in the hope that it will be useful, | ||
1499 | 644 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1500 | 645 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1501 | 646 | GNU General Public License for more details. | ||
1502 | 647 | |||
1503 | 648 | You should have received a copy of the GNU General Public License | ||
1504 | 649 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1505 | 650 | |||
1506 | 651 | Also add information on how to contact you by electronic and paper mail. | ||
1507 | 652 | |||
1508 | 653 | If the program does terminal interaction, make it output a short | ||
1509 | 654 | notice like this when it starts in an interactive mode: | ||
1510 | 655 | |||
1511 | 656 | <program> Copyright (C) <year> <name of author> | ||
1512 | 657 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||
1513 | 658 | This is free software, and you are welcome to redistribute it | ||
1514 | 659 | under certain conditions; type `show c' for details. | ||
1515 | 660 | |||
1516 | 661 | The hypothetical commands `show w' and `show c' should show the appropriate | ||
1517 | 662 | parts of the General Public License. Of course, your program's commands | ||
1518 | 663 | might be different; for a GUI interface, you would use an "about box". | ||
1519 | 664 | |||
1520 | 665 | You should also get your employer (if you work as a programmer) or school, | ||
1521 | 666 | if any, to sign a "copyright disclaimer" for the program, if necessary. | ||
1522 | 667 | For more information on this, and how to apply and follow the GNU GPL, see | ||
1523 | 668 | <http://www.gnu.org/licenses/>. | ||
1524 | 669 | |||
1525 | 670 | The GNU General Public License does not permit incorporating your program | ||
1526 | 671 | into proprietary programs. If your program is a subroutine library, you | ||
1527 | 672 | may consider it more useful to permit linking proprietary applications with | ||
1528 | 673 | the library. If this is what you want to do, use the GNU Lesser General | ||
1529 | 674 | Public License instead of this License. But first, please read | ||
1530 | 675 | <http://www.gnu.org/philosophy/why-not-lgpl.html>. | ||
1531 | 676 | |||
1532 | 0 | 677 | ||
1533 | === added directory 'dxdiff/dxdiff' | |||
1534 | === added file 'dxdiff/dxdiff/__init__.py' | |||
1535 | === added file 'dxdiff/dxdiff/bimap.py' | |||
1536 | --- dxdiff/dxdiff/bimap.py 1970-01-01 00:00:00 +0000 | |||
1537 | +++ dxdiff/dxdiff/bimap.py 2011-08-24 16:38:18 +0000 | |||
1538 | @@ -0,0 +1,49 @@ | |||
1539 | 1 | #!/usr/bin/env python | ||
1540 | 2 | |||
1541 | 3 | # This file is part of dxdiff. | ||
1542 | 4 | # | ||
1543 | 5 | # dxdiff is free software: you can redistribute it and/or modify | ||
1544 | 6 | # it under the terms of the GNU General Public License as published by | ||
1545 | 7 | # the Free Software Foundation, either version 3 of the License, or | ||
1546 | 8 | # (at your option) any later version. | ||
1547 | 9 | # | ||
1548 | 10 | # dxdiff is distributed in the hope that it will be useful, | ||
1549 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1550 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1551 | 13 | # GNU General Public License for more details. | ||
1552 | 14 | # | ||
1553 | 15 | # You should have received a copy of the GNU General Public License | ||
1554 | 16 | # along with Diamond. If not, see <http://www.gnu.org/licenses/>. | ||
1555 | 17 | |||
1556 | 18 | |||
1557 | 19 | class Bimap: | ||
1558 | 20 | """ | ||
1559 | 21 | Bimap is a simple wrapper class over two dicts, | ||
1560 | 22 | it behaves as a bi-directional map. | ||
1561 | 23 | """ | ||
1562 | 24 | |||
1563 | 25 | def __init__(self): | ||
1564 | 26 | self.left = {} | ||
1565 | 27 | self.right = {} | ||
1566 | 28 | |||
1567 | 29 | def __len__(self): | ||
1568 | 30 | return len(self.left) | ||
1569 | 31 | |||
1570 | 32 | def __iter__(self): | ||
1571 | 33 | # we iter over the left dict so that the left item is | ||
1572 | 34 | # on the left side of the tuple returned | ||
1573 | 35 | for item in self.left.iteritems(): | ||
1574 | 36 | yield item | ||
1575 | 37 | |||
1576 | 38 | def __contains__(self, item): | ||
1577 | 39 | # check that the left dict contains left and points to right | ||
1578 | 40 | try: | ||
1579 | 41 | left, right = item | ||
1580 | 42 | return self.left[left] == right | ||
1581 | 43 | except KeyError: | ||
1582 | 44 | return False | ||
1583 | 45 | |||
1584 | 46 | def add(self, item): | ||
1585 | 47 | x, y = item | ||
1586 | 48 | self.left[x] = y | ||
1587 | 49 | self.right[y] = x | ||
1588 | 0 | 50 | ||
1589 | === added file 'dxdiff/dxdiff/diff.py' | |||
1590 | --- dxdiff/dxdiff/diff.py 1970-01-01 00:00:00 +0000 | |||
1591 | +++ dxdiff/dxdiff/diff.py 2011-08-24 16:38:18 +0000 | |||
1592 | @@ -0,0 +1,26 @@ | |||
1593 | 1 | #!/usr/bin/env python | ||
1594 | 2 | |||
1595 | 3 | # This file is part of dxdiff. | ||
1596 | 4 | # | ||
1597 | 5 | # dxdiff is free software: you can redistribute it and/or modify | ||
1598 | 6 | # it under the terms of the GNU General Public License as published by | ||
1599 | 7 | # the Free Software Foundation, either version 3 of the License, or | ||
1600 | 8 | # (at your option) any later version. | ||
1601 | 9 | # | ||
1602 | 10 | # dxdiff is distributed in the hope that it will be useful, | ||
1603 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1604 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1605 | 13 | # GNU General Public License for more details. | ||
1606 | 14 | # | ||
1607 | 15 | # You should have received a copy of the GNU General Public License | ||
1608 | 16 | # along with Diamond. If not, see <http://www.gnu.org/licenses/>. | ||
1609 | 17 | |||
1610 | 18 | import fmes | ||
1611 | 19 | |||
1612 | 20 | def diff(xmlold, xmlnew): | ||
1613 | 21 | """ | ||
1614 | 22 | Compares two xml trees. | ||
1615 | 23 | Returns an editscript to transform old into new. | ||
1616 | 24 | """ | ||
1617 | 25 | |||
1618 | 26 | return fmes.diff(xmlold, xmlnew) | ||
1619 | 0 | 27 | ||
1620 | === added file 'dxdiff/dxdiff/dxdiff' | |||
1621 | --- dxdiff/dxdiff/dxdiff 1970-01-01 00:00:00 +0000 | |||
1622 | +++ dxdiff/dxdiff/dxdiff 2011-08-24 16:38:18 +0000 | |||
1623 | @@ -0,0 +1,87 @@ | |||
1624 | 1 | #!/usr/bin/env python | ||
1625 | 2 | |||
1626 | 3 | # This file is part of dxdiff. | ||
1627 | 4 | # | ||
1628 | 5 | # dxdiff is free software: you can redistribute it and/or modify | ||
1629 | 6 | # it under the terms of the GNU General Public License as published by | ||
1630 | 7 | # the Free Software Foundation, either version 3 of the License, or | ||
1631 | 8 | # (at your option) any later version. | ||
1632 | 9 | # | ||
1633 | 10 | # dxdiff is distributed in the hope that it will be useful, | ||
1634 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1635 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1636 | 13 | # GNU General Public License for more details. | ||
1637 | 14 | # | ||
1638 | 15 | # You should have received a copy of the GNU General Public License | ||
1639 | 16 | # along with Diamond. If not, see <http://www.gnu.org/licenses/>. | ||
1640 | 17 | |||
1641 | 18 | from getopt import getopt | ||
1642 | 19 | import sys | ||
1643 | 20 | import os | ||
1644 | 21 | from lxml import etree | ||
1645 | 22 | from dxdiff.diff import diff | ||
1646 | 23 | |||
1647 | 24 | def __display_help(): | ||
1648 | 25 | """ | ||
1649 | 26 | Prints usage information to standard output. | ||
1650 | 27 | """ | ||
1651 | 28 | |||
1652 | 29 | print "\n".join(["Usage: dxdiff [OPTIONS] ... [FILE1] [FILE2]", | ||
1653 | 30 | "", | ||
1654 | 31 | "An XML aware diff tool. [FILE1] and [FILE2] are the XML files to be compared.", | ||
1655 | 32 | "[FILE1] should be the old file.", | ||
1656 | 33 | "", | ||
1657 | 34 | "Options:", | ||
1658 | 35 | "" | ||
1659 | 36 | "-h Display this message", | ||
1660 | 37 | ""]) | ||
1661 | 38 | |||
1662 | 39 | def __main(): | ||
1663 | 40 | """ | ||
1664 | 41 | Main routine to run dxdiff | ||
1665 | 42 | """ | ||
1666 | 43 | |||
1667 | 44 | try: | ||
1668 | 45 | opts, args = getopt(sys.argv[1:], "hso:") | ||
1669 | 46 | except: | ||
1670 | 47 | __display_help() | ||
1671 | 48 | sys.exit(1) | ||
1672 | 49 | |||
1673 | 50 | if len(args) != 2: | ||
1674 | 51 | __display_help() | ||
1675 | 52 | sys.exit(1) | ||
1676 | 53 | |||
1677 | 54 | if ("h", "") in opts: | ||
1678 | 55 | __display_help() | ||
1679 | 56 | |||
1680 | 57 | output_file = None | ||
1681 | 58 | for opt in opts: | ||
1682 | 59 | if opt[0] == "-o": | ||
1683 | 60 | output_file = opt[1] | ||
1684 | 61 | |||
1685 | 62 | file1 = args[0] | ||
1686 | 63 | file2 = args[1] | ||
1687 | 64 | |||
1688 | 65 | try: | ||
1689 | 66 | os.stat(file1) | ||
1690 | 67 | except OSError: | ||
1691 | 68 | print "Could not find " + file1 + "!" | ||
1692 | 69 | sys.exit(1) | ||
1693 | 70 | |||
1694 | 71 | try: | ||
1695 | 72 | os.stat(file2) | ||
1696 | 73 | except OSError: | ||
1697 | 74 | print "Could not find " + file2 + "!" | ||
1698 | 75 | sys.exit(1) | ||
1699 | 76 | |||
1700 | 77 | xmlold = etree.parse(file1) | ||
1701 | 78 | xmlnew = etree.parse(file2) | ||
1702 | 79 | |||
1703 | 80 | editscript = diff(xmlold, xmlnew) | ||
1704 | 81 | if ("s", "") not in opts: | ||
1705 | 82 | print editscript | ||
1706 | 83 | if output_file is not None: | ||
1707 | 84 | editscript.write(output_file) | ||
1708 | 85 | |||
1709 | 86 | if __name__ == "__main__": | ||
1710 | 87 | __main() | ||
1711 | 0 | 88 | ||
1712 | === added file 'dxdiff/dxdiff/editscript.py' | |||
1713 | --- dxdiff/dxdiff/editscript.py 1970-01-01 00:00:00 +0000 | |||
1714 | +++ dxdiff/dxdiff/editscript.py 2011-08-24 16:38:18 +0000 | |||
1715 | @@ -0,0 +1,79 @@ | |||
1716 | 1 | #!/usr/bin/env python | ||
1717 | 2 | |||
1718 | 3 | # This file is part of dxdiff. | ||
1719 | 4 | # | ||
1720 | 5 | # dxdiff is free software: you can redistribute it and/or modify | ||
1721 | 6 | # it under the terms of the GNU General Public License as published by | ||
1722 | 7 | # the Free Software Foundation, either version 3 of the License, or | ||
1723 | 8 | # (at your option) any later version. | ||
1724 | 9 | # | ||
1725 | 10 | # dxdiff is distributed in the hope that it will be useful, | ||
1726 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1727 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1728 | 13 | # GNU General Public License for more details. | ||
1729 | 14 | # | ||
1730 | 15 | # You should have received a copy of the GNU General Public License | ||
1731 | 16 | # along with Diamond. If not, see <http://www.gnu.org/licenses/>. | ||
1732 | 17 | |||
1733 | 18 | from lxml import etree | ||
1734 | 19 | |||
1735 | 20 | class EditScript: | ||
1736 | 21 | |||
1737 | 22 | def __init__(self): | ||
1738 | 23 | self.script = [] | ||
1739 | 24 | |||
1740 | 25 | def __str__(self): | ||
1741 | 26 | return etree.tostring(self.to_xml(), pretty_print = True) | ||
1742 | 27 | |||
1743 | 28 | def __len__(self): | ||
1744 | 29 | return len(self.script) | ||
1745 | 30 | |||
1746 | 31 | def __getitem__(self, key): | ||
1747 | 32 | return self.script[key] | ||
1748 | 33 | |||
1749 | 34 | def __iter__(self): | ||
1750 | 35 | return self.script.__iter__() | ||
1751 | 36 | |||
1752 | 37 | def update(self, path, value, userdata = None): | ||
1753 | 38 | self.script.append({ "type": "update", | ||
1754 | 39 | "location": path, | ||
1755 | 40 | "value": value, | ||
1756 | 41 | "userdata": userdata }) | ||
1757 | 42 | |||
1758 | 43 | def insert(self, path, index, tag, value = None, userdata = None): | ||
1759 | 44 | self.script.append({ "type": "insert", | ||
1760 | 45 | "location": path, | ||
1761 | 46 | "index": index, | ||
1762 | 47 | "value": tag + (" " + value if value is not None else ""), | ||
1763 | 48 | "userdata": userdata}) | ||
1764 | 49 | |||
1765 | 50 | def delete(self, path, userdata = None): | ||
1766 | 51 | self.script.append({ "type": "delete", | ||
1767 | 52 | "location": path, | ||
1768 | 53 | "userdata": userdata}) | ||
1769 | 54 | |||
1770 | 55 | def move(self, path, destination, index, userdata = None): | ||
1771 | 56 | self.script.append({ "type": "move", | ||
1772 | 57 | "location": path, | ||
1773 | 58 | "index": index, | ||
1774 | 59 | "value": destination, | ||
1775 | 60 | "userdata": userdata }) | ||
1776 | 61 | |||
1777 | 62 | def to_xml(self): | ||
1778 | 63 | tree = etree.Element("xmldiff") | ||
1779 | 64 | |||
1780 | 65 | for edit in self.script: | ||
1781 | 66 | node = etree.Element(edit["type"], location = edit["location"]) | ||
1782 | 67 | if "index" in edit: | ||
1783 | 68 | node.attrib["index"] = edit["index"] | ||
1784 | 69 | if edit["userdata"] is not None: | ||
1785 | 70 | node.attrib["userdata"] = edit["userdata"] | ||
1786 | 71 | |||
1787 | 72 | if "value" in edit: | ||
1788 | 73 | node.text = edit["value"] | ||
1789 | 74 | tree.append(node) | ||
1790 | 75 | |||
1791 | 76 | return etree.ElementTree(tree) | ||
1792 | 77 | |||
1793 | 78 | def write(self, path): | ||
1794 | 79 | self.to_xml().write(path, pretty_print = True, xml_declaration = True, encoding = "utf-8") | ||
1795 | 0 | 80 | ||
1796 | === added file 'dxdiff/dxdiff/fmes.py' | |||
1797 | --- dxdiff/dxdiff/fmes.py 1970-01-01 00:00:00 +0000 | |||
1798 | +++ dxdiff/dxdiff/fmes.py 2011-08-24 16:38:18 +0000 | |||
1799 | @@ -0,0 +1,466 @@ | |||
1800 | 1 | #!/usr/bin/env python | ||
1801 | 2 | |||
1802 | 3 | # This file is part of dxdiff. | ||
1803 | 4 | # | ||
1804 | 5 | # dxdiff is free software: you can redistribute it and/or modify | ||
1805 | 6 | # it under the terms of the GNU General Public License as published by | ||
1806 | 7 | # the Free Software Foundation, either version 3 of the License, or | ||
1807 | 8 | # (at your option) any later version. | ||
1808 | 9 | # | ||
1809 | 10 | # dxdiff is distributed in the hope that it will be useful, | ||
1810 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1811 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1812 | 13 | # GNU General Public License for more details. | ||
1813 | 14 | # | ||
1814 | 15 | # You should have received a copy of the GNU General Public License | ||
1815 | 16 | # along with Diamond. If not, see <http://www.gnu.org/licenses/>. | ||
1816 | 17 | """ | ||
1817 | 18 | Diff xml trees using a modification of FMES [http://infolab.stanford.edu/pub/papers/tdiff3-8.ps] | ||
1818 | 19 | """ | ||
1819 | 20 | |||
1820 | 21 | from lxml import etree | ||
1821 | 22 | from collections import deque | ||
1822 | 23 | from bimap import Bimap | ||
1823 | 24 | from editscript import EditScript | ||
1824 | 25 | |||
1825 | 26 | import lcs | ||
1826 | 27 | import utils | ||
1827 | 28 | |||
1828 | 29 | class Dom: | ||
1829 | 30 | def __init__(self, tag, value, parent, attribute = False): | ||
1830 | 31 | self.tag = tag | ||
1831 | 32 | self.value = value | ||
1832 | 33 | self.parent = parent | ||
1833 | 34 | self.children = [] | ||
1834 | 35 | |||
1835 | 36 | if value is None: | ||
1836 | 37 | self.typetag = "/Element" | ||
1837 | 38 | elif attribute: | ||
1838 | 39 | self.typetag = "/Attribute" | ||
1839 | 40 | else: | ||
1840 | 41 | self.typetag = "/Text" | ||
1841 | 42 | |||
1842 | 43 | if parent: | ||
1843 | 44 | self.depth = parent.depth + 1 | ||
1844 | 45 | else: | ||
1845 | 46 | self.depth = 0 | ||
1846 | 47 | |||
1847 | 48 | self.inorder = False | ||
1848 | 49 | |||
1849 | 50 | def elements(self): | ||
1850 | 51 | return [child for child in self.children if child.is_element()] | ||
1851 | 52 | |||
1852 | 53 | def attributes(self): | ||
1853 | 54 | return [child for child in self.children if child.is_attribute()] | ||
1854 | 55 | |||
1855 | 56 | def text(self): | ||
1856 | 57 | return [child for child in self.children if child.is_text()] | ||
1857 | 58 | |||
1858 | 59 | def is_element(self): | ||
1859 | 60 | return self.typetag == "/Element" | ||
1860 | 61 | |||
1861 | 62 | def is_text(self): | ||
1862 | 63 | return self.typetag == "/Text" | ||
1863 | 64 | |||
1864 | 65 | def is_attribute(self): | ||
1865 | 66 | return self.typetag == "/Attribute" | ||
1866 | 67 | |||
1867 | 68 | def __repr__(self): | ||
1868 | 69 | return "<" + self.label + ">" + (self.value or "") | ||
1869 | 70 | |||
1870 | 71 | def __str__(self, indent = ""): | ||
1871 | 72 | title = indent + "<" + self.path() + ">" + (self.value or "") + "\n" + indent | ||
1872 | 73 | children = ("\n" + indent).join(child.__str__(indent + " ") for child in self.children) | ||
1873 | 74 | return title + children | ||
1874 | 75 | |||
1875 | 76 | def path(self): | ||
1876 | 77 | """ | ||
1877 | 78 | Finds the path of this element. | ||
1878 | 79 | """ | ||
1879 | 80 | if self.is_text(): | ||
1880 | 81 | return self.parent.path() + "/text()" | ||
1881 | 82 | |||
1882 | 83 | if self.is_attribute(): | ||
1883 | 84 | return self.parent.path() + "/@" + self.tag | ||
1884 | 85 | |||
1885 | 86 | if self.parent: | ||
1886 | 87 | siblings = [sibling for sibling in self.parent.elements() if sibling.tag == self.tag] | ||
1887 | 88 | if len(siblings) != 1: | ||
1888 | 89 | index = "[" + str(siblings.index(self) + 1) + "]" | ||
1889 | 90 | else: | ||
1890 | 91 | index = "" | ||
1891 | 92 | return self.parent.path() + "/" + self.tag + index | ||
1892 | 93 | else: | ||
1893 | 94 | return "/" + self.tag | ||
1894 | 95 | |||
1895 | 96 | def find(self, path): | ||
1896 | 97 | |||
1897 | 98 | if self.is_text(): | ||
1898 | 99 | if path == "/text()": | ||
1899 | 100 | return self | ||
1900 | 101 | else: return None | ||
1901 | 102 | |||
1902 | 103 | if self.is_attribute(): | ||
1903 | 104 | if path == "/@" + self.tag: | ||
1904 | 105 | return self | ||
1905 | 106 | else: return None | ||
1906 | 107 | |||
1907 | 108 | index = path.find("/", 1) | ||
1908 | 109 | if index == -1: | ||
1909 | 110 | index = len(path) | ||
1910 | 111 | |||
1911 | 112 | root = path[:index] | ||
1912 | 113 | path = path[index:] | ||
1913 | 114 | |||
1914 | 115 | if self.parent: | ||
1915 | 116 | siblings = [sibling for sibling in self.parent.elements() if sibling.tag == self.tag] | ||
1916 | 117 | if len(siblings) != 1: | ||
1917 | 118 | index = "[" + str(siblings.index(self) + 1) + "]" | ||
1918 | 119 | else: | ||
1919 | 120 | index = "" | ||
1920 | 121 | |||
1921 | 122 | if root != "/" + self.tag + index: | ||
1922 | 123 | return None | ||
1923 | 124 | else: | ||
1924 | 125 | if root != "/" + self.tag: | ||
1925 | 126 | return None | ||
1926 | 127 | |||
1927 | 128 | if path: | ||
1928 | 129 | for child in self.children: | ||
1929 | 130 | result = child.find(path) | ||
1930 | 131 | if result: | ||
1931 | 132 | return result | ||
1932 | 133 | else: | ||
1933 | 134 | return self | ||
1934 | 135 | |||
1935 | 136 | def _real_index(self, parent, index): | ||
1936 | 137 | if index == 0: | ||
1937 | 138 | return 0 | ||
1938 | 139 | |||
1939 | 140 | elements = parent.elements() | ||
1940 | 141 | if len(elements) < index: | ||
1941 | 142 | return len(parent.children) | ||
1942 | 143 | return parent.children.index(elements[index - 1]) | ||
1943 | 144 | |||
1944 | 145 | def insert(self, tag, tagtype, value, path, index): | ||
1945 | 146 | parent = self.find(path) | ||
1946 | 147 | |||
1947 | 148 | node = Dom(tag, value, parent, tagtype == "/Attribute") | ||
1948 | 149 | parent.children.insert(self._real_index(parent, index), node) | ||
1949 | 150 | node.label = _strip_indexers(node.path()) + node.typetag | ||
1950 | 151 | return node | ||
1951 | 152 | |||
1952 | 153 | def update(self, path, value): | ||
1953 | 154 | node = self.find(path) | ||
1954 | 155 | |||
1955 | 156 | node.value = value | ||
1956 | 157 | return node | ||
1957 | 158 | |||
1958 | 159 | def move(self, from_path, to_path, index): | ||
1959 | 160 | node = self.find(from_path) | ||
1960 | 161 | node.parent.children.remove(node) | ||
1961 | 162 | |||
1962 | 163 | parent = self.find(to_path) | ||
1963 | 164 | parent.children.insert(self._real_index(parent, index), node) | ||
1964 | 165 | node.parent = parent | ||
1965 | 166 | |||
1966 | 167 | def delete(self, path): | ||
1967 | 168 | node = self.find(path) | ||
1968 | 169 | node.parent.children.remove(node) | ||
1969 | 170 | node.parent = None | ||
1970 | 171 | |||
1971 | 172 | def _get_text(tree): | ||
1972 | 173 | """ | ||
1973 | 174 | Returns the text and child tails. | ||
1974 | 175 | """ | ||
1975 | 176 | return "".join([tree.text or ""] + [child.tail or "" for child in tree]).strip() | ||
1976 | 177 | |||
1977 | 178 | def _strip_indexers(path): | ||
1978 | 179 | """ | ||
1979 | 180 | Strips out indexers from an path. | ||
1980 | 181 | """ | ||
1981 | 182 | while True: | ||
1982 | 183 | lindex = path.find("[") | ||
1983 | 184 | if lindex == -1: | ||
1984 | 185 | break | ||
1985 | 186 | rindex = path.find("]", lindex) | ||
1986 | 187 | path = path[:lindex] + path[rindex + 1:] | ||
1987 | 188 | return path | ||
1988 | 189 | |||
1989 | 190 | def dom(root, tree = None, parent = None): | ||
1990 | 191 | |||
1991 | 192 | if tree is None: | ||
1992 | 193 | tree = root.getroot() | ||
1993 | 194 | |||
1994 | 195 | xpath = root.getpath(tree) | ||
1995 | 196 | path = _strip_indexers(xpath) | ||
1996 | 197 | |||
1997 | 198 | node = Dom(tree.tag, None, parent) | ||
1998 | 199 | node.label = path + node.typetag | ||
1999 | 200 | node.xpath = xpath | ||
2000 | 201 | |||
2001 | 202 | text = _get_text(tree) | ||
2002 | 203 | if text: | ||
2003 | 204 | text = Dom(tree.tag, text, node) | ||
2004 | 205 | text.label = path + text.typetag | ||
2005 | 206 | text.xpath = xpath + "/text()" | ||
2006 | 207 | node.children.append(text) | ||
2007 | 208 | |||
2008 | 209 | for key, value in tree.items(): | ||
2009 | 210 | attr = Dom(key, value, node, True) | ||
2010 | 211 | attr.label = path + "/@" + key + attr.typetag | ||
2011 | 212 | attr.xpath = path + "/@" + key | ||
2012 | 213 | node.children.append(attr) | ||
2013 | 214 | |||
2014 | 215 | for child in tree: | ||
2015 | 216 | node.children.append(dom(root, child, node)) | ||
2016 | 217 | |||
2017 | 218 | return node | ||
2018 | 219 | |||
2019 | 220 | def get_leaf_nodes(tree): | ||
2020 | 221 | """ | ||
2021 | 222 | Gets all the leaf nodes of an xml tree. | ||
2022 | 223 | """ | ||
2023 | 224 | if tree.children: | ||
2024 | 225 | return utils.flatten([get_leaf_nodes(child) for child in tree.children]) | ||
2025 | 226 | else: | ||
2026 | 227 | return [tree] | ||
2027 | 228 | |||
2028 | 229 | def get_parent_nodes(tree): | ||
2029 | 230 | """ | ||
2030 | 231 | Returns all the non leaf nodes of an xml tree. | ||
2031 | 232 | """ | ||
2032 | 233 | |||
2033 | 234 | if tree.children: | ||
2034 | 235 | return utils.flatten([get_parent_nodes(child) for child in tree.children]) + [tree] | ||
2035 | 236 | else: | ||
2036 | 237 | return [] | ||
2037 | 238 | |||
2038 | 239 | def get_depth(tree): | ||
2039 | 240 | """ | ||
2040 | 241 | Returns the maximum depth of a tree. | ||
2041 | 242 | """ | ||
2042 | 243 | depth = tree.depth | ||
2043 | 244 | for child in tree.children: | ||
2044 | 245 | depth = max(depth, get_depth(child)) | ||
2045 | 246 | return depth | ||
2046 | 247 | |||
2047 | 248 | def get_depth_nodes(tree, depth): | ||
2048 | 249 | """ | ||
2049 | 250 | Gets all the nodes of a certain depth of an xml tree. | ||
2050 | 251 | """ | ||
2051 | 252 | if tree.depth == depth: | ||
2052 | 253 | return [tree] | ||
2053 | 254 | else: | ||
2054 | 255 | if tree.children: | ||
2055 | 256 | return utils.flatten([get_depth_nodes(child, depth) for child in tree.children]) | ||
2056 | 257 | else: | ||
2057 | 258 | return [] | ||
2058 | 259 | |||
2059 | 260 | def get_chain(nodes, label): | ||
2060 | 261 | return [node for node in nodes if node.label == label] | ||
2061 | 262 | |||
2062 | 263 | def compare_value(value1, value2): | ||
2063 | 264 | if value1 is None and value2 is None: | ||
2064 | 265 | return 0.0 | ||
2065 | 266 | if value1 is None or value2 is None: | ||
2066 | 267 | return 1.0 | ||
2067 | 268 | return 1.0 - (float(len(lcs.lcs(lcs.path(value1, value2)))) / max(len(value1), len(value2))) | ||
2068 | 269 | |||
2069 | 270 | def leaf_equal(f, M, l1, l2): | ||
2070 | 271 | return l1.label == l2.label and compare_value(l1.value, l2.value) <= f | ||
2071 | 272 | |||
2072 | 273 | def common(children1, children2, M): | ||
2073 | 274 | return [(x, y) for (x, y) in M if x in children1 and y in children2] | ||
2074 | 275 | |||
2075 | 276 | def compare_children(children1, children2, M): | ||
2076 | 277 | return (float(len(common(children1, children2, M))) / max(len(children1), len(children2))) | ||
2077 | 278 | |||
2078 | 279 | def node_equal(t, M, n1, n2): | ||
2079 | 280 | return n1.label == n2.label and compare_children(n1.children, n2.children, M) > t | ||
2080 | 281 | |||
2081 | 282 | def depth_equal(f, t, M, n1, n2): | ||
2082 | 283 | if n1.children or n2.children: | ||
2083 | 284 | return node_equal(t, M, n1, n2) | ||
2084 | 285 | else: | ||
2085 | 286 | return leaf_equal(f, M, n1, n2) | ||
2086 | 287 | |||
2087 | 288 | def _match(nodes1, nodes2, M, equal): | ||
2088 | 289 | nodes = nodes1 + nodes2 | ||
2089 | 290 | for label in utils.nub([node.label for node in nodes]): | ||
2090 | 291 | |||
2091 | 292 | s1 = get_chain(nodes1, label) | ||
2092 | 293 | s2 = get_chain(nodes2, label) | ||
2093 | 294 | |||
2094 | 295 | path = lcs.lcs(lcs.path(s1, s2, equal)) | ||
2095 | 296 | |||
2096 | 297 | for x, y in path: | ||
2097 | 298 | M.add((s1[x], s2[y])) | ||
2098 | 299 | for x, y in reversed(path): | ||
2099 | 300 | s1.pop(x) | ||
2100 | 301 | s2.pop(y) | ||
2101 | 302 | |||
2102 | 303 | for x in range(len(s1)): | ||
2103 | 304 | for y in range(len(s2)): | ||
2104 | 305 | if equal(s1[x], s2[y]): | ||
2105 | 306 | M.add((s1[x], s2[y])) | ||
2106 | 307 | s2.pop(y) | ||
2107 | 308 | break | ||
2108 | 309 | |||
2109 | 310 | def fastmatch(t1, t2): | ||
2110 | 311 | """ | ||
2111 | 312 | Calculates a match between t1 and t2. | ||
2112 | 313 | See figure 10 in reference. | ||
2113 | 314 | """ | ||
2114 | 315 | M = Bimap() | ||
2115 | 316 | |||
2116 | 317 | depth = max(get_depth(t1), get_depth(t2)) | ||
2117 | 318 | |||
2118 | 319 | while 0 <= depth: | ||
2119 | 320 | nodes1 = get_depth_nodes(t1, depth) | ||
2120 | 321 | nodes2 = get_depth_nodes(t2, depth) | ||
2121 | 322 | |||
2122 | 323 | equal = utils.partial(depth_equal, 0.6, 0.5, M) | ||
2123 | 324 | |||
2124 | 325 | _match(nodes1, nodes2, M, equal) | ||
2125 | 326 | |||
2126 | 327 | depth -= 1 | ||
2127 | 328 | |||
2128 | 329 | return M | ||
2129 | 330 | |||
2130 | 331 | def breadth_iter(tree): | ||
2131 | 332 | Q = deque() | ||
2132 | 333 | Q.append(tree) | ||
2133 | 334 | while Q: | ||
2134 | 335 | t = Q.popleft() | ||
2135 | 336 | if t is not tree: | ||
2136 | 337 | yield t | ||
2137 | 338 | if t.parent is not None or t is tree: #check we haven't deleted it | ||
2138 | 339 | for child in t.children: | ||
2139 | 340 | Q.append(child) | ||
2140 | 341 | |||
2141 | 342 | def postorder_iter(tree): | ||
2142 | 343 | S = [] | ||
2143 | 344 | O = [] | ||
2144 | 345 | S.append(tree) | ||
2145 | 346 | while S: | ||
2146 | 347 | t = S.pop() | ||
2147 | 348 | O.append(t) | ||
2148 | 349 | for child in t.children: | ||
2149 | 350 | S.append(child) | ||
2150 | 351 | while O: | ||
2151 | 352 | t = O.pop() | ||
2152 | 353 | if t is not tree: | ||
2153 | 354 | yield t | ||
2154 | 355 | |||
2155 | 356 | def editscript(t1, t2): | ||
2156 | 357 | """ | ||
2157 | 358 | Finds an editscript between t1 and t2. | ||
2158 | 359 | See figure 8 in reference. | ||
2159 | 360 | """ | ||
2160 | 361 | |||
2161 | 362 | E = EditScript() | ||
2162 | 363 | M = fastmatch(t1, t2) | ||
2163 | 364 | |||
2164 | 365 | M.add((t1, t2)) | ||
2165 | 366 | alignchildren(t1, t2, M, E, t1, t2) | ||
2166 | 367 | |||
2167 | 368 | for x in breadth_iter(t2): | ||
2168 | 369 | y = x.parent | ||
2169 | 370 | z = M.right[y] | ||
2170 | 371 | |||
2171 | 372 | if x not in M.right: | ||
2172 | 373 | if x.typetag == "/Text": #Can't insert Text, do an update | ||
2173 | 374 | E.update(z.path(), x.value, x.xpath if hasattr(x, "xpath") else None) | ||
2174 | 375 | w = t1.insert(x.tag, x.typetag, x.value, z.path(), 0) | ||
2175 | 376 | M.add((w, x)) | ||
2176 | 377 | else: | ||
2177 | 378 | x.inorder = True | ||
2178 | 379 | k = findpos(M, x) | ||
2179 | 380 | E.insert(z.path(), str(k), x.tag, x.value, x.xpath if hasattr(x, "xpath") else None) | ||
2180 | 381 | w = t1.insert(x.tag, x.typetag, x.value, z.path(), k) | ||
2181 | 382 | M.add((w, x)) | ||
2182 | 383 | else: # y is not None: | ||
2183 | 384 | w = M.right[x] | ||
2184 | 385 | v = w.parent | ||
2185 | 386 | if w.value != x.value: | ||
2186 | 387 | E.update(w.path(), x.value, w.xpath if hasattr(w, "xpath") else None) | ||
2187 | 388 | t1.update(w.path(), x.value) | ||
2188 | 389 | if (v, y) not in M: | ||
2189 | 390 | x.inorder = True | ||
2190 | 391 | k = findpos(M, x) | ||
2191 | 392 | E.move(w.path(), z.path(), str(k), w.xpath if hasattr(w, "xpath") else None) | ||
2192 | 393 | t1.move(w.path(), z.path(), k) | ||
2193 | 394 | |||
2194 | 395 | alignchildren(t1, t2, M, E, w, x) | ||
2195 | 396 | |||
2196 | 397 | for w in breadth_iter(t1): | ||
2197 | 398 | if w not in M.left: | ||
2198 | 399 | if w.typetag == "/Text": #Can't delete Text, do an update | ||
2199 | 400 | E.update(w.path(), "", w.xpath if hasattr(w, "xpath") else None) | ||
2200 | 401 | t1.update(w.path(), "") | ||
2201 | 402 | else: | ||
2202 | 403 | E.delete(w.path(), w.xpath if hasattr(w, "xpath") else None) | ||
2203 | 404 | t1.delete(w.path()) | ||
2204 | 405 | |||
2205 | 406 | return E | ||
2206 | 407 | |||
2207 | 408 | def alignchildren(t1, t2, M, E, w, x): | ||
2208 | 409 | """ | ||
2209 | 410 | See figure 9 in reference. | ||
2210 | 411 | """ | ||
2211 | 412 | |||
2212 | 413 | for c in w.elements(): | ||
2213 | 414 | c.inorder = False | ||
2214 | 415 | for c in x.elements(): | ||
2215 | 416 | c.inorder = False | ||
2216 | 417 | |||
2217 | 418 | s1 = [child for child in w.elements() if child in M.left and M.left[child].parent == x] | ||
2218 | 419 | s2 = [child for child in x.elements() if child in M.right and M.right[child].parent == w] | ||
2219 | 420 | |||
2220 | 421 | def equal(a, b): | ||
2221 | 422 | return (a, b) in M | ||
2222 | 423 | |||
2223 | 424 | S = [(s1[x], s2[y]) for x, y in lcs.lcs(lcs.path(s1, s2, equal))] | ||
2224 | 425 | for (a, b) in S: | ||
2225 | 426 | a.inorder = b.inorder = True | ||
2226 | 427 | |||
2227 | 428 | for a in s1: | ||
2228 | 429 | for b in s2: | ||
2229 | 430 | if (a, b) in M and (a, b) not in S: | ||
2230 | 431 | k = findpos(M, b) | ||
2231 | 432 | E.move(a.path(), w.path(), k, a.xpath if hasattr(a, "xpath") else None) | ||
2232 | 433 | t1.move(a.path(), w.path(), str(k)) | ||
2233 | 434 | a.inorder = b.inorder = True | ||
2234 | 435 | |||
2235 | 436 | def findpos(M, x): | ||
2236 | 437 | """ | ||
2237 | 438 | See figure 9 in reference. | ||
2238 | 439 | """ | ||
2239 | 440 | if x.is_text() or x.is_attribute(): | ||
2240 | 441 | return 0 | ||
2241 | 442 | |||
2242 | 443 | y = x.parent | ||
2243 | 444 | children = y.elements() | ||
2244 | 445 | |||
2245 | 446 | #find the rightmost inorder node left of x (v) | ||
2246 | 447 | index = children.index(x) | ||
2247 | 448 | v = None | ||
2248 | 449 | for i in range(index): | ||
2249 | 450 | c = children[i] | ||
2250 | 451 | if c.inorder: | ||
2251 | 452 | v = c | ||
2252 | 453 | |||
2253 | 454 | if v is None: | ||
2254 | 455 | return 1 | ||
2255 | 456 | |||
2256 | 457 | u = M.right[v] | ||
2257 | 458 | children = u.parent.elements() | ||
2258 | 459 | index = children.index(u) + 1 | ||
2259 | 460 | return index + 1 | ||
2260 | 461 | |||
2261 | 462 | def diff(tree1, tree2): | ||
2262 | 463 | t1 = dom(tree1) | ||
2263 | 464 | t2 = dom(tree2) | ||
2264 | 465 | E = editscript(t1, t2) | ||
2265 | 466 | return E | ||
2266 | 0 | 467 | ||
2267 | === added file 'dxdiff/dxdiff/lcs.py' | |||
2268 | --- dxdiff/dxdiff/lcs.py 1970-01-01 00:00:00 +0000 | |||
2269 | +++ dxdiff/dxdiff/lcs.py 2011-08-24 16:38:18 +0000 | |||
2270 | @@ -0,0 +1,284 @@ | |||
2271 | 1 | #!/usr/bin/env python | ||
2272 | 2 | |||
2273 | 3 | # This file is part of dxdiff. | ||
2274 | 4 | # | ||
2275 | 5 | # dxdiff is free software: you can redistribute it and/or modify | ||
2276 | 6 | # it under the terms of the GNU General Public License as published by | ||
2277 | 7 | # the Free Software Foundation, either version 3 of the License, or | ||
2278 | 8 | # (at your option) any later version. | ||
2279 | 9 | # | ||
2280 | 10 | # dxdiff is distributed in the hope that it will be useful, | ||
2281 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2282 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2283 | 13 | # GNU General Public License for more details. | ||
2284 | 14 | # | ||
2285 | 15 | # You should have received a copy of the GNU General Public License | ||
2286 | 16 | # along with Diamond. If not, see <http://www.gnu.org/licenses/>. | ||
2287 | 17 | """ | ||
2288 | 18 | Find the LCS (Longest Common Subsequence). Uses [http://www.xmailserver.org/diff2.pdf] | ||
2289 | 19 | """ | ||
2290 | 20 | |||
2291 | 21 | from utils import irange | ||
2292 | 22 | |||
2293 | 23 | def __path(V, D, k): | ||
2294 | 24 | if D == 0: | ||
2295 | 25 | return [(xy, xy) for xy in irange(V[0][0])] | ||
2296 | 26 | |||
2297 | 27 | tx = V[D][k] | ||
2298 | 28 | |||
2299 | 29 | if k == -D or (k != D and V[D][k - 1] < V[D][k + 1]): | ||
2300 | 30 | x = V[D][k + 1] | ||
2301 | 31 | y = x - (k + 1) | ||
2302 | 32 | k = k + 1 | ||
2303 | 33 | y = y + 1 | ||
2304 | 34 | else: | ||
2305 | 35 | x = V[D][k - 1] | ||
2306 | 36 | y = x - (k - 1) | ||
2307 | 37 | k = k - 1 | ||
2308 | 38 | x = x + 1 | ||
2309 | 39 | |||
2310 | 40 | return __path(V, D - 1, k) + [(x + d, y + d) for d in irange(tx - x)] | ||
2311 | 41 | |||
2312 | 42 | def __eq(a, b): return a == b | ||
2313 | 43 | |||
2314 | 44 | def path(a, b, eq = __eq): | ||
2315 | 45 | """ | ||
2316 | 46 | Finds the path through the match grid of sequence a and b, | ||
2317 | 47 | using the function eq to determine equality. | ||
2318 | 48 | Returns path | ||
2319 | 49 | """ | ||
2320 | 50 | |||
2321 | 51 | m = len(a) | ||
2322 | 52 | n = len(b) | ||
2323 | 53 | mn = m + n | ||
2324 | 54 | |||
2325 | 55 | if mn == 0: # two empty sequences | ||
2326 | 56 | return [(0, 0)] | ||
2327 | 57 | |||
2328 | 58 | Vd = [] | ||
2329 | 59 | V = {1: 0} | ||
2330 | 60 | |||
2331 | 61 | for D in irange(mn): | ||
2332 | 62 | for k in irange(-D, D, 2): | ||
2333 | 63 | if k == -D or (k != D and V[k - 1] < V[k + 1]): | ||
2334 | 64 | x = V[k + 1] | ||
2335 | 65 | else: | ||
2336 | 66 | x = V[k - 1] + 1 | ||
2337 | 67 | y = x - k | ||
2338 | 68 | |||
2339 | 69 | while x < m and y < n and eq(a[x], b[y]): | ||
2340 | 70 | x += 1 | ||
2341 | 71 | y += 1 | ||
2342 | 72 | |||
2343 | 73 | V[k] = x | ||
2344 | 74 | |||
2345 | 75 | if x >= m and y >= n: | ||
2346 | 76 | Vd.append(V.copy()) | ||
2347 | 77 | return __path(Vd, D, k) | ||
2348 | 78 | |||
2349 | 79 | Vd.append(V.copy()) | ||
2350 | 80 | |||
2351 | 81 | raise Exception("lcs should not reach here") | ||
2352 | 82 | |||
2353 | 83 | def lcs(path): | ||
2354 | 84 | """ | ||
2355 | 85 | Given an edit script path returns the longest common subseqence. | ||
2356 | 86 | """ | ||
2357 | 87 | |||
2358 | 88 | result = [] | ||
2359 | 89 | |||
2360 | 90 | for i in range(1, len(path)): | ||
2361 | 91 | x, y = path[i] | ||
2362 | 92 | px, py = path[i - 1] | ||
2363 | 93 | dx, dy = x - px, y - py | ||
2364 | 94 | if dx == 1 and dy == 1: | ||
2365 | 95 | result.append((px, py)) | ||
2366 | 96 | |||
2367 | 97 | return result | ||
2368 | 98 | |||
2369 | 99 | def ses(path, b): | ||
2370 | 100 | """ | ||
2371 | 101 | Returns an edit script for a given match grid path. | ||
2372 | 102 | The edit script transforms sequence A of the match grid | ||
2373 | 103 | into sequence B via deletions ("D", index) and inserations | ||
2374 | 104 | ("I", A index, B value). | ||
2375 | 105 | """ | ||
2376 | 106 | |||
2377 | 107 | patch = [] | ||
2378 | 108 | for i in range(len(path) - 1): | ||
2379 | 109 | x, y = path[i] | ||
2380 | 110 | nx, ny = path[i + 1] | ||
2381 | 111 | dx, dy = nx - x, ny - y | ||
2382 | 112 | if dx == 1 and dy == 1: | ||
2383 | 113 | pass #match | ||
2384 | 114 | elif dx == 1: | ||
2385 | 115 | patch.append(("D", x)) | ||
2386 | 116 | else: #dy == 1: | ||
2387 | 117 | patch.append(("I", x, b[y])) | ||
2388 | 118 | |||
2389 | 119 | return patch | ||
2390 | 120 | |||
2391 | 121 | def patch(patch, a): | ||
2392 | 122 | """ | ||
2393 | 123 | Given a sequence and a patch from the ses function transforms a into b | ||
2394 | 124 | """ | ||
2395 | 125 | |||
2396 | 126 | seq = type(a) | ||
2397 | 127 | result = seq() | ||
2398 | 128 | i = 0 | ||
2399 | 129 | |||
2400 | 130 | for op in patch: | ||
2401 | 131 | while i < op[1]: | ||
2402 | 132 | result += seq(a[i]) | ||
2403 | 133 | i += 1 | ||
2404 | 134 | |||
2405 | 135 | if op[0] == "D": | ||
2406 | 136 | i += 1 | ||
2407 | 137 | else: | ||
2408 | 138 | result += seq(op[2]) | ||
2409 | 139 | |||
2410 | 140 | while i < len(a): | ||
2411 | 141 | result += seq(a[i]) | ||
2412 | 142 | i += 1 | ||
2413 | 143 | |||
2414 | 144 | return result | ||
2415 | 145 | |||
2416 | 146 | ################## | ||
2417 | 147 | ### Unit Tests ### | ||
2418 | 148 | ################## | ||
2419 | 149 | |||
2420 | 150 | import unittest | ||
2421 | 151 | |||
2422 | 152 | class __Test_lcs(unittest.TestCase): | ||
2423 | 153 | def test_zero(self): | ||
2424 | 154 | self.assertEqual(path("", ""), [(0, 0)]) | ||
2425 | 155 | self.assertEqual(path("", "a"), [(0, 0), (0, 1)]) | ||
2426 | 156 | self.assertEqual(path("a", ""), [(0, 0), (1, 0)]) | ||
2427 | 157 | |||
2428 | 158 | def test_single(self): | ||
2429 | 159 | self.assertEqual(path("a", "a"), [(0, 0), (1, 1)]) | ||
2430 | 160 | self.assertEqual(path("a", "b"), [(0, 0), (1, 0), (1, 1)]) | ||
2431 | 161 | |||
2432 | 162 | def test_short(self): | ||
2433 | 163 | self.assertEqual(path("ab", "ab"), [(0, 0), (1, 1), (2, 2)]) | ||
2434 | 164 | self.assertEqual(path("ab", "ac"), [(0, 0), (1, 1), (2, 1), (2, 2)]) | ||
2435 | 165 | self.assertEqual(path("abcabba", "cbabac"), [(0, 0), (1, 0), (2, 0), (3, 1), (3, 2), (4, 3), (5, 4), (6, 4), (7, 5), (7, 6)]) | ||
2436 | 166 | self.assertEqual(path("hello", "help me"), [(0, 0), (1, 1), (2, 2), (3, 3), (4, 3), (5, 3), (5, 4), (5, 5), (5, 6), (5, 7)]) | ||
2437 | 167 | |||
2438 | 168 | def test_long(self): | ||
2439 | 169 | self.assertEqual(path("hello", "night night"), | ||
2440 | 170 | [(0, 0), (0, 1), (0, 2), (0, 3), (1, 4), (2, 4), | ||
2441 | 171 | (3, 4), (4, 4), (5, 4), (5, 5), (5, 6), (5, 7), | ||
2442 | 172 | (5, 8), (5, 9), (5, 10), (5, 11)]) | ||
2443 | 173 | |||
2444 | 174 | self.assertEqual(path([ | ||
2445 | 175 | "This part of the", | ||
2446 | 176 | "document has stayed the", | ||
2447 | 177 | "same from version to", | ||
2448 | 178 | "version. It shouldn't", | ||
2449 | 179 | "be shown if it doesn't", | ||
2450 | 180 | "change. Otherwise, that", | ||
2451 | 181 | "would not be helping to", | ||
2452 | 182 | "compress the size of the", | ||
2453 | 183 | "changes.", | ||
2454 | 184 | "", | ||
2455 | 185 | "This paragraph contains", | ||
2456 | 186 | "text that is outdated.", | ||
2457 | 187 | "It will be deleted in the", | ||
2458 | 188 | "near future.", | ||
2459 | 189 | "", | ||
2460 | 190 | "It is important to spell", | ||
2461 | 191 | "check this dokument. On", | ||
2462 | 192 | "the other hand, a", | ||
2463 | 193 | "misspelled word isn't", | ||
2464 | 194 | "the end of the world.", | ||
2465 | 195 | "Nothing in the rest of", | ||
2466 | 196 | "this paragraph needs to", | ||
2467 | 197 | "be changed. Things can", | ||
2468 | 198 | "be added after it." | ||
2469 | 199 | ], [ | ||
2470 | 200 | "This is an important", | ||
2471 | 201 | "notice! It should", | ||
2472 | 202 | "therefore be located at", | ||
2473 | 203 | "the beginning of this", | ||
2474 | 204 | "document!", | ||
2475 | 205 | "", | ||
2476 | 206 | "This part of the", | ||
2477 | 207 | "document has stayed the", | ||
2478 | 208 | "same from version to", | ||
2479 | 209 | "version. It shouldn't", | ||
2480 | 210 | "be shown if it doesn't", | ||
2481 | 211 | "change. Otherwise, that", | ||
2482 | 212 | "would not be helping to", | ||
2483 | 213 | "compress anything.", | ||
2484 | 214 | "", | ||
2485 | 215 | "It is important to spell", | ||
2486 | 216 | "check this document. On", | ||
2487 | 217 | "the other hand, a", | ||
2488 | 218 | "misspelled word isn't", | ||
2489 | 219 | "the end of the world.", | ||
2490 | 220 | "Nothing in the rest of", | ||
2491 | 221 | "this paragraph needs to", | ||
2492 | 222 | "be changed. Things can", | ||
2493 | 223 | "be added after it.", | ||
2494 | 224 | "", | ||
2495 | 225 | "This paragraph contains", | ||
2496 | 226 | "important new additions", | ||
2497 | 227 | "to this document.", | ||
2498 | 228 | ]), [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), | ||
2499 | 229 | (0, 5), (0, 6), (1, 7), (2, 8), (3, 9), | ||
2500 | 230 | (4, 10), (5, 11), (6, 12), (7, 13), (8, 13), | ||
2501 | 231 | (9, 13), (9, 14), (10, 15), (11, 15), (12, 15), | ||
2502 | 232 | (13, 15), (14, 15), (15, 15), (16, 16), (17, 16), | ||
2503 | 233 | (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), | ||
2504 | 234 | (22, 22), (23, 23), (24, 24), (24, 25), (24, 26), | ||
2505 | 235 | (24, 27), (24, 28)]) | ||
2506 | 236 | |||
2507 | 237 | class __Test_diff(unittest.TestCase): | ||
2508 | 238 | def test_zero(self): | ||
2509 | 239 | p = path("", "") | ||
2510 | 240 | |||
2511 | 241 | self.assertEqual(ses(p, ""), []) | ||
2512 | 242 | |||
2513 | 243 | def test_delete(self): | ||
2514 | 244 | p = path("a", "") | ||
2515 | 245 | self.assertEqual(ses(p, ""), [("D", 0)]) | ||
2516 | 246 | |||
2517 | 247 | p = path("abcd", "") | ||
2518 | 248 | self.assertEqual(ses(p, ""), [("D", 0), ("D", 1), ("D", 2), ("D", 3)]) | ||
2519 | 249 | |||
2520 | 250 | p = path("abcd", "cd") | ||
2521 | 251 | self.assertEqual(ses(p, "cd"), [("D", 0), ("D", 1)]) | ||
2522 | 252 | |||
2523 | 253 | p = path("abcd", "ab") | ||
2524 | 254 | self.assertEqual(ses(p, "ab"), [("D", 2), ("D", 3)]) | ||
2525 | 255 | |||
2526 | 256 | p = path("abcd", "bc") | ||
2527 | 257 | self.assertEqual(ses(p, "bc"), [("D", 0), ("D", 3)]) | ||
2528 | 258 | |||
2529 | 259 | def test_insert(self): | ||
2530 | 260 | p = path("", "a") | ||
2531 | 261 | self.assertEqual(ses(p, "a"), [("I", 0, "a")]) | ||
2532 | 262 | |||
2533 | 263 | p = path("", "abcd") | ||
2534 | 264 | self.assertEqual(ses(p, "abcd"), [("I", 0, "a"), ("I", 0, "b"), ("I", 0, "c"), ("I", 0, "d")]) | ||
2535 | 265 | |||
2536 | 266 | def test_delins(self): | ||
2537 | 267 | p = path("abcd", "abef") | ||
2538 | 268 | self.assertEqual(ses(p, "abef"), [("D", 2), ("D", 3), ("I", 4, "e"), ("I", 4, "f")]) | ||
2539 | 269 | |||
2540 | 270 | class __Test_patch(unittest.TestCase): | ||
2541 | 271 | def do_patch(self, a, b): | ||
2542 | 272 | self.assertEqual(patch(ses(path(a, b), b), a), b) | ||
2543 | 273 | |||
2544 | 274 | def test_patch(self): | ||
2545 | 275 | self.do_patch("", "hello") | ||
2546 | 276 | self.do_patch("hello", "") | ||
2547 | 277 | self.do_patch("hello", "hello") | ||
2548 | 278 | self.do_patch("hello", "night night") | ||
2549 | 279 | self.do_patch("hello", "help me") | ||
2550 | 280 | self.do_patch("test bob", "kill bob") | ||
2551 | 281 | self.do_patch("test bill", "test jane") | ||
2552 | 282 | |||
2553 | 283 | if __name__ == "__main__": | ||
2554 | 284 | unittest.main() | ||
2555 | 0 | 285 | ||
2556 | === added file 'dxdiff/dxdiff/utils.py' | |||
2557 | --- dxdiff/dxdiff/utils.py 1970-01-01 00:00:00 +0000 | |||
2558 | +++ dxdiff/dxdiff/utils.py 2011-08-24 16:38:18 +0000 | |||
2559 | @@ -0,0 +1,172 @@ | |||
2560 | 1 | #!/usr/bin/env python | ||
2561 | 2 | |||
2562 | 3 | # This file is part of dxdiff. | ||
2563 | 4 | # | ||
2564 | 5 | # dxdiff is free software: you can redistribute it and/or modify | ||
2565 | 6 | # it under the terms of the GNU General Public License as published by | ||
2566 | 7 | # the Free Software Foundation, either version 3 of the License, or | ||
2567 | 8 | # (at your option) any later version. | ||
2568 | 9 | # | ||
2569 | 10 | # dxdiff is distributed in the hope that it will be useful, | ||
2570 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2571 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2572 | 13 | # GNU General Public License for more details. | ||
2573 | 14 | # | ||
2574 | 15 | # You should have received a copy of the GNU General Public License | ||
2575 | 16 | # along with Diamond. If not, see <http://www.gnu.org/licenses/>. | ||
2576 | 17 | |||
2577 | 18 | def flatten(l): | ||
2578 | 19 | """ | ||
2579 | 20 | Flattens a list of lists into a list. | ||
2580 | 21 | """ | ||
2581 | 22 | return [item for sublist in l for item in sublist] | ||
2582 | 23 | |||
2583 | 24 | def nub(l, reverse=False): | ||
2584 | 25 | """ | ||
2585 | 26 | Removes duplicates from a list. | ||
2586 | 27 | If reverse is true keeps the last duplicate item | ||
2587 | 28 | as opposed to the first. | ||
2588 | 29 | """ | ||
2589 | 30 | if reverse: | ||
2590 | 31 | seen = {} | ||
2591 | 32 | result = [] | ||
2592 | 33 | for item in reversed(l): | ||
2593 | 34 | if item in seen: continue | ||
2594 | 35 | seen[item] = 1 | ||
2595 | 36 | result.append(item) | ||
2596 | 37 | return reversed(result) | ||
2597 | 38 | else: | ||
2598 | 39 | seen = {} | ||
2599 | 40 | result = [] | ||
2600 | 41 | for item in l: | ||
2601 | 42 | if item in seen: continue | ||
2602 | 43 | seen[item] = 1 | ||
2603 | 44 | result.append(item) | ||
2604 | 45 | return result | ||
2605 | 46 | |||
2606 | 47 | def partial(fn, *cargs, **ckwargs): | ||
2607 | 48 | """ | ||
2608 | 49 | Partial function application, taken from PEP 309. | ||
2609 | 50 | """ | ||
2610 | 51 | ckwargs = ckwargs.copy() | ||
2611 | 52 | def call_fn(*fargs, **fkwargs): | ||
2612 | 53 | d = ckwargs | ||
2613 | 54 | d.update(fkwargs) | ||
2614 | 55 | return fn(*(cargs + fargs), **d) | ||
2615 | 56 | return call_fn | ||
2616 | 57 | |||
2617 | 58 | def irange(*args): | ||
2618 | 59 | """ | ||
2619 | 60 | Similar to range but stop is an inclusive upper bound. | ||
2620 | 61 | """ | ||
2621 | 62 | if len(args) == 0: | ||
2622 | 63 | raise TypeError("irange expected at least 1 arguments, got 0") | ||
2623 | 64 | elif len(args) == 1: | ||
2624 | 65 | stop = args[0] | ||
2625 | 66 | start = 0 | ||
2626 | 67 | step = 1 | ||
2627 | 68 | elif len(args) == 2: | ||
2628 | 69 | start, stop = args | ||
2629 | 70 | step = 1 | ||
2630 | 71 | elif len(args) == 3: | ||
2631 | 72 | start, stop, step = args | ||
2632 | 73 | else: | ||
2633 | 74 | raise TypeError("irange expected at most 3 arguments, got " + str(len(args))) | ||
2634 | 75 | |||
2635 | 76 | if step == 0: | ||
2636 | 77 | raise ValueError("irange() step argument must not be zero") | ||
2637 | 78 | |||
2638 | 79 | stop = stop + 1 if step > 0 else stop - 1 | ||
2639 | 80 | return range(start, stop, step) | ||
2640 | 81 | |||
2641 | 82 | ################## | ||
2642 | 83 | ### Unit Tests ### | ||
2643 | 84 | ################## | ||
2644 | 85 | |||
2645 | 86 | import unittest | ||
2646 | 87 | |||
2647 | 88 | class __Test_flatten(unittest.TestCase): | ||
2648 | 89 | def test_type(self): | ||
2649 | 90 | self.assertRaises(TypeError, flatten, 1, 2, 3) | ||
2650 | 91 | |||
2651 | 92 | def test_zero(self): | ||
2652 | 93 | self.assertEqual(flatten([]), []) | ||
2653 | 94 | self.assertEqual(flatten([[]]), []) | ||
2654 | 95 | self.assertEqual(flatten([[], []]), []) | ||
2655 | 96 | |||
2656 | 97 | def test_one(self): | ||
2657 | 98 | self.assertEqual(flatten([[1]]), [1]) | ||
2658 | 99 | self.assertEqual(flatten([[1, 2], [3, 4]]), [1, 2, 3, 4]) | ||
2659 | 100 | |||
2660 | 101 | def test_two(self): | ||
2661 | 102 | self.assertEqual(flatten([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), [[1, 2], [3, 4], [5, 6], [7, 8]]) | ||
2662 | 103 | |||
2663 | 104 | class __Test_nub(unittest.TestCase): | ||
2664 | 105 | def test_zero(self): | ||
2665 | 106 | self.assertEqual(nub([]), []) | ||
2666 | 107 | |||
2667 | 108 | def test_nodups(self): | ||
2668 | 109 | self.assertEqual(nub([1, 2, 3, 4]), [1, 2, 3, 4]) | ||
2669 | 110 | |||
2670 | 111 | def test_dups(self): | ||
2671 | 112 | self.assertEqual(nub([1, 1, 2, 3, 4, 2]), [1, 2, 3, 4]) | ||
2672 | 113 | |||
2673 | 114 | class __Test_partial(unittest.TestCase): | ||
2674 | 115 | def printer(*args, **kargs): | ||
2675 | 116 | result = [] | ||
2676 | 117 | for arg in args: | ||
2677 | 118 | result.append(str(args)) | ||
2678 | 119 | for k, v in kargs.items(): | ||
2679 | 120 | result.append(str(k) + ": " + str(v)) | ||
2680 | 121 | return ' '.join(result) | ||
2681 | 122 | |||
2682 | 123 | def test_zero(self): | ||
2683 | 124 | self.assertEqual(partial(self.printer)(), self.printer()) | ||
2684 | 125 | |||
2685 | 126 | def test_args(self): | ||
2686 | 127 | self.assertEqual(partial(self.printer, 1)(), self.printer(1)) | ||
2687 | 128 | self.assertEqual(partial(self.printer)(1), self.printer(1)) | ||
2688 | 129 | |||
2689 | 130 | def test_kargs(self): | ||
2690 | 131 | self.assertEqual(partial(self.printer, a = 0)(), self.printer(a = 0)) | ||
2691 | 132 | self.assertEqual(partial(self.printer)(a = 0), self.printer(a = 0)) | ||
2692 | 133 | |||
2693 | 134 | class __Test_irange(unittest.TestCase): | ||
2694 | 135 | def test_type(self): | ||
2695 | 136 | self.assertRaises(TypeError, irange) | ||
2696 | 137 | self.assertRaises(TypeError, irange, 0, 1, 2, 3) | ||
2697 | 138 | self.assertRaises(TypeError, irange, 0, 1, 2, 3, 4) | ||
2698 | 139 | |||
2699 | 140 | def test_zerostep(self): | ||
2700 | 141 | self.assertRaises(ValueError, irange, 0, 0, 0) | ||
2701 | 142 | self.assertRaises(ValueError, irange, 1, 2, 0) | ||
2702 | 143 | |||
2703 | 144 | def test_zero(self): | ||
2704 | 145 | self.assertEqual(irange(0), [0]) | ||
2705 | 146 | |||
2706 | 147 | def test_stop(self): | ||
2707 | 148 | self.assertEqual(irange(1), [0, 1]) | ||
2708 | 149 | self.assertEqual(irange(2), [0, 1, 2]) | ||
2709 | 150 | |||
2710 | 151 | def test_start(self): | ||
2711 | 152 | self.assertEqual(irange(5, 10), [5, 6, 7, 8, 9, 10]) | ||
2712 | 153 | |||
2713 | 154 | def test_step(self): | ||
2714 | 155 | self.assertEqual(irange(0, 4, 2), [0, 2, 4]) | ||
2715 | 156 | self.assertEqual(irange(0, 3, 2), [0, 2]) | ||
2716 | 157 | |||
2717 | 158 | def test_negative(self): | ||
2718 | 159 | self.assertEqual(irange(-10, -5), [-10, -9, -8, -7, -6, -5]) | ||
2719 | 160 | self.assertEqual(irange(-5, 5), [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) | ||
2720 | 161 | |||
2721 | 162 | def test_negstep(self): | ||
2722 | 163 | self.assertEqual(irange(5, 0, -1), [5, 4, 3, 2, 1, 0]) | ||
2723 | 164 | self.assertEqual(irange(2, -2, -1), [2, 1, 0, -1, -2]) | ||
2724 | 165 | |||
2725 | 166 | def test_norange(self): | ||
2726 | 167 | self.assertEqual(irange(5, 0), []) | ||
2727 | 168 | self.assertEqual(irange(1, -1), []) | ||
2728 | 169 | self.assertEqual(irange(0, 5, -1), []) | ||
2729 | 170 | |||
2730 | 171 | if __name__ == "__main__": | ||
2731 | 172 | unittest.main() | ||
2732 | 0 | 173 | ||
2733 | === added file 'dxdiff/setup.py' | |||
2734 | --- dxdiff/setup.py 1970-01-01 00:00:00 +0000 | |||
2735 | +++ dxdiff/setup.py 2011-08-24 16:38:18 +0000 | |||
2736 | @@ -0,0 +1,21 @@ | |||
2737 | 1 | from distutils.core import setup | ||
2738 | 2 | import os | ||
2739 | 3 | import os.path | ||
2740 | 4 | import glob | ||
2741 | 5 | |||
2742 | 6 | try: | ||
2743 | 7 | destdir = os.environ["DESTDIR"] | ||
2744 | 8 | except KeyError: | ||
2745 | 9 | destdir = "" | ||
2746 | 10 | |||
2747 | 11 | setup( | ||
2748 | 12 | name='dxdiff', | ||
2749 | 13 | version='1.0', | ||
2750 | 14 | description="An XML aware diff tool.", | ||
2751 | 15 | author = "The ICOM team", | ||
2752 | 16 | author_email = "fraser.waters08@imperial.ac.uk", | ||
2753 | 17 | url = "http://amcg.ese.ic.ac.uk", | ||
2754 | 18 | packages = ['dxdiff'], | ||
2755 | 19 | scripts=["dxdiff/dxdiff"], | ||
2756 | 20 | ) | ||
2757 | 21 | |||
2758 | 0 | 22 | ||
2759 | === modified file 'examples/show_ballistics' (properties changed: +x to -x) | |||
2760 | === modified file 'install-sh' (properties changed: +x to -x) |
[pef@caoimhe: /tmp/xmldiff/ diamond] $ python bin/diamond diamond/ bin/../ diamond/ interface. py", line 50, in <module>
Traceback (most recent call last):
File "bin/diamond", line 228, in <module>
main()
File "bin/diamond", line 92, in main
import diamond.interface as interface
File "/tmp/xmldiff/
import diffview
ImportError: No module named diffview
Did you forget to bzr add?