Module implementing a dialog to compare two files.
DiffDialog | Class implementing a dialog to compare two files. |
_SequenceMatcher | Class to extend the Python 2.2 SequenceMatcher by a method from Python 2.3. |
context_diff | Compare two sequences of lines; generate the delta as a context diff. |
unified_diff | Compare two sequences of lines; generate the delta as a unified diff. |
Class implementing a dialog to compare two files.
DiffDialog | Constructor |
generateContextDiff | Private slot to generate a context diff output. |
generateUnifiedDiff | Private slot to generate a unified diff output. |
handleDiff | Private slot to handle the Compare button press. |
handleFileChanged | Private slot to enable/disable the Compare button. |
handleSave | Private slot to handle the Save button press. |
handleSelectFile | Private slot to display a file selection dialog. |
handleSelectFile1 | Private slot to handle the file 1 file selection button press. |
handleSelectFile2 | Private slot to handle the file 2 file selection button press. |
Constructor
Private slot to generate a context diff output.
Private slot to generate a unified diff output.
Private slot to handle the Compare button press.
Private slot to enable/disable the Compare button.
Private slot to handle the Save button press.
It saves the diff shown in the dialog to a file in the local filesystem.
Private slot to display a file selection dialog.
Private slot to handle the file 1 file selection button press.
Private slot to handle the file 2 file selection button press.
Class to extend the Python 2.2 SequenceMatcher by a method from Python 2.3.
get_grouped_opcodes | Method to isolate change clusters by eliminating ranges with no changes. |
Method to isolate change clusters by eliminating ranges with no changes.
Return a generator of groups with upto n lines of context. Each group is in the same format as returned by get_opcodes().
>>> from pprint import pprint >>> a = map(str, range(1,40)) >>> b = a[:] >>> b[8:8] = ['i'] # Make an insertion >>> b[20] += 'x' # Make a replacement >>> b[23:28] = [] # Make a deletion >>> b[30] += 'y' # Make another replacement >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes())) [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)], [('equal', 16, 19, 17, 20), ('replace', 19, 20, 20, 21), ('equal', 20, 22, 21, 23), ('delete', 22, 27, 23, 23), ('equal', 27, 30, 23, 26)], [('equal', 31, 34, 27, 30), ('replace', 34, 35, 30, 31), ('equal', 35, 38, 31, 34)]]
Compare two sequences of lines; generate the delta as a context diff.
Context diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which defaults to three.
By default, the diff control lines (those with *** or ---) are created with a trailing newline. This is helpful so that inputs created from file.readlines() result in diffs that are suitable for file.writelines() since both the inputs and outputs have trailing newlines.
For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free.
The context diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification times are normally expressed in the format returned by time.ctime(). If not specified, the strings default to blanks.
Example:
>>> print ''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1), ... 'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current', ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:22:46 2003')), *** Original Sat Jan 26 23:30:50 1991 --- Current Fri Jun 06 10:22:46 2003 *************** *** 1,4 **** one ! two ! three four --- 1,4 ---- + zero one ! tree four
Compare two sequences of lines; generate the delta as a unified diff.
Unified diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which defaults to three.
By default, the diff control lines (those with ---, +++, or @@) are created with a trailing newline. This is helpful so that inputs created from file.readlines() result in diffs that are suitable for file.writelines() since both the inputs and outputs have trailing newlines.
For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free.
The unidiff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification times are normally expressed in the format returned by time.ctime().
Example:
>>> for line in unified_diff('one two three four'.split(), ... 'zero one tree four'.split(), 'Original', 'Current', ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:20:52 2003', ... lineterm=''): ... print line --- Original Sat Jan 26 23:30:50 1991 +++ Current Fri Jun 06 10:20:52 2003 @ -1,4 +1,4 @@ +zero one -two -three +tree four