Author: guido.van.rossum
Date: Sat Jun 30 03:04:31 2007
New Revision: 56124

Modified:
   python/branches/p3yk/   (props changed)
   python/branches/p3yk/Doc/lib/libshlex.tex
   python/branches/p3yk/Doc/lib/libshutil.tex
   python/branches/p3yk/Doc/lib/libtarfile.tex
   python/branches/p3yk/Doc/lib/libwinreg.tex
   python/branches/p3yk/Lib/logging/__init__.py
   python/branches/p3yk/Lib/tarfile.py
   python/branches/p3yk/Lib/test/test_tarfile.py
Log:
Merged revisions 56014-56123 via svnmerge from 
svn+ssh://[EMAIL PROTECTED]/python/trunk

........
  r56019 | lars.gustaebel | 2007-06-18 04:42:11 -0700 (Mon, 18 Jun 2007) | 2 
lines
  
  Added exclude keyword argument to the TarFile.add() method.
........
  r56023 | lars.gustaebel | 2007-06-18 13:05:55 -0700 (Mon, 18 Jun 2007) | 3 
lines
  
  Added missing \versionchanged tag for the new exclude
  parameter.
........
  r56038 | georg.brandl | 2007-06-19 05:36:00 -0700 (Tue, 19 Jun 2007) | 2 lines
  
  Bug #1737864: allow empty message in logging format routines.
........
  r56040 | georg.brandl | 2007-06-19 05:38:20 -0700 (Tue, 19 Jun 2007) | 2 lines
  
  Bug #1739115: make shutil.rmtree docs clear wrt. file deletion.
........
  r56084 | georg.brandl | 2007-06-25 08:21:23 -0700 (Mon, 25 Jun 2007) | 2 lines
  
  Bug #1742901: document None behavior of shlex.split.
........
  r56091 | georg.brandl | 2007-06-27 07:09:56 -0700 (Wed, 27 Jun 2007) | 2 lines
  
  Fix a variable name in winreg docs.
........


Modified: python/branches/p3yk/Doc/lib/libshlex.tex
==============================================================================
--- python/branches/p3yk/Doc/lib/libshlex.tex   (original)
+++ python/branches/p3yk/Doc/lib/libshlex.tex   Sat Jun 30 03:04:31 2007
@@ -28,6 +28,9 @@
 \var{posix} argument is false.
 \versionadded{2.3}
 \versionchanged[Added the \var{posix} parameter]{2.6}
+\note{Since the \function{split()} function instantiates a \class{shlex}
+      instance, passing \code{None} for \var{s} will read the string
+      to split from standard input.}
 \end{funcdesc}
 
 The \module{shlex} module defines the following class:

Modified: python/branches/p3yk/Doc/lib/libshutil.tex
==============================================================================
--- python/branches/p3yk/Doc/lib/libshutil.tex  (original)
+++ python/branches/p3yk/Doc/lib/libshutil.tex  Sat Jun 30 03:04:31 2007
@@ -91,11 +91,12 @@
 \end{funcdesc}
 
 \begin{funcdesc}{rmtree}{path\optional{, ignore_errors\optional{, onerror}}}
-  Delete an entire directory tree.\index{directory!deleting}
-  If \var{ignore_errors} is true,
-  errors resulting from failed removals will be ignored; if false or
-  omitted, such errors are handled by calling a handler specified by
-  \var{onerror} or, if that is omitted, they raise an exception.
+  \index{directory!deleting}
+  Delete an entire directory tree (\var{path} must point to a directory).
+  If \var{ignore_errors} is true, errors resulting from failed removals
+  will be ignored; if false or omitted, such errors are handled by
+  calling a handler specified by \var{onerror} or, if that is omitted,
+  they raise an exception.
 
   If \var{onerror} is provided, it must be a callable that accepts
   three parameters: \var{function}, \var{path}, and \var{excinfo}.

Modified: python/branches/p3yk/Doc/lib/libtarfile.tex
==============================================================================
--- python/branches/p3yk/Doc/lib/libtarfile.tex (original)
+++ python/branches/p3yk/Doc/lib/libtarfile.tex Sat Jun 30 03:04:31 2007
@@ -314,13 +314,17 @@
     \end{notice}
 \end{methoddesc}
 
-\begin{methoddesc}{add}{name\optional{, arcname\optional{, recursive}}}
+\begin{methoddesc}{add}{name\optional{, arcname\optional{, 
recursive\optional{, exclude}}}}
     Add the file \var{name} to the archive. \var{name} may be any type
     of file (directory, fifo, symbolic link, etc.).
     If given, \var{arcname} specifies an alternative name for the file in the
     archive. Directories are added recursively by default.
