# HG changeset patch # User Brett Smith # Date 1212720850 14400 # Node ID 0aea49161478138463ec40970d6fcad094e70006 # Parent d7b46cae939bf0b1896956328b2c6addbf911ccc Make the wording on the One Entry question a little clearer. Unfortunately I now realize that things don't really work when your archive just contains one *file*, so I'll have to address that later. diff -r d7b46cae939b -r 0aea49161478 TODO --- a/TODO Thu Jun 05 22:00:39 2008 -0400 +++ b/TODO Thu Jun 05 22:54:10 2008 -0400 @@ -2,14 +2,7 @@ To do: -* When there's partial success in extracting an archive, go ahead and use - the partial version. To do this, when extracting, save the stderr of - everything that gets run, along with its status code. Let the top-level - loop decide what to do with that information. It should do this by - looking in the extraction directory/file and seeing if there's anything - actually there. If there is, it should go ahead and keep it, and report - errors as warnings (including stderr). Otherwise, it should treat it as - an unsuccessful extraction. +* Everything is messed up when an archive contains one file. * The text for when directory names don't match confused Paul. Consider alternatives. He thinks it would be cool if the actual/expected diff -r d7b46cae939b -r 0aea49161478 scripts/dtrx --- a/scripts/dtrx Thu Jun 05 22:00:39 2008 -0400 +++ b/scripts/dtrx Thu Jun 05 22:54:10 2008 -0400 @@ -49,10 +49,13 @@ Public License for more details.""" % (VERSION,) MATCHING_DIRECTORY = 1 -ONE_ENTRY = 2 +ONE_ENTRY_KNOWN = 2 BOMB = 3 EMPTY = 4 -ONE_ENTRY_KNOWN = 5 +ONE_ENTRY_FILE = 'file' +ONE_ENTRY_DIRECTORY = 'directory' + +ONE_ENTRY_UNKNOWN = [ONE_ENTRY_FILE, ONE_ENTRY_DIRECTORY] EXTRACT_HERE = 1 EXTRACT_WRAP = 2 @@ -213,8 +216,10 @@ elif len(self.contents) == 1: if self.basename() == self.contents[0]: self.content_type = MATCHING_DIRECTORY + elif os.path.isdir(self.contents[0]): + self.content_type = ONE_ENTRY_DIRECTORY else: - self.content_type = ONE_ENTRY + self.content_type = ONE_ENTRY_FILE self.content_name = self.contents[0] if os.path.isdir(self.contents[0]): self.content_name += '/' @@ -560,7 +565,7 @@ class MatchHandler(BaseHandler): def can_handle(contents, options): return ((contents == MATCHING_DIRECTORY) or - ((contents == ONE_ENTRY) and + ((contents in ONE_ENTRY_UNKNOWN) and options.one_entry_policy.ok_for_match())) can_handle = staticmethod(can_handle) @@ -613,7 +618,7 @@ self.permanent_policy = None def ask_question(self, question): - question = textwrap.wrap(question) + self.choices + question = question + self.choices while True: print "\n".join(question) try: @@ -638,9 +643,11 @@ " * extract it Here"] prompt = "What do you want to do? (I/r/h) " - def prep(self, archive_filename, entry_name): - question = ("%s contains one entry: %s." % - (archive_filename, entry_name)) + def prep(self, archive_filename, extractor): + question = ["%s contains one %s, but it has a weird name." % + (archive_filename, extractor.content_type)] + question.append(" Expected: " + extractor.basename()) + question.append(" Actual: " + extractor.content_name) self.current_policy = (self.permanent_policy or self.ask_question(question)) @@ -677,6 +684,7 @@ else: question = ("%s contains another archive: %s." % (current_filename, extractor.included_archives[0])) + question = textwrap.wrap(question) if target == '.': target = '' included_root = extractor.included_root @@ -855,9 +863,9 @@ self.did_print = False def get_handler(self, extractor): - if extractor.content_type == ONE_ENTRY: + if extractor.content_type in ONE_ENTRY_UNKNOWN: self.options.one_entry_policy.prep(self.current_filename, - extractor.content_name) + extractor) for handler in self.handlers: if handler.can_handle(extractor.content_type, self.options): logger.debug("using %s handler" % (handler.__name__,)) diff -r d7b46cae939b -r 0aea49161478 tests/tests.yml --- a/tests/tests.yml Thu Jun 05 22:00:39 2008 -0400 +++ b/tests/tests.yml Thu Jun 05 22:54:10 2008 -0400 @@ -234,6 +234,7 @@ - name: one directory extracted inside another (gz) options: "" filenames: test-onedir.tar.gz + grep: one directory input: i baseline: | mkdir test-onedir @@ -299,22 +300,25 @@ options: "" filenames: test-onefile.tar.gz input: i + grep: one file baseline: | mkdir test-onefile cd test-onefile tar -zxf ../$1 -- name: one file extracted with rename +- name: one file extracted with rename, with Expected text options: "" filenames: test-onefile.tar.gz input: r + grep: "Expected: test-onefile" baseline: | tar -zxOf $1 >test-onefile -- name: one file extracted here +- name: one file extracted here, with Actual text options: "" filenames: test-onefile.tar.gz input: h + grep: " Actual: test-text" baseline: | tar -zxf $1 @@ -330,7 +334,7 @@ - name: one directory preceded by dot in the table filenames: test-dot-first-onedir.tar.gz options: "" - grep: "one entry: (./)?dir/" + grep: "Actual: (./)?dir/" input: h baseline: | tar -zxf $1