| their :func:`os.stat` signature changes. |
| |
| Note that no external programs are called from this function, giving it |
| portability and efficiency. |
| |
| |
| .. function:: cmpfiles(dir1, dir2, common[, shallow]) |
| |
n | Returns three lists of file names: *match*, *mismatch*, *errors*. *match* |
n | Compare the files in the two directories *dir1* and *dir2* whose names are |
| contains the list of files match in both directories, *mismatch* includes the |
| given by *common*. |
| names of those that don't, and *errros* lists the names of files which could not |
| be compared. Files may be listed in *errors* because the user may lack |
| permission to read them or many other reasons, but always that the comparison |
| could not be done for some reason. |
| |
n | The *common* parameter is a list of file names found in both directories. The |
n | Returns three lists of file names: *match*, *mismatch*, |
| *errors*. *match* contains the list of files that match, *mismatch* contains |
| the names of those that don't, and *errors* lists the names of files which |
| could not be compared. Files are listed in *errors* if they don't exist in |
| one of the directories, the user lacks permission to read them or if the |
| comparison could not be done for some other reason. |
| |
| *shallow* parameter has the same meaning and default value as for |
| The *shallow* parameter has the same meaning and default value as for |
| :func:`filecmp.cmp`. |
n | |
| For example, ``cmpfiles('a', 'b', ['c', 'd/e'])`` will compare ``a/c`` with |
| ``b/c`` and ``a/d/e`` with ``b/d/e``. ``'c'`` and ``'d/e'`` will each be in |
| one of the three returned lists. |
| |
| |
| Example:: |
| |
| >>> import filecmp |
n | >>> filecmp.cmp('libundoc.tex', 'libundoc.tex') |
n | >>> filecmp.cmp('undoc.rst', 'undoc.rst') |
| True |
n | >>> filecmp.cmp('libundoc.tex', 'lib.tex') |
n | >>> filecmp.cmp('undoc.rst', 'index.rst') |
| False |
| |
| |
| .. _dircmp-objects: |
| |
| The :class:`dircmp` class |
| ------------------------- |
| |
| |
| .. class:: dircmp(a, b[, ignore[, hide]]) |
| |
| Construct a new directory comparison object, to compare the directories *a* and |
| *b*. *ignore* is a list of names to ignore, and defaults to ``['RCS', 'CVS', |
| 'tags']``. *hide* is a list of names to hide, and defaults to ``[os.curdir, |
| os.pardir]``. |
| |
n | The :class:`dircmp` class provides the following methods: |
n | The :class:`dircmp` class provides the following methods: |
| |
| |
n | .. method:: dircmp.report() |
n | .. method:: report() |
| |
n | Print (to ``sys.stdout``) a comparison between *a* and *b*. |
n | Print (to ``sys.stdout``) a comparison between *a* and *b*. |
| |
| |
n | .. method:: dircmp.report_partial_closure() |
n | .. method:: report_partial_closure() |
| |
n | Print a comparison between *a* and *b* and common immediate subdirectories. |
n | Print a comparison between *a* and *b* and common immediate |
| subdirectories. |
| |
| |
n | .. method:: dircmp.report_full_closure() |
n | .. method:: report_full_closure() |
| |
n | Print a comparison between *a* and *b* and common subdirectories (recursively). |
n | Print a comparison between *a* and *b* and common subdirectories |
| (recursively). |
| |
n | The :class:`dircmp` offers a number of interesting attributes that may be used |
n | The :class:`dircmp` offers a number of interesting attributes that may be |
| to get various bits of information about the directory trees being compared. |
| used to get various bits of information about the directory trees being |
| compared. |
| |
n | Note that via :meth:`__getattr__` hooks, all attributes are computed lazily, so |
n | Note that via :meth:`__getattr__` hooks, all attributes are computed lazily, |
| there is no speed penalty if only those attributes which are lightweight to |
| so there is no speed penalty if only those attributes which are lightweight |
| compute are used. |
| to compute are used. |
| |
| |
n | .. attribute:: dircmp.left_list |
n | .. attribute:: left_list |
| |
n | Files and subdirectories in *a*, filtered by *hide* and *ignore*. |
n | Files and subdirectories in *a*, filtered by *hide* and *ignore*. |
| |
| |
n | .. attribute:: dircmp.right_list |
n | .. attribute:: right_list |
| |
n | Files and subdirectories in *b*, filtered by *hide* and *ignore*. |
n | Files and subdirectories in *b*, filtered by *hide* and *ignore*. |
| |
| |
n | .. attribute:: dircmp.common |
n | .. attribute:: common |
| |
n | Files and subdirectories in both *a* and *b*. |
n | Files and subdirectories in both *a* and *b*. |
| |
| |
n | .. attribute:: dircmp.left_only |
n | .. attribute:: left_only |
| |
n | Files and subdirectories only in *a*. |
n | Files and subdirectories only in *a*. |
| |
| |
n | .. attribute:: dircmp.right_only |
n | .. attribute:: right_only |
| |
n | Files and subdirectories only in *b*. |
n | Files and subdirectories only in *b*. |
| |
| |
n | .. attribute:: dircmp.common_dirs |
n | .. attribute:: common_dirs |
| |
n | Subdirectories in both *a* and *b*. |
n | Subdirectories in both *a* and *b*. |
| |
| |
n | .. attribute:: dircmp.common_files |
n | .. attribute:: common_files |
| |
n | Files in both *a* and *b* |
n | Files in both *a* and *b* |
| |
| |
n | .. attribute:: dircmp.common_funny |
n | .. attribute:: common_funny |
| |
n | Names in both *a* and *b*, such that the type differs between the directories, |
n | Names in both *a* and *b*, such that the type differs between the |
| or names for which :func:`os.stat` reports an error. |
| directories, or names for which :func:`os.stat` reports an error. |
| |
| |
n | .. attribute:: dircmp.same_files |
n | .. attribute:: same_files |
| |
n | Files which are identical in both *a* and *b*. |
n | Files which are identical in both *a* and *b*. |
| |
| |
n | .. attribute:: dircmp.diff_files |
n | .. attribute:: diff_files |
| |
n | Files which are in both *a* and *b*, whose contents differ. |
n | Files which are in both *a* and *b*, whose contents differ. |
| |
| |
n | .. attribute:: dircmp.funny_files |
n | .. attribute:: funny_files |
| |
n | Files which are in both *a* and *b*, but could not be compared. |
n | Files which are in both *a* and *b*, but could not be compared. |
| |
| |
n | .. attribute:: dircmp.subdirs |
n | .. attribute:: subdirs |
| |
t | A dictionary mapping names in :attr:`common_dirs` to :class:`dircmp` objects. |
t | A dictionary mapping names in :attr:`common_dirs` to :class:`dircmp` objects. |
| |