-    This can be avoided by setting \var{recursive} to \constant{False};
-    the default is \constant{True}.
+    This can be avoided by setting \var{recursive} to \constant{False}.
+    If \var{exclude} is given it must be a function that takes one filename
+    argument and returns a boolean value. Depending on this value the
+    respective file is either excluded (\constant{True}) or added
+    (\constant{False}).
+    \versionchanged[Added the \var{exclude} parameter]{2.6}
 \end{methoddesc}
 
 \begin{methoddesc}{addfile}{tarinfo\optional{, fileobj}}

Modified: python/branches/p3yk/Doc/lib/libwinreg.tex
==============================================================================
--- python/branches/p3yk/Doc/lib/libwinreg.tex  (original)
+++ python/branches/p3yk/Doc/lib/libwinreg.tex  Sat Jun 30 03:04:31 2007
@@ -321,7 +321,7 @@
  \var{key} is an already open key, or one of the predefined 
  \constant{HKEY_*} constants.
 
- \var{sub_key} is a string that names the subkey with which the 
+ \var{value_name} is a string that names the subkey with which the 
  value is associated.
 
  \var{type} is an integer that specifies the type of the data.  

Modified: python/branches/p3yk/Lib/logging/__init__.py
==============================================================================
--- python/branches/p3yk/Lib/logging/__init__.py        (original)
+++ python/branches/p3yk/Lib/logging/__init__.py        Sat Jun 30 03:04:31 2007
@@ -400,7 +400,7 @@
         traceback.print_exception(ei[0], ei[1], ei[2], None, sio)
         s = sio.getvalue()
         sio.close()
-        if s[-1] == "\n":
+        if s[-1:] == "\n":
             s = s[:-1]
         return s
 
@@ -427,7 +427,7 @@
             if not record.exc_text:
                 record.exc_text = self.formatException(record.exc_info)
         if record.exc_text:
-            if s[-1] != "\n":
+            if s[-1:] != "\n":
                 s = s + "\n"
             s = s + record.exc_text
         return s

Modified: python/branches/p3yk/Lib/tarfile.py
==============================================================================
--- python/branches/p3yk/Lib/tarfile.py (original)
+++ python/branches/p3yk/Lib/tarfile.py Sat Jun 30 03:04:31 2007
@@ -1925,18 +1925,24 @@
                     print("link to", tarinfo.linkname, end=' ')
             print()
 
-    def add(self, name, arcname=None, recursive=True):
+    def add(self, name, arcname=None, recursive=True, exclude=None):
         """Add the file `name' to the archive. `name' may be any type of file
            (directory, fifo, symbolic link, etc.). If given, `arcname'
            specifies an alternative name for the file in the archive.
            Directories are added recursively by default. This can be avoided by
-           setting `recursive' to False.
+           setting `recursive' to False. `exclude' is a function that should
+           return True for each filename to be excluded.
         """
         self._check("aw")
 
         if arcname is None:
             arcname = name
 
+        # Exclude pathnames.
+        if exclude is not None and exclude(name):
+            self._dbg(2, "tarfile: Excluded %r" % name)
+            return
+
         # Skip if somebody tries to archive the archive...
         if self.name is not None and os.path.abspath(name) == self.name:
             self._dbg(2, "tarfile: Skipped %r" % name)
@@ -1949,7 +1955,7 @@
                 if arcname == ".":
                     arcname = ""
                 for f in os.listdir(name):
-                    self.add(f, os.path.join(arcname, f))
+                    self.add(f, os.path.join(arcname, f), recursive, exclude)
             return
 
         self._dbg(1, name)
@@ -1971,7 +1977,7 @@
             self.addfile(tarinfo)
             if recursive:
                 for f in os.listdir(name):
-                    self.add(os.path.join(name, f), os.path.join(arcname, f))
+                    self.add(os.path.join(name, f), os.path.join(arcname, f), 
recursive, exclude)
 
         else:
             self.addfile(tarinfo)

Modified: python/branches/p3yk/Lib/test/test_tarfile.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_tarfile.py       (original)
+++ python/branches/p3yk/Lib/test/test_tarfile.py       Sat Jun 30 03:04:31 2007
@@ -558,6 +558,27 @@
         os.chdir(cwd)
         self.assert_(tar.getnames() == [], "added the archive to itself")
 
+    def test_exclude(self):
+        tempdir = os.path.join(TEMPDIR, "exclude")
+        os.mkdir(tempdir)
+        try:
+            for name in ("foo", "bar", "baz"):
+                name = os.path.join(tempdir, name)
+                open(name, "wb").close()
+
+            def exclude(name):
+                return os.path.isfile(name)
+
+            tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
+            tar.add(tempdir, arcname="empty_dir", exclude=exclude)
+            tar.close()
+
+            tar = tarfile.open(tmpname, "r")
+            self.assertEqual(len(tar.getmembers()), 1)
+            self.assertEqual(tar.getnames()[0], "empty_dir")
+        finally:
+            shutil.rmtree(tempdir)
+
 
 class StreamWriteTest(unittest.TestCase):
 
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to