[Python-checkins] distutils2: manifest.read_template now accepts file objects
tarek.ziade
python-checkins at python.org
Sun Oct 17 22:12:18 CEST 2010
tarek.ziade pushed f882ae3f2895 to distutils2:
http://hg.python.org/distutils2/rev/f882ae3f2895
changeset: 771:f882ae3f2895
tag: tip
user: Tarek Ziade <tarek at ziade.org>
date: Sun Oct 17 22:11:49 2010 +0200
summary: manifest.read_template now accepts file objects
files: distutils2/manifest.py, distutils2/tests/test_manifest.py
diff --git a/distutils2/manifest.py b/distutils2/manifest.py
--- a/distutils2/manifest.py
+++ b/distutils2/manifest.py
@@ -66,12 +66,17 @@
if self.files[i] == self.files[i - 1]:
del self.files[i]
- def read_template(self, path):
+ def read_template(self, path_or_file):
"""Read and parse a manifest template file.
+ 'path' can be a path or a file-like object.
Updates the list accordingly.
"""
- f = open(path)
+ if isinstance(path_or_file, str):
+ f = open(path_or_file)
+ else:
+ f = path_or_file
+
try:
content = f.read()
# first, let's unwrap collapsed lines
@@ -89,7 +94,7 @@
try:
self._process_template_line(line)
except DistutilsTemplateError, msg:
- logging.warning("%s, %s" % (path, msg))
+ logging.warning("%s, %s" % (path_or_file, msg))
def write(self, path):
"""Write the file list in 'self.filelist' (presumably as filled in
diff --git a/distutils2/tests/test_manifest.py b/distutils2/tests/test_manifest.py
--- a/distutils2/tests/test_manifest.py
+++ b/distutils2/tests/test_manifest.py
@@ -48,6 +48,17 @@
for warn in warns:
self.assertIn('warning: no files found matching', warn)
+ # manifest also accepts file-like objects
+ old_warn = logging.warning
+ logging.warning = _warn
+ try:
+ manifest.read_template(open(MANIFEST))
+ finally:
+ logging.warning = old_warn
+
+ # the manifest should have been read
+ # and 3 warnings issued (we ddidn't provided the files)
+ self.assertEqual(len(warns), 6)
def test_suite():
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list