scripts/dtrx

branch
trunk
changeset 99
1ae3722ca219
parent 98
6b7860fca221
child 100
7353b443dc98
--- a/scripts/dtrx	Thu Nov 06 20:49:57 2008 -0500
+++ b/scripts/dtrx	Thu Nov 06 21:33:15 2008 -0500
@@ -658,6 +658,12 @@
 
         
 class BasePolicy(object):
+    try:
+        width = int(os.environ['COLUMNS'])
+    except (KeyError, ValueError):
+        width = 80
+    wrapper = textwrap.TextWrapper(width=width - 1)
+
     def __init__(self, options):
         self.current_policy = None
         if options.batch:
@@ -665,6 +671,13 @@
         else:
             self.permanent_policy = None
 
+    def wrap(self, question, filename):
+        # Note: This function assumes the filename is the first thing in the
+        # question text, and that's the only place it appears.
+        if len(self.wrapper.wrap(filename + ' a')) > 1:
+            return [filename] + self.wrapper.wrap(question[3:])
+        return self.wrapper.wrap(question % (filename,))
+
     def ask_question(self, question):
         question = question + self.choices
         while True:
@@ -709,8 +722,9 @@
             raise ValueError("bad value %s for default policy" % (default,))
 
     def prep(self, archive_filename, extractor):
-        question = ["%s contains one %s, but it has a weird name." %
-                    (archive_filename, extractor.content_type)]
+        question = self.wrap(("%%s contains one %s, but its name " +
+                              "doesn't match.") %
+                             (extractor.content_type,), archive_filename)
         question.append(" Expected: " + extractor.basename())
         question.append("   Actual: " + extractor.content_name)
         self.current_policy = (self.permanent_policy or
@@ -743,10 +757,10 @@
         if (self.permanent_policy is not None) or (archive_count == 0):
             self.current_policy = self.permanent_policy or RECURSE_NOT_NOW
             return
-        question = (("%s contains %s other archive file(s), " +
-                     "out of %s file(s) total.") %
-                    (current_filename, archive_count, extractor.file_count))
-        question = textwrap.wrap(question)
+        question = self.wrap(("%%s contains %s other archive file(s), " +
+                              "out of %s file(s) total.") %
+                             (archive_count, extractor.file_count),
+                             current_filename)
         if target == '.':
             target = ''
         included_root = extractor.included_root

mercurial