source: vendor/python/2.5/Doc/lib/libfilecmp.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 4.5 KB
Line 
1\section{\module{filecmp} ---
2 File and Directory Comparisons}
3
4\declaremodule{standard}{filecmp}
5\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
6\modulesynopsis{Compare files efficiently.}
7
8
9The \module{filecmp} module defines functions to compare files and
10directories, with various optional time/correctness trade-offs.
11
12The \module{filecmp} module defines the following functions:
13
14\begin{funcdesc}{cmp}{f1, f2\optional{, shallow}}
15Compare the files named \var{f1} and \var{f2}, returning \code{True} if
16they seem equal, \code{False} otherwise.
17
18Unless \var{shallow} is given and is false, files with identical
19\function{os.stat()} signatures are taken to be equal.
20
21Files that were compared using this function will not be compared again
22unless their \function{os.stat()} signature changes.
23
24Note that no external programs are called from this function, giving it
25portability and efficiency.
26\end{funcdesc}
27
28\begin{funcdesc}{cmpfiles}{dir1, dir2, common\optional{,
29 shallow}}
30Returns three lists of file names: \var{match}, \var{mismatch},
31\var{errors}. \var{match} contains the list of files match in both
32directories, \var{mismatch} includes the names of those that don't,
33and \var{errros} lists the names of files which could not be
34compared. Files may be listed in \var{errors} because the user may
35lack permission to read them or many other reasons, but always that
36the comparison could not be done for some reason.
37
38The \var{common} parameter is a list of file names found in both directories.
39The \var{shallow} parameter has the same
40meaning and default value as for \function{filecmp.cmp()}.
41\end{funcdesc}
42
43Example:
44
45\begin{verbatim}
46>>> import filecmp
47>>> filecmp.cmp('libundoc.tex', 'libundoc.tex')
48True
49>>> filecmp.cmp('libundoc.tex', 'lib.tex')
50False
51\end{verbatim}
52
53
54\subsection{The \protect\class{dircmp} class \label{dircmp-objects}}
55
56\class{dircmp} instances are built using this constructor:
57
58\begin{classdesc}{dircmp}{a, b\optional{, ignore\optional{, hide}}}
59Construct a new directory comparison object, to compare the
60directories \var{a} and \var{b}. \var{ignore} is a list of names to
61ignore, and defaults to \code{['RCS', 'CVS', 'tags']}. \var{hide} is a
62list of names to hide, and defaults to \code{[os.curdir, os.pardir]}.
63\end{classdesc}
64
65The \class{dircmp} class provides the following methods:
66
67\begin{methoddesc}[dircmp]{report}{}
68Print (to \code{sys.stdout}) a comparison between \var{a} and \var{b}.
69\end{methoddesc}
70
71\begin{methoddesc}[dircmp]{report_partial_closure}{}
72Print a comparison between \var{a} and \var{b} and common immediate
73subdirectories.
74\end{methoddesc}
75
76\begin{methoddesc}[dircmp]{report_full_closure}{}
77Print a comparison between \var{a} and \var{b} and common
78subdirectories (recursively).
79\end{methoddesc}
80
81
82The \class{dircmp} offers a number of interesting attributes that may
83be used to get various bits of information about the directory trees
84being compared.
85
86Note that via \method{__getattr__()} hooks, all attributes are
87computed lazily, so there is no speed penalty if only those
88attributes which are lightweight to compute are used.
89
90\begin{memberdesc}[dircmp]{left_list}
91Files and subdirectories in \var{a}, filtered by \var{hide} and
92\var{ignore}.
93\end{memberdesc}
94
95\begin{memberdesc}[dircmp]{right_list}
96Files and subdirectories in \var{b}, filtered by \var{hide} and
97\var{ignore}.
98\end{memberdesc}
99
100\begin{memberdesc}[dircmp]{common}
101Files and subdirectories in both \var{a} and \var{b}.
102\end{memberdesc}
103
104\begin{memberdesc}[dircmp]{left_only}
105Files and subdirectories only in \var{a}.
106\end{memberdesc}
107
108\begin{memberdesc}[dircmp]{right_only}
109Files and subdirectories only in \var{b}.
110\end{memberdesc}
111
112\begin{memberdesc}[dircmp]{common_dirs}
113Subdirectories in both \var{a} and \var{b}.
114\end{memberdesc}
115
116\begin{memberdesc}[dircmp]{common_files}
117Files in both \var{a} and \var{b}
118\end{memberdesc}
119
120\begin{memberdesc}[dircmp]{common_funny}
121Names in both \var{a} and \var{b}, such that the type differs between
122the directories, or names for which \function{os.stat()} reports an
123error.
124\end{memberdesc}
125
126\begin{memberdesc}[dircmp]{same_files}
127Files which are identical in both \var{a} and \var{b}.
128\end{memberdesc}
129
130\begin{memberdesc}[dircmp]{diff_files}
131Files which are in both \var{a} and \var{b}, whose contents differ.
132\end{memberdesc}
133
134\begin{memberdesc}[dircmp]{funny_files}
135Files which are in both \var{a} and \var{b}, but could not be
136compared.
137\end{memberdesc}
138
139\begin{memberdesc}[dircmp]{subdirs}
140A dictionary mapping names in \member{common_dirs} to
141\class{dircmp} objects.
142\end{memberdesc}
Note: See TracBrowser for help on using the repository browser.