Count files in the archive and report that in the recursion prompt. trunk

Thu, 10 Jul 2008 19:51:53 -0400

author
Brett Smith <brett@brettcsmith.org>
date
Thu, 10 Jul 2008 19:51:53 -0400
branch
trunk
changeset 69
35a2f45cdd3b
parent 68
d0a8ee8473ca
child 70
48d2421a3178

Count files in the archive and report that in the recursion prompt.

I like this because, for example, if you see that all or most of the files
in the archive are recursive, you can go ahead and decide to recurse right
away.

This invoved making the grep tests a little smarter about handling white
space.

scripts/dtrx file | annotate | diff | comparison | revisions
tests/compare.py file | annotate | diff | comparison | revisions
tests/tests.yml file | annotate | diff | comparison | revisions
--- a/scripts/dtrx	Thu Jul 10 19:31:23 2008 -0400
+++ b/scripts/dtrx	Thu Jul 10 19:51:53 2008 -0400
@@ -136,6 +136,7 @@
             raise ValueError("unrecognized encoding %s" % (encoding,))
         self.filename = os.path.realpath(filename)
         self.encoding = encoding
+        self.file_count = 0
         self.included_archives = []
         self.target = None
         self.content_type = None
@@ -203,6 +204,7 @@
             self.included_root = self.content_name
         start_index = len(self.included_root)
         for path, dirname, filenames in os.walk(self.included_root):
+            self.file_count += len(filenames)
             path = path[start_index:]
             for filename in filenames:
                 if (ExtractorBuilder.try_by_mimetype(filename) or
@@ -683,12 +685,9 @@
         if (self.permanent_policy is not None) or (archive_count == 0):
             self.current_policy = self.permanent_policy or RECURSE_NOT_NOW
             return
-        elif archive_count > 1:
-            question = ("%s contains %s other archive files." %
-                        (current_filename, archive_count))
-        else:
-            question = ("%s contains another archive: %s." %
-                        (current_filename, extractor.included_archives[0]))
+        question = (("%s contains %s other archive file(s), " +
+                     "out of %s files total.") %
+                    (current_filename, archive_count, extractor.file_count))
         question = textwrap.wrap(question)
         if target == '.':
             target = ''
--- a/tests/compare.py	Thu Jul 10 19:31:23 2008 -0400
+++ b/tests/compare.py	Thu Jul 10 19:51:53 2008 -0400
@@ -165,9 +165,11 @@
         return None
 
     def grep_output(self, output):
-        if self.grep and (not re.search(self.grep, output, re.MULTILINE)):
+        if self.grep and (not re.search(self.grep.replace(' ', '\\s+'),
+                                        output, re.MULTILINE)):
             return "output did not match %s" % (self.grep)
-        elif self.antigrep and re.search(self.antigrep, output, re.MULTILINE):
+        elif self.antigrep and re.search(self.antigrep.replace(' ', '\\s+'),
+                                         output, re.MULTILINE):
             return "output matched antigrep %s" % (self.antigrep)
         return None
 
--- a/tests/tests.yml	Thu Jul 10 19:31:23 2008 -0400
+++ b/tests/tests.yml	Thu Jul 10 19:51:53 2008 -0400
@@ -415,7 +415,7 @@
   input: |
     h
     o
-  grep: "contains 2"
+  grep: "contains 2 other archive file\(s\), out of 2 files"
   baseline: |
     tar -xf $1
     cd subdir

mercurial