1999-10-29 19:23:15 +02:00
|
|
|
\section{\module{filecmp} ---
|
2000-07-03 10:24:49 +02:00
|
|
|
File and Directory Comparisons}
|
1999-10-29 19:23:15 +02:00
|
|
|
|
|
|
|
\declaremodule{standard}{filecmp}
|
2000-12-01 16:25:23 +01:00
|
|
|
\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
|
1999-10-29 19:23:15 +02:00
|
|
|
\modulesynopsis{Compare files efficiently.}
|
|
|
|
|
2000-07-03 10:24:49 +02:00
|
|
|
|
2001-05-11 19:01:32 +02:00
|
|
|
The \module{filecmp} module defines functions to compare files and
|
|
|
|
directories, with various optional time/correctness trade-offs.
|
1999-10-29 19:23:15 +02:00
|
|
|
|
2001-05-11 19:01:32 +02:00
|
|
|
The \module{filecmp} module defines the following functions:
|
1999-10-29 19:23:15 +02:00
|
|
|
|
|
|
|
\begin{funcdesc}{cmp}{f1, f2\optional{, shallow\optional{, use_statcache}}}
|
2000-07-03 10:24:49 +02:00
|
|
|
Compare the files named \var{f1} and \var{f2}, returning \code{1} if
|
|
|
|
they seem equal, \code{0} otherwise.
|
1999-10-29 19:23:15 +02:00
|
|
|
|
|
|
|
Unless \var{shallow} is given and is false, files with identical
|
2000-07-03 10:24:49 +02:00
|
|
|
\function{os.stat()} signatures are taken to be equal. If
|
1999-10-29 19:23:15 +02:00
|
|
|
\var{use_statcache} is given and is true,
|
2000-07-03 10:24:49 +02:00
|
|
|
\function{statcache.stat()} will be called rather then
|
|
|
|
\function{os.stat()}; the default is to use \function{os.stat()}.
|
1999-10-29 19:23:15 +02:00
|
|
|
|
|
|
|
Files that were compared using this function will not be compared again
|
|
|
|
unless their \function{os.stat()} signature changes. Note that using
|
|
|
|
\var{use_statcache} true will cause the cache invalidation mechanism to
|
|
|
|
fail --- the stale stat value will be used from \refmodule{statcache}'s
|
|
|
|
cache.
|
|
|
|
|
2000-07-03 10:24:49 +02:00
|
|
|
Note that no external programs are called from this function, giving it
|
1999-10-29 19:23:15 +02:00
|
|
|
portability and efficiency.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
2000-07-03 10:24:49 +02:00
|
|
|
\begin{funcdesc}{cmpfiles}{dir1, dir2, common\optional{,
|
|
|
|
shallow\optional{, use_statcache}}}
|
|
|
|
Returns three lists of file names: \var{match}, \var{mismatch},
|
|
|
|
\var{errors}. \var{match} contains the list of files match in both
|
|
|
|
directories, \var{mismatch} includes the names of those that don't,
|
|
|
|
and \var{errros} lists the names of files which could not be
|
|
|
|
compared. Files may be listed in \var{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.
|
|
|
|
|
|
|
|
The \var{shallow} and \var{use_statcache} parameters have the same
|
|
|
|
meanings and default values as for \function{filecmp.cmp()}.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
1999-10-29 19:23:15 +02:00
|
|
|
Example:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
>>> import filecmp
|
|
|
|
>>> filecmp.cmp('libundoc.tex', 'libundoc.tex')
|
|
|
|
1
|
|
|
|
>>> filecmp.cmp('libundoc.tex', 'lib.tex')
|
|
|
|
0
|
|
|
|
\end{verbatim}
|
2000-07-03 10:24:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
\subsection{The \protect\class{dircmp} class \label{dircmp-objects}}
|
|
|
|
|
2001-05-11 19:01:32 +02:00
|
|
|
\class{dircmp} instances are built using this constructor:
|
|
|
|
|
2000-07-03 10:24:49 +02:00
|
|
|
\begin{classdesc}{dircmp}{a, b\optional{, ignore\optional{, hide}}}
|
|
|
|
Construct a new directory comparison object, to compare the
|
|
|
|
directories \var{a} and \var{b}. \var{ignore} is a list of names to
|
|
|
|
ignore, and defaults to \code{['RCS', 'CVS', 'tags']}. \var{hide} is a
|
2001-01-18 11:44:08 +01:00
|
|
|
list of names to hide, and defaults to \code{[os.curdir, os.pardir]}.
|
2000-07-03 10:24:49 +02:00
|
|
|
\end{classdesc}
|
|
|
|
|
2001-05-11 19:01:32 +02:00
|
|
|
The \class{dircmp} class provides the following methods:
|
|
|
|
|
2000-07-03 10:24:49 +02:00
|
|
|
\begin{methoddesc}[dircmp]{report}{}
|
|
|
|
Print (to \code{sys.stdout}) a comparison between \var{a} and \var{b}.
|
|
|
|
\end{methoddesc}
|
|
|
|
|
|
|
|
\begin{methoddesc}[dircmp]{report_partial_closure}{}
|
|
|
|
Print a comparison between \var{a} and \var{b} and common immediate
|
|
|
|
subdirctories.
|
|
|
|
\end{methoddesc}
|
|
|
|
|
|
|
|
\begin{methoddesc}[dircmp]{report_full_closure}{}
|
|
|
|
Print a comparison between \var{a} and \var{b} and common
|
|
|
|
subdirctories (recursively).
|
|
|
|
\end{methoddesc}
|
|
|
|
|
2001-05-11 19:01:32 +02:00
|
|
|
|
|
|
|
The \class{dircmp} offers a number of interesting attributes that may
|
|
|
|
be used to get various bits of information about the directory trees
|
|
|
|
being compared.
|
|
|
|
|
|
|
|
Note that via \method{__getattr__()} hooks, all attributes are
|
|
|
|
computed lazilly, so there is no speed penalty if only those
|
|
|
|
attributes which are lightweight to compute are used.
|
|
|
|
|
2000-07-03 10:24:49 +02:00
|
|
|
\begin{memberdesc}[dircmp]{left_list}
|
|
|
|
Files and subdirectories in \var{a}, filtered by \var{hide} and
|
|
|
|
\var{ignore}.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{right_list}
|
|
|
|
Files and subdirectories in \var{b}, filtered by \var{hide} and
|
|
|
|
\var{ignore}.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{common}
|
|
|
|
Files and subdirectories in both \var{a} and \var{b}.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{left_only}
|
|
|
|
Files and subdirectories only in \var{a}.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{right_only}
|
|
|
|
Files and subdirectories only in \var{b}.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{common_dirs}
|
|
|
|
Subdirectories in both \var{a} and \var{b}.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{common_files}
|
|
|
|
Files in both \var{a} and \var{b}
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{common_funny}
|
|
|
|
Names in both \var{a} and \var{b}, such that the type differs between
|
|
|
|
the directories, or names for which \function{os.stat()} reports an
|
|
|
|
error.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{same_files}
|
|
|
|
Files which are identical in both \var{a} and \var{b}.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{diff_files}
|
|
|
|
Files which are in both \var{a} and \var{b}, whose contents differ.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{funny_files}
|
|
|
|
Files which are in both \var{a} and \var{b}, but could not be
|
|
|
|
compared.
|
|
|
|
\end{memberdesc}
|
|
|
|
|
|
|
|
\begin{memberdesc}[dircmp]{subdirs}
|
|
|
|
A dictionary mapping names in \member{common_dirs} to
|
|
|
|
\class{dircmp} objects.
|
|
|
|
\end{memberdesc}
|