667 size = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, |
667 size = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, |
668 struct.pack("HHHH", 0, 0, 0, 0)) |
668 struct.pack("HHHH", 0, 0, 0, 0)) |
669 width = struct.unpack("HHHH", size)[1] |
669 width = struct.unpack("HHHH", size)[1] |
670 except IOError: |
670 except IOError: |
671 width = 80 |
671 width = 80 |
672 q_wrapper = textwrap.TextWrapper(width=width - 1, break_long_words=False) |
672 width = width - 1 |
673 choice_wrapper = textwrap.TextWrapper(width=width - 1, initial_indent=' * ', |
673 choice_wrapper = textwrap.TextWrapper(width=width, initial_indent=' * ', |
674 subsequent_indent=' ', |
674 subsequent_indent=' ', |
675 break_long_words=False) |
675 break_long_words=False) |
676 |
676 |
677 def __init__(self, options): |
677 def __init__(self, options): |
678 self.current_policy = None |
678 self.current_policy = None |
693 return self.answers[''] |
693 return self.answers[''] |
694 try: |
694 try: |
695 return self.answers[answer.lower()] |
695 return self.answers[answer.lower()] |
696 except KeyError: |
696 except KeyError: |
697 print |
697 print |
|
698 |
|
699 def wrap(self, question, *args): |
|
700 words = question.split() |
|
701 for arg in args: |
|
702 words[words.index('%s')] = arg |
|
703 result = [words.pop(0)] |
|
704 for word in words: |
|
705 extend = '%s %s' % (result[-1], word) |
|
706 if len(extend) > self.width: |
|
707 result.append(word) |
|
708 else: |
|
709 result[-1] = extend |
|
710 return result |
698 |
711 |
699 def __cmp__(self, other): |
712 def __cmp__(self, other): |
700 return cmp(self.current_policy, other) |
713 return cmp(self.current_policy, other) |
701 |
714 |
702 |
715 |
724 self.permanent_policy = EXTRACT_WRAP |
737 self.permanent_policy = EXTRACT_WRAP |
725 elif default is not None: |
738 elif default is not None: |
726 raise ValueError("bad value %s for default policy" % (default,)) |
739 raise ValueError("bad value %s for default policy" % (default,)) |
727 |
740 |
728 def prep(self, archive_filename, extractor): |
741 def prep(self, archive_filename, extractor): |
729 question = self.q_wrapper.wrap( |
742 question = self.wrap( |
730 "%s contains one %s, but its name doesn't match." % |
743 "%s contains one %s but its name doesn't match.", |
731 (archive_filename, extractor.content_type)) |
744 archive_filename, extractor.content_type) |
732 question.append(" Expected: " + extractor.basename()) |
745 question.append(" Expected: " + extractor.basename()) |
733 question.append(" Actual: " + extractor.content_name) |
746 question.append(" Actual: " + extractor.content_name) |
734 choice_vars = (extractor.content_type, extractor.basename()) |
747 choice_vars = (extractor.content_type, extractor.basename()) |
735 self.choices = [text % choice_vars[:text.count('%s')] |
748 self.choices = [text % choice_vars[:text.count('%s')] |
736 for text in self.choice_template] |
749 for text in self.choice_template] |
761 def prep(self, current_filename, target, extractor): |
774 def prep(self, current_filename, target, extractor): |
762 archive_count = len(extractor.included_archives) |
775 archive_count = len(extractor.included_archives) |
763 if (self.permanent_policy is not None) or (archive_count == 0): |
776 if (self.permanent_policy is not None) or (archive_count == 0): |
764 self.current_policy = self.permanent_policy or RECURSE_NOT_NOW |
777 self.current_policy = self.permanent_policy or RECURSE_NOT_NOW |
765 return |
778 return |
766 question = self.q_wrapper.wrap( |
779 question = self.wrap( |
767 "%s contains %s other archive file(s), out of %s file(s) total." % |
780 "%s contains %s other archive file(s), out of %s file(s) total.", |
768 (current_filename, archive_count, extractor.file_count)) |
781 current_filename, archive_count, extractor.file_count) |
769 if target == '.': |
782 if target == '.': |
770 target = '' |
783 target = '' |
771 included_root = extractor.included_root |
784 included_root = extractor.included_root |
772 if included_root == './': |
785 if included_root == './': |
773 included_root = '' |
786 included_root = '' |