[svn] Add interactive option to list recursive archives when found. trunk

Sun, 20 Jan 2008 12:00:35 -0500

author
brett
date
Sun, 20 Jan 2008 12:00:35 -0500
branch
trunk
changeset 53
cd853ddb224c
parent 52
cf191f957fd0
child 54
cd43d2f61162

[svn] Add interactive option to list recursive archives when found.

I'm not really wild about how this is built but since it's a one-off I'm
not sure what a better infrastructure would look like yet.

Also add a test for a -fv combo while I was in there.

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	Sun Jan 20 11:10:48 2008 -0500
+++ b/scripts/dtrx	Sun Jan 20 12:00:35 2008 -0500
@@ -62,6 +62,7 @@
 RECURSE_ONCE = 2
 RECURSE_NOT_NOW = 3
 RECURSE_NEVER = 4
+RECURSE_LIST = 5
 
 mimetypes.encodings_map.setdefault('.bz2', 'bzip2')
 mimetypes.encodings_map.setdefault('.lzma', 'lzma')
@@ -560,7 +561,7 @@
             os.rmdir(self.extractor.target)
         else:
             os.rename(self.extractor.target, self.target)
-        self.extractor.included_root = '.'
+        self.extractor.included_root = './'
 
 
 class EmptyHandler(object):
@@ -629,13 +630,14 @@
 
 class RecursionPolicy(BasePolicy):
     answers = {'o': RECURSE_ONCE, 'a': RECURSE_ALWAYS, 'n': RECURSE_NOT_NOW,
-               'v': RECURSE_NEVER, '': RECURSE_NOT_NOW}
+               'v': RECURSE_NEVER, 'l': RECURSE_LIST, '': RECURSE_NOT_NOW}
     choices = ["You can:",
                " * Always extract included archives",
                " * extract included archives this Once",
                " * choose Not to extract included archives",
-               " * neVer extract included archives"]
-    prompt = "What do you want to do?  (a/o/N/v) "
+               " * neVer extract included archives",
+               " * List included archives"]
+    prompt = "What do you want to do?  (a/o/N/v/l) "
 
     def __init__(self, options):
         BasePolicy.__init__(self, options)
@@ -644,8 +646,8 @@
         elif options.recursive:
             self.permanent_policy = RECURSE_ALWAYS
 
-    def prep(self, current_filename, included_archives):
-        archive_count = len(included_archives)
+    def prep(self, current_filename, target, extractor):
+        archive_count = len(extractor.included_archives)
         if (self.permanent_policy is not None) or (archive_count == 0):
             self.current_policy = self.permanent_policy or RECURSE_NOT_NOW
             return
@@ -654,8 +656,19 @@
                         (current_filename, archive_count))
         else:
             question = ("%s contains another archive: %s." %
-                        (current_filename, included_archives[0]))
-        self.current_policy = self.ask_question(question)
+                        (current_filename, extractor.included_archives[0]))
+        if target == '.':
+            target = ''
+        included_root = extractor.included_root
+        if included_root == './':
+            included_root = ''
+        while True:
+            self.current_policy = self.ask_question(question)
+            if self.current_policy != RECURSE_LIST:
+                break
+            print ("\n%s\n" %
+                   '\n'.join([os.path.join(target, included_root, filename)
+                              for filename in extractor.included_archives]))
         if self.current_policy in (RECURSE_ALWAYS, RECURSE_NEVER):
             self.permanent_policy = self.current_policy
 
@@ -975,10 +988,9 @@
         logger.debug("logger is set up")
 
     def recurse(self, filename, extractor, action):
-        archives = extractor.included_archives
-        self.options.recursion_policy.prep(filename, archives)
+        self.options.recursion_policy.prep(filename, action.target, extractor)
         if self.options.recursion_policy.ok_to_recurse():
-            for filename in archives:
+            for filename in extractor.included_archives:
                 tail_path, basename = os.path.split(filename)
                 directory = os.path.join(self.current_directory, action.target,
                                          extractor.included_root, tail_path)
--- a/tests/compare.py	Sun Jan 20 11:10:48 2008 -0500
+++ b/tests/compare.py	Sun Jan 20 12:00:35 2008 -0500
@@ -165,9 +165,9 @@
         return None
 
     def grep_output(self, output):
-        if self.grep and (not re.search(self.grep, output)):
+        if self.grep and (not re.search(self.grep, output, re.MULTILINE)):
             return "output did not match %s" % (self.grep)
-        elif self.antigrep and re.search(self.antigrep, output):
+        elif self.antigrep and re.search(self.antigrep, output, re.MULTILINE):
             return "output matched antigrep %s" % (self.antigrep)
         return None
 
--- a/tests/tests.yml	Sun Jan 20 11:10:48 2008 -0500
+++ b/tests/tests.yml	Sun Jan 20 12:00:35 2008 -0500
@@ -554,3 +554,22 @@
     
     test-text.gz:
     test-text
+
+- name: output filenames with -v and -f
+  options: -nvf
+  directory: busydir
+  filenames: ../test-onedir.tar.gz
+  output: |
+    ../test-onedir.tar.gz:
+    test/
+    test/foobar
+    test/quux
+
+- name: list recursive archives
+  options: ""
+  filenames: test-deep-recursion.tar
+  input: |
+    r
+    l
+    n
+  grep: "^test-deep-recursion/subsubdir/test-text\.gz$"

mercurial