diff options
| author | Tarek Ziade <tarek@ziade.org> | 2010-10-17 22:11:49 +0200 |
|---|---|---|
| committer | Tarek Ziade <tarek@ziade.org> | 2010-10-17 22:11:49 +0200 |
| commit | 8d49dfea0cbc013da87ca760f5c7542de7aa43e0 (patch) | |
| tree | fc939a5f80bb0371f1a52e62c40f2e824476d926 /distutils2 | |
| parent | 6cbe6383303fb03e89e399b2c68289779cdd75be (diff) | |
| download | disutils2-8d49dfea0cbc013da87ca760f5c7542de7aa43e0.tar.gz | |
manifest.read_template now accepts file objects
Diffstat (limited to 'distutils2')
| -rw-r--r-- | distutils2/manifest.py | 11 | ||||
| -rw-r--r-- | distutils2/tests/test_manifest.py | 11 |
2 files changed, 19 insertions, 3 deletions
diff --git a/distutils2/manifest.py b/distutils2/manifest.py index 27b3dce..6d4694a 100644 --- a/distutils2/manifest.py +++ b/distutils2/manifest.py @@ -66,12 +66,17 @@ class Manifest(object): 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 @@ class Manifest(object): 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 index bb8c96c..dcf570f 100644 --- a/distutils2/tests/test_manifest.py +++ b/distutils2/tests/test_manifest.py @@ -48,6 +48,17 @@ class ManifestTestCase(support.TempdirManager, 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(): |
