16 |
16 |
17 a { color: #BA6D36; } |
17 a { color: #BA6D36; } |
18 |
18 |
19 </style> |
19 </style> |
20 </head> |
20 </head> |
21 <body><a NAME="top" ID="top"></a> |
21 <body> |
|
22 <a NAME="top" ID="top"></a> |
22 <h1>eric6.UI.DiffDialog</h1> |
23 <h1>eric6.UI.DiffDialog</h1> |
|
24 |
23 <p> |
25 <p> |
24 Module implementing a dialog to compare two files. |
26 Module implementing a dialog to compare two files. |
25 </p> |
27 </p> |
26 <h3>Global Attributes</h3> |
28 <h3>Global Attributes</h3> |
|
29 |
27 <table> |
30 <table> |
28 <tr><td>None</td></tr> |
31 <tr><td>None</td></tr> |
29 </table> |
32 </table> |
30 <h3>Classes</h3> |
33 <h3>Classes</h3> |
31 <table> |
34 |
|
35 <table> |
|
36 |
32 <tr> |
37 <tr> |
33 <td><a href="#DiffDialog">DiffDialog</a></td> |
38 <td><a href="#DiffDialog">DiffDialog</a></td> |
34 <td>Class implementing a dialog to compare two files.</td> |
39 <td>Class implementing a dialog to compare two files.</td> |
35 </tr><tr> |
40 </tr> |
|
41 <tr> |
36 <td><a href="#DiffWindow">DiffWindow</a></td> |
42 <td><a href="#DiffWindow">DiffWindow</a></td> |
37 <td>Main window class for the standalone dialog.</td> |
43 <td>Main window class for the standalone dialog.</td> |
38 </tr> |
44 </tr> |
39 </table> |
45 </table> |
40 <h3>Functions</h3> |
46 <h3>Functions</h3> |
41 <table> |
47 |
|
48 <table> |
|
49 |
42 <tr> |
50 <tr> |
43 <td><a href="#context_diff">context_diff</a></td> |
51 <td><a href="#context_diff">context_diff</a></td> |
44 <td>Compare two sequences of lines; generate the delta as a context diff.</td> |
52 <td>Compare two sequences of lines; generate the delta as a context diff.</td> |
45 </tr><tr> |
53 </tr> |
|
54 <tr> |
46 <td><a href="#unified_diff">unified_diff</a></td> |
55 <td><a href="#unified_diff">unified_diff</a></td> |
47 <td>Compare two sequences of lines; generate the delta as a unified diff.</td> |
56 <td>Compare two sequences of lines; generate the delta as a unified diff.</td> |
48 </tr> |
57 </tr> |
49 </table> |
58 </table> |
50 <hr /><hr /> |
59 <hr /> |
|
60 <hr /> |
51 <a NAME="DiffDialog" ID="DiffDialog"></a> |
61 <a NAME="DiffDialog" ID="DiffDialog"></a> |
52 <h2>DiffDialog</h2> |
62 <h2>DiffDialog</h2> |
|
63 |
53 <p> |
64 <p> |
54 Class implementing a dialog to compare two files. |
65 Class implementing a dialog to compare two files. |
55 </p> |
66 </p> |
56 <h3>Derived from</h3> |
67 <h3>Derived from</h3> |
57 QWidget, Ui_DiffDialog |
68 QWidget, Ui_DiffDialog |
58 <h3>Class Attributes</h3> |
69 <h3>Class Attributes</h3> |
|
70 |
59 <table> |
71 <table> |
60 <tr><td>None</td></tr> |
72 <tr><td>None</td></tr> |
61 </table> |
73 </table> |
62 <h3>Class Methods</h3> |
74 <h3>Class Methods</h3> |
|
75 |
63 <table> |
76 <table> |
64 <tr><td>None</td></tr> |
77 <tr><td>None</td></tr> |
65 </table> |
78 </table> |
66 <h3>Methods</h3> |
79 <h3>Methods</h3> |
67 <table> |
80 |
|
81 <table> |
|
82 |
68 <tr> |
83 <tr> |
69 <td><a href="#DiffDialog.__init__">DiffDialog</a></td> |
84 <td><a href="#DiffDialog.__init__">DiffDialog</a></td> |
70 <td>Constructor</td> |
85 <td>Constructor</td> |
71 </tr><tr> |
86 </tr> |
|
87 <tr> |
72 <td><a href="#DiffDialog.__appendText">__appendText</a></td> |
88 <td><a href="#DiffDialog.__appendText">__appendText</a></td> |
73 <td>Private method to append text to the end of the contents pane.</td> |
89 <td>Private method to append text to the end of the contents pane.</td> |
74 </tr><tr> |
90 </tr> |
|
91 <tr> |
75 <td><a href="#DiffDialog.__fileChanged">__fileChanged</a></td> |
92 <td><a href="#DiffDialog.__fileChanged">__fileChanged</a></td> |
76 <td>Private slot to enable/disable the Compare button.</td> |
93 <td>Private slot to enable/disable the Compare button.</td> |
77 </tr><tr> |
94 </tr> |
|
95 <tr> |
78 <td><a href="#DiffDialog.__generateContextDiff">__generateContextDiff</a></td> |
96 <td><a href="#DiffDialog.__generateContextDiff">__generateContextDiff</a></td> |
79 <td>Private slot to generate a context diff output.</td> |
97 <td>Private slot to generate a context diff output.</td> |
80 </tr><tr> |
98 </tr> |
|
99 <tr> |
81 <td><a href="#DiffDialog.__generateUnifiedDiff">__generateUnifiedDiff</a></td> |
100 <td><a href="#DiffDialog.__generateUnifiedDiff">__generateUnifiedDiff</a></td> |
82 <td>Private slot to generate a unified diff output.</td> |
101 <td>Private slot to generate a unified diff output.</td> |
83 </tr><tr> |
102 </tr> |
|
103 <tr> |
84 <td><a href="#DiffDialog.on_buttonBox_clicked">on_buttonBox_clicked</a></td> |
104 <td><a href="#DiffDialog.on_buttonBox_clicked">on_buttonBox_clicked</a></td> |
85 <td>Private slot called by a button of the button box clicked.</td> |
105 <td>Private slot called by a button of the button box clicked.</td> |
86 </tr><tr> |
106 </tr> |
|
107 <tr> |
87 <td><a href="#DiffDialog.on_diffButton_clicked">on_diffButton_clicked</a></td> |
108 <td><a href="#DiffDialog.on_diffButton_clicked">on_diffButton_clicked</a></td> |
88 <td>Private slot to handle the Compare button press.</td> |
109 <td>Private slot to handle the Compare button press.</td> |
89 </tr><tr> |
110 </tr> |
|
111 <tr> |
90 <td><a href="#DiffDialog.on_saveButton_clicked">on_saveButton_clicked</a></td> |
112 <td><a href="#DiffDialog.on_saveButton_clicked">on_saveButton_clicked</a></td> |
91 <td>Private slot to handle the Save button press.</td> |
113 <td>Private slot to handle the Save button press.</td> |
92 </tr><tr> |
114 </tr> |
|
115 <tr> |
93 <td><a href="#DiffDialog.show">show</a></td> |
116 <td><a href="#DiffDialog.show">show</a></td> |
94 <td>Public slot to show the dialog.</td> |
117 <td>Public slot to show the dialog.</td> |
95 </tr> |
118 </tr> |
96 </table> |
119 </table> |
97 <h3>Static Methods</h3> |
120 <h3>Static Methods</h3> |
98 <table> |
121 |
99 <tr><td>None</td></tr> |
122 <table> |
100 </table> |
123 <tr><td>None</td></tr> |
|
124 </table> |
|
125 |
101 <a NAME="DiffDialog.__init__" ID="DiffDialog.__init__"></a> |
126 <a NAME="DiffDialog.__init__" ID="DiffDialog.__init__"></a> |
102 <h4>DiffDialog (Constructor)</h4> |
127 <h4>DiffDialog (Constructor)</h4> |
103 <b>DiffDialog</b>(<i>parent=None</i>) |
128 <b>DiffDialog</b>(<i>parent=None</i>) |
|
129 |
104 <p> |
130 <p> |
105 Constructor |
131 Constructor |
106 </p><dl> |
132 </p> |
|
133 <dl> |
|
134 |
107 <dt><i>parent</i></dt> |
135 <dt><i>parent</i></dt> |
108 <dd> |
136 <dd> |
109 reference to the parent widget (QWidget) |
137 reference to the parent widget (QWidget) |
110 </dd> |
138 </dd> |
111 </dl><a NAME="DiffDialog.__appendText" ID="DiffDialog.__appendText"></a> |
139 </dl> |
|
140 <a NAME="DiffDialog.__appendText" ID="DiffDialog.__appendText"></a> |
112 <h4>DiffDialog.__appendText</h4> |
141 <h4>DiffDialog.__appendText</h4> |
113 <b>__appendText</b>(<i>txt</i>) |
142 <b>__appendText</b>(<i>txt</i>) |
|
143 |
114 <p> |
144 <p> |
115 Private method to append text to the end of the contents pane. |
145 Private method to append text to the end of the contents pane. |
116 </p><dl> |
146 </p> |
|
147 <dl> |
|
148 |
117 <dt><i>txt</i></dt> |
149 <dt><i>txt</i></dt> |
118 <dd> |
150 <dd> |
119 text to insert (string) |
151 text to insert (string) |
120 </dd> |
152 </dd> |
121 </dl><a NAME="DiffDialog.__fileChanged" ID="DiffDialog.__fileChanged"></a> |
153 </dl> |
|
154 <a NAME="DiffDialog.__fileChanged" ID="DiffDialog.__fileChanged"></a> |
122 <h4>DiffDialog.__fileChanged</h4> |
155 <h4>DiffDialog.__fileChanged</h4> |
123 <b>__fileChanged</b>(<i></i>) |
156 <b>__fileChanged</b>(<i></i>) |
|
157 |
124 <p> |
158 <p> |
125 Private slot to enable/disable the Compare button. |
159 Private slot to enable/disable the Compare button. |
126 </p><a NAME="DiffDialog.__generateContextDiff" ID="DiffDialog.__generateContextDiff"></a> |
160 </p> |
|
161 <a NAME="DiffDialog.__generateContextDiff" ID="DiffDialog.__generateContextDiff"></a> |
127 <h4>DiffDialog.__generateContextDiff</h4> |
162 <h4>DiffDialog.__generateContextDiff</h4> |
128 <b>__generateContextDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
163 <b>__generateContextDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
|
164 |
129 <p> |
165 <p> |
130 Private slot to generate a context diff output. |
166 Private slot to generate a context diff output. |
131 </p><dl> |
167 </p> |
|
168 <dl> |
|
169 |
132 <dt><i>a</i></dt> |
170 <dt><i>a</i></dt> |
133 <dd> |
171 <dd> |
134 first sequence of lines (list of strings) |
172 first sequence of lines (list of strings) |
135 </dd><dt><i>b</i></dt> |
173 </dd> |
|
174 <dt><i>b</i></dt> |
136 <dd> |
175 <dd> |
137 second sequence of lines (list of strings) |
176 second sequence of lines (list of strings) |
138 </dd><dt><i>fromfile</i></dt> |
177 </dd> |
|
178 <dt><i>fromfile</i></dt> |
139 <dd> |
179 <dd> |
140 filename of the first file (string) |
180 filename of the first file (string) |
141 </dd><dt><i>tofile</i></dt> |
181 </dd> |
|
182 <dt><i>tofile</i></dt> |
142 <dd> |
183 <dd> |
143 filename of the second file (string) |
184 filename of the second file (string) |
144 </dd><dt><i>fromfiledate</i></dt> |
185 </dd> |
|
186 <dt><i>fromfiledate</i></dt> |
145 <dd> |
187 <dd> |
146 modification time of the first file (string) |
188 modification time of the first file (string) |
147 </dd><dt><i>tofiledate</i></dt> |
189 </dd> |
|
190 <dt><i>tofiledate</i></dt> |
148 <dd> |
191 <dd> |
149 modification time of the second file (string) |
192 modification time of the second file (string) |
150 </dd> |
193 </dd> |
151 </dl><a NAME="DiffDialog.__generateUnifiedDiff" ID="DiffDialog.__generateUnifiedDiff"></a> |
194 </dl> |
|
195 <a NAME="DiffDialog.__generateUnifiedDiff" ID="DiffDialog.__generateUnifiedDiff"></a> |
152 <h4>DiffDialog.__generateUnifiedDiff</h4> |
196 <h4>DiffDialog.__generateUnifiedDiff</h4> |
153 <b>__generateUnifiedDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
197 <b>__generateUnifiedDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
|
198 |
154 <p> |
199 <p> |
155 Private slot to generate a unified diff output. |
200 Private slot to generate a unified diff output. |
156 </p><dl> |
201 </p> |
|
202 <dl> |
|
203 |
157 <dt><i>a</i></dt> |
204 <dt><i>a</i></dt> |
158 <dd> |
205 <dd> |
159 first sequence of lines (list of strings) |
206 first sequence of lines (list of strings) |
160 </dd><dt><i>b</i></dt> |
207 </dd> |
|
208 <dt><i>b</i></dt> |
161 <dd> |
209 <dd> |
162 second sequence of lines (list of strings) |
210 second sequence of lines (list of strings) |
163 </dd><dt><i>fromfile</i></dt> |
211 </dd> |
|
212 <dt><i>fromfile</i></dt> |
164 <dd> |
213 <dd> |
165 filename of the first file (string) |
214 filename of the first file (string) |
166 </dd><dt><i>tofile</i></dt> |
215 </dd> |
|
216 <dt><i>tofile</i></dt> |
167 <dd> |
217 <dd> |
168 filename of the second file (string) |
218 filename of the second file (string) |
169 </dd><dt><i>fromfiledate</i></dt> |
219 </dd> |
|
220 <dt><i>fromfiledate</i></dt> |
170 <dd> |
221 <dd> |
171 modification time of the first file (string) |
222 modification time of the first file (string) |
172 </dd><dt><i>tofiledate</i></dt> |
223 </dd> |
|
224 <dt><i>tofiledate</i></dt> |
173 <dd> |
225 <dd> |
174 modification time of the second file (string) |
226 modification time of the second file (string) |
175 </dd> |
227 </dd> |
176 </dl><a NAME="DiffDialog.on_buttonBox_clicked" ID="DiffDialog.on_buttonBox_clicked"></a> |
228 </dl> |
|
229 <a NAME="DiffDialog.on_buttonBox_clicked" ID="DiffDialog.on_buttonBox_clicked"></a> |
177 <h4>DiffDialog.on_buttonBox_clicked</h4> |
230 <h4>DiffDialog.on_buttonBox_clicked</h4> |
178 <b>on_buttonBox_clicked</b>(<i>button</i>) |
231 <b>on_buttonBox_clicked</b>(<i>button</i>) |
|
232 |
179 <p> |
233 <p> |
180 Private slot called by a button of the button box clicked. |
234 Private slot called by a button of the button box clicked. |
181 </p><dl> |
235 </p> |
|
236 <dl> |
|
237 |
182 <dt><i>button</i></dt> |
238 <dt><i>button</i></dt> |
183 <dd> |
239 <dd> |
184 button that was clicked (QAbstractButton) |
240 button that was clicked (QAbstractButton) |
185 </dd> |
241 </dd> |
186 </dl><a NAME="DiffDialog.on_diffButton_clicked" ID="DiffDialog.on_diffButton_clicked"></a> |
242 </dl> |
|
243 <a NAME="DiffDialog.on_diffButton_clicked" ID="DiffDialog.on_diffButton_clicked"></a> |
187 <h4>DiffDialog.on_diffButton_clicked</h4> |
244 <h4>DiffDialog.on_diffButton_clicked</h4> |
188 <b>on_diffButton_clicked</b>(<i></i>) |
245 <b>on_diffButton_clicked</b>(<i></i>) |
|
246 |
189 <p> |
247 <p> |
190 Private slot to handle the Compare button press. |
248 Private slot to handle the Compare button press. |
191 </p><a NAME="DiffDialog.on_saveButton_clicked" ID="DiffDialog.on_saveButton_clicked"></a> |
249 </p> |
|
250 <a NAME="DiffDialog.on_saveButton_clicked" ID="DiffDialog.on_saveButton_clicked"></a> |
192 <h4>DiffDialog.on_saveButton_clicked</h4> |
251 <h4>DiffDialog.on_saveButton_clicked</h4> |
193 <b>on_saveButton_clicked</b>(<i></i>) |
252 <b>on_saveButton_clicked</b>(<i></i>) |
|
253 |
194 <p> |
254 <p> |
195 Private slot to handle the Save button press. |
255 Private slot to handle the Save button press. |
196 </p><p> |
256 </p> |
|
257 <p> |
197 It saves the diff shown in the dialog to a file in the local |
258 It saves the diff shown in the dialog to a file in the local |
198 filesystem. |
259 filesystem. |
199 </p><a NAME="DiffDialog.show" ID="DiffDialog.show"></a> |
260 </p> |
|
261 <a NAME="DiffDialog.show" ID="DiffDialog.show"></a> |
200 <h4>DiffDialog.show</h4> |
262 <h4>DiffDialog.show</h4> |
201 <b>show</b>(<i>filename=None</i>) |
263 <b>show</b>(<i>filename=None</i>) |
|
264 |
202 <p> |
265 <p> |
203 Public slot to show the dialog. |
266 Public slot to show the dialog. |
204 </p><dl> |
267 </p> |
|
268 <dl> |
|
269 |
205 <dt><i>filename</i></dt> |
270 <dt><i>filename</i></dt> |
206 <dd> |
271 <dd> |
207 name of a file to use as the first file (string) |
272 name of a file to use as the first file (string) |
208 </dd> |
273 </dd> |
209 </dl> |
274 </dl> |
210 <div align="right"><a href="#top">Up</a></div> |
275 <div align="right"><a href="#top">Up</a></div> |
211 <hr /><hr /> |
276 <hr /> |
|
277 <hr /> |
212 <a NAME="DiffWindow" ID="DiffWindow"></a> |
278 <a NAME="DiffWindow" ID="DiffWindow"></a> |
213 <h2>DiffWindow</h2> |
279 <h2>DiffWindow</h2> |
|
280 |
214 <p> |
281 <p> |
215 Main window class for the standalone dialog. |
282 Main window class for the standalone dialog. |
216 </p> |
283 </p> |
217 <h3>Derived from</h3> |
284 <h3>Derived from</h3> |
218 E5MainWindow |
285 E5MainWindow |
219 <h3>Class Attributes</h3> |
286 <h3>Class Attributes</h3> |
|
287 |
220 <table> |
288 <table> |
221 <tr><td>None</td></tr> |
289 <tr><td>None</td></tr> |
222 </table> |
290 </table> |
223 <h3>Class Methods</h3> |
291 <h3>Class Methods</h3> |
|
292 |
224 <table> |
293 <table> |
225 <tr><td>None</td></tr> |
294 <tr><td>None</td></tr> |
226 </table> |
295 </table> |
227 <h3>Methods</h3> |
296 <h3>Methods</h3> |
228 <table> |
297 |
|
298 <table> |
|
299 |
229 <tr> |
300 <tr> |
230 <td><a href="#DiffWindow.__init__">DiffWindow</a></td> |
301 <td><a href="#DiffWindow.__init__">DiffWindow</a></td> |
231 <td>Constructor</td> |
302 <td>Constructor</td> |
232 </tr><tr> |
303 </tr> |
|
304 <tr> |
233 <td><a href="#DiffWindow.eventFilter">eventFilter</a></td> |
305 <td><a href="#DiffWindow.eventFilter">eventFilter</a></td> |
234 <td>Public method to filter events.</td> |
306 <td>Public method to filter events.</td> |
235 </tr> |
307 </tr> |
236 </table> |
308 </table> |
237 <h3>Static Methods</h3> |
309 <h3>Static Methods</h3> |
238 <table> |
310 |
239 <tr><td>None</td></tr> |
311 <table> |
240 </table> |
312 <tr><td>None</td></tr> |
|
313 </table> |
|
314 |
241 <a NAME="DiffWindow.__init__" ID="DiffWindow.__init__"></a> |
315 <a NAME="DiffWindow.__init__" ID="DiffWindow.__init__"></a> |
242 <h4>DiffWindow (Constructor)</h4> |
316 <h4>DiffWindow (Constructor)</h4> |
243 <b>DiffWindow</b>(<i>parent=None</i>) |
317 <b>DiffWindow</b>(<i>parent=None</i>) |
|
318 |
244 <p> |
319 <p> |
245 Constructor |
320 Constructor |
246 </p><dl> |
321 </p> |
|
322 <dl> |
|
323 |
247 <dt><i>parent</i></dt> |
324 <dt><i>parent</i></dt> |
248 <dd> |
325 <dd> |
249 reference to the parent widget (QWidget) |
326 reference to the parent widget (QWidget) |
250 </dd> |
327 </dd> |
251 </dl><a NAME="DiffWindow.eventFilter" ID="DiffWindow.eventFilter"></a> |
328 </dl> |
|
329 <a NAME="DiffWindow.eventFilter" ID="DiffWindow.eventFilter"></a> |
252 <h4>DiffWindow.eventFilter</h4> |
330 <h4>DiffWindow.eventFilter</h4> |
253 <b>eventFilter</b>(<i>obj, event</i>) |
331 <b>eventFilter</b>(<i>obj, event</i>) |
|
332 |
254 <p> |
333 <p> |
255 Public method to filter events. |
334 Public method to filter events. |
256 </p><dl> |
335 </p> |
|
336 <dl> |
|
337 |
257 <dt><i>obj</i></dt> |
338 <dt><i>obj</i></dt> |
258 <dd> |
339 <dd> |
259 reference to the object the event is meant for (QObject) |
340 reference to the object the event is meant for (QObject) |
260 </dd><dt><i>event</i></dt> |
341 </dd> |
|
342 <dt><i>event</i></dt> |
261 <dd> |
343 <dd> |
262 reference to the event object (QEvent) |
344 reference to the event object (QEvent) |
263 </dd> |
345 </dd> |
264 </dl><dl> |
346 </dl> |
|
347 <dl> |
265 <dt>Returns:</dt> |
348 <dt>Returns:</dt> |
266 <dd> |
349 <dd> |
267 flag indicating, whether the event was handled (boolean) |
350 flag indicating, whether the event was handled (boolean) |
268 </dd> |
351 </dd> |
269 </dl> |
352 </dl> |
270 <div align="right"><a href="#top">Up</a></div> |
353 <div align="right"><a href="#top">Up</a></div> |
271 <hr /><hr /> |
354 <hr /> |
|
355 <hr /> |
272 <a NAME="context_diff" ID="context_diff"></a> |
356 <a NAME="context_diff" ID="context_diff"></a> |
273 <h2>context_diff</h2> |
357 <h2>context_diff</h2> |
274 <b>context_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
358 <b>context_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
|
359 |
275 <p> |
360 <p> |
276 Compare two sequences of lines; generate the delta as a context diff. |
361 Compare two sequences of lines; generate the delta as a context diff. |
277 </p><p> |
362 </p> |
|
363 <p> |
278 Context diffs are a compact way of showing line changes and a few |
364 Context diffs are a compact way of showing line changes and a few |
279 lines of context. The number of context lines is set by 'n' which |
365 lines of context. The number of context lines is set by 'n' which |
280 defaults to three. |
366 defaults to three. |
281 </p><p> |
367 </p> |
|
368 <p> |
282 By default, the diff control lines (those with *** or ---) are |
369 By default, the diff control lines (those with *** or ---) are |
283 created with a trailing newline. This is helpful so that inputs |
370 created with a trailing newline. This is helpful so that inputs |
284 created from file.readlines() result in diffs that are suitable for |
371 created from file.readlines() result in diffs that are suitable for |
285 file.writelines() since both the inputs and outputs have trailing |
372 file.writelines() since both the inputs and outputs have trailing |
286 newlines. |
373 newlines. |
287 </p><p> |
374 </p> |
|
375 <p> |
288 For inputs that do not have trailing newlines, set the lineterm |
376 For inputs that do not have trailing newlines, set the lineterm |
289 argument to "" so that the output will be uniformly newline free. |
377 argument to "" so that the output will be uniformly newline free. |
290 </p><p> |
378 </p> |
|
379 <p> |
291 The context diff format normally has a header for filenames and |
380 The context diff format normally has a header for filenames and |
292 modification times. Any or all of these may be specified using |
381 modification times. Any or all of these may be specified using |
293 strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. |
382 strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. |
294 The modification times are normally expressed in the format returned |
383 The modification times are normally expressed in the format returned |
295 by time.ctime(). If not specified, the strings default to blanks. |
384 by time.ctime(). If not specified, the strings default to blanks. |
296 </p><p> |
385 </p> |
|
386 <p> |
297 Example: |
387 Example: |
298 </p><p> |
388 </p> |
|
389 <p> |
299 <pre> |
390 <pre> |
300 >>> print ''.join( |
391 >>> print ''.join( |
301 ... context_diff('one\ntwo\nthree\nfour\n'.splitlines(1), |
392 ... context_diff('one\ntwo\nthree\nfour\n'.splitlines(1), |
302 ... 'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current', |
393 ... 'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current', |
303 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:22:46 2003')), |
394 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:22:46 2003')), |
313 + zero |
404 + zero |
314 one |
405 one |
315 ! tree |
406 ! tree |
316 four |
407 four |
317 </pre> |
408 </pre> |
318 </p><dl> |
409 </p> |
|
410 <dl> |
|
411 |
319 <dt><i>a</i></dt> |
412 <dt><i>a</i></dt> |
320 <dd> |
413 <dd> |
321 first sequence of lines (list of strings) |
414 first sequence of lines (list of strings) |
322 </dd><dt><i>b</i></dt> |
415 </dd> |
|
416 <dt><i>b</i></dt> |
323 <dd> |
417 <dd> |
324 second sequence of lines (list of strings) |
418 second sequence of lines (list of strings) |
325 </dd><dt><i>fromfile</i></dt> |
419 </dd> |
|
420 <dt><i>fromfile</i></dt> |
326 <dd> |
421 <dd> |
327 filename of the first file (string) |
422 filename of the first file (string) |
328 </dd><dt><i>tofile</i></dt> |
423 </dd> |
|
424 <dt><i>tofile</i></dt> |
329 <dd> |
425 <dd> |
330 filename of the second file (string) |
426 filename of the second file (string) |
331 </dd><dt><i>fromfiledate</i></dt> |
427 </dd> |
|
428 <dt><i>fromfiledate</i></dt> |
332 <dd> |
429 <dd> |
333 modification time of the first file (string) |
430 modification time of the first file (string) |
334 </dd><dt><i>tofiledate</i></dt> |
431 </dd> |
|
432 <dt><i>tofiledate</i></dt> |
335 <dd> |
433 <dd> |
336 modification time of the second file (string) |
434 modification time of the second file (string) |
337 </dd><dt><i>n</i></dt> |
435 </dd> |
|
436 <dt><i>n</i></dt> |
338 <dd> |
437 <dd> |
339 number of lines of context (integer) |
438 number of lines of context (integer) |
340 </dd><dt><i>lineterm</i></dt> |
439 </dd> |
|
440 <dt><i>lineterm</i></dt> |
341 <dd> |
441 <dd> |
342 line termination string (string) |
442 line termination string (string) |
343 </dd> |
443 </dd> |
344 </dl><dl> |
444 </dl> |
|
445 <dl> |
345 <dt>Returns:</dt> |
446 <dt>Returns:</dt> |
346 <dd> |
447 <dd> |
347 a generator yielding lines of differences |
448 a generator yielding lines of differences |
348 </dd> |
449 </dd> |
349 </dl> |
450 </dl> |
350 <div align="right"><a href="#top">Up</a></div> |
451 <div align="right"><a href="#top">Up</a></div> |
351 <hr /><hr /> |
452 <hr /> |
|
453 <hr /> |
352 <a NAME="unified_diff" ID="unified_diff"></a> |
454 <a NAME="unified_diff" ID="unified_diff"></a> |
353 <h2>unified_diff</h2> |
455 <h2>unified_diff</h2> |
354 <b>unified_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
456 <b>unified_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
|
457 |
355 <p> |
458 <p> |
356 Compare two sequences of lines; generate the delta as a unified diff. |
459 Compare two sequences of lines; generate the delta as a unified diff. |
357 </p><p> |
460 </p> |
|
461 <p> |
358 Unified diffs are a compact way of showing line changes and a few |
462 Unified diffs are a compact way of showing line changes and a few |
359 lines of context. The number of context lines is set by 'n' which |
463 lines of context. The number of context lines is set by 'n' which |
360 defaults to three. |
464 defaults to three. |
361 </p><p> |
465 </p> |
|
466 <p> |
362 By default, the diff control lines (those with ---, +++, or @@) are |
467 By default, the diff control lines (those with ---, +++, or @@) are |
363 created with a trailing newline. This is helpful so that inputs |
468 created with a trailing newline. This is helpful so that inputs |
364 created from file.readlines() result in diffs that are suitable for |
469 created from file.readlines() result in diffs that are suitable for |
365 file.writelines() since both the inputs and outputs have trailing |
470 file.writelines() since both the inputs and outputs have trailing |
366 newlines. |
471 newlines. |
367 </p><p> |
472 </p> |
|
473 <p> |
368 For inputs that do not have trailing newlines, set the lineterm |
474 For inputs that do not have trailing newlines, set the lineterm |
369 argument to "" so that the output will be uniformly newline free. |
475 argument to "" so that the output will be uniformly newline free. |
370 </p><p> |
476 </p> |
|
477 <p> |
371 The unidiff format normally has a header for filenames and modification |
478 The unidiff format normally has a header for filenames and modification |
372 times. Any or all of these may be specified using strings for |
479 times. Any or all of these may be specified using strings for |
373 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification |
480 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification |
374 times are normally expressed in the format returned by time.ctime(). |
481 times are normally expressed in the format returned by time.ctime(). |
375 </p><p> |
482 </p> |
|
483 <p> |
376 Example: |
484 Example: |
377 </p><p> |
485 </p> |
|
486 <p> |
378 <pre> |
487 <pre> |
379 >>> for line in unified_diff('one two three four'.split(), |
488 >>> for line in unified_diff('one two three four'.split(), |
380 ... 'zero one tree four'.split(), 'Original', 'Current', |
489 ... 'zero one tree four'.split(), 'Original', 'Current', |
381 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:20:52 2003', |
490 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:20:52 2003', |
382 ... lineterm=''): |
491 ... lineterm=''): |