eric3.UI.DiffDialog

Module implementing a dialog to compare two files.

Classes

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.

Functions

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.


DiffDialog

Class implementing a dialog to compare two files.

Derived from

DiffForm

Methods

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.

DiffDialog (Constructor)

DiffDialog(parent = None)

Constructor

DiffDialog.generateContextDiff

generateContextDiff(a, b, fromfile, tofile, fromfiledate, tofiledate)

Private slot to generate a context diff output.

a
first sequence of lines (list of strings)
b
second sequence of lines (list of strings)
fromfile
filename of the first file (string)
tofile
filename of the second file (string)
fromfiledate
modification time of the first file (string)
tofiledate
modification time of the second file (string)

DiffDialog.generateUnifiedDiff

generateUnifiedDiff(a, b, fromfile, tofile, fromfiledate, tofiledate)

Private slot to generate a unified diff output.

a
first sequence of lines (list of strings)
b
second sequence of lines (list of strings)
fromfile
filename of the first file (string)
tofile
filename of the second file (string)
fromfiledate
modification time of the first file (string)
tofiledate
modification time of the second file (string)

DiffDialog.handleDiff

handleDiff()

Private slot to handle the Compare button press.

DiffDialog.handleFileChanged

handleFileChanged()

Private slot to enable/disable the Compare button.

DiffDialog.handleSave

handleSave()

Private slot to handle the Save button press. It saves the diff shown in the dialog to a file in the local filesystem.

DiffDialog.handleSelectFile

handleSelectFile(lineEdit)

Private slot to display a file selection dialog.

lineEdit
field for the display of the selected filename (QLineEdit)

DiffDialog.handleSelectFile1

handleSelectFile1()

Private slot to handle the file 1 file selection button press.

DiffDialog.handleSelectFile2

handleSelectFile2()

Private slot to handle the file 2 file selection button press.

Up


_SequenceMatcher

Class to extend the Python 2.2 SequenceMatcher by a method from Python 2.3.

Derived from

SequenceMatcher

Methods

get_grouped_opcodes Method to isolate change clusters by eliminating ranges with no changes.

_SequenceMatcher.get_grouped_opcodes

get_grouped_opcodes(n=3)

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)]]
            

n
number of lines of context (integer)
Returns:
a generator of groups with up to n lines of context

Up


context_diff

context_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n')

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
    

a
first sequence of lines (list of strings)
b
second sequence of lines (list of strings)
fromfile
filename of the first file (string)
tofile
filename of the second file (string)
fromfiledate
modification time of the first file (string)
tofiledate
modification time of the second file (string)
n
number of lines of context (integer)
lineterm
line termination string (string)
Returns:
a generator yielding lines of differences
Up


unified_diff

unified_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n')

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
    

a
first sequence of lines (list of strings)
b
second sequence of lines (list of strings)
fromfile
filename of the first file (string)
tofile
filename of the second file (string)
fromfiledate
modification time of the first file (string)
tofiledate
modification time of the second file (string)
n
number of lines of context (integer)
lineterm
line termination string (string)
Returns:
a generator yielding lines of differences
Up