195 self.archive = final_stdout |
195 self.archive = final_stdout |
196 |
196 |
197 def prepare(self): |
197 def prepare(self): |
198 pass |
198 pass |
199 |
199 |
200 def check_included_archives(self, filenames): |
200 def check_included_archives(self): |
201 for filename in filenames: |
201 if (self.content_name is None) or (not self.content_name.endswith('/')): |
202 if (ExtractorBuilder.try_by_mimetype(filename) or |
202 self.included_root = './' |
203 ExtractorBuilder.try_by_extension(filename)): |
203 else: |
204 self.included_archives.append(filename) |
204 self.included_root = self.content_name |
|
205 start_index = len(self.included_root) |
|
206 for path, dirname, filenames in os.walk(self.included_root): |
|
207 path = path[start_index:] |
|
208 for filename in filenames: |
|
209 if (ExtractorBuilder.try_by_mimetype(filename) or |
|
210 ExtractorBuilder.try_by_extension(filename)): |
|
211 self.included_archives.append(os.path.join(path, filename)) |
205 |
212 |
206 def check_contents(self): |
213 def check_contents(self): |
207 filenames = os.listdir('.') |
214 filenames = os.listdir('.') |
208 if not filenames: |
215 if not filenames: |
209 self.content_type = EMPTY |
216 self.content_type = EMPTY |
215 self.content_name = filenames[0] |
222 self.content_name = filenames[0] |
216 if os.path.isdir(filenames[0]): |
223 if os.path.isdir(filenames[0]): |
217 self.content_name += '/' |
224 self.content_name += '/' |
218 else: |
225 else: |
219 self.content_type = BOMB |
226 self.content_type = BOMB |
220 self.check_included_archives(filenames) |
227 self.check_included_archives() |
221 |
228 |
222 def basename(self): |
229 def basename(self): |
223 pieces = os.path.basename(self.filename).split('.') |
230 pieces = os.path.basename(self.filename).split('.') |
224 extension = '.' + pieces[-1] |
231 extension = '.' + pieces[-1] |
225 if mimetypes.encodings_map.has_key(extension): |
232 if mimetypes.encodings_map.has_key(extension): |
332 elif len(pieces[-1]) < 8: |
339 elif len(pieces[-1]) < 8: |
333 pieces.pop() |
340 pieces.pop() |
334 return '.'.join(pieces) |
341 return '.'.join(pieces) |
335 |
342 |
336 def check_contents(self): |
343 def check_contents(self): |
337 self.check_included_archives(os.listdir('.')) |
344 self.check_included_archives() |
338 self.content_type = BOMB |
345 self.content_type = BOMB |
339 |
346 |
340 |
347 |
341 class DebExtractor(TarExtractor): |
348 class DebExtractor(TarExtractor): |
342 file_type = 'Debian package' |
349 file_type = 'Debian package' |
354 if (len(last_piece) > 10) or (not last_piece.endswith('.deb')): |
361 if (len(last_piece) > 10) or (not last_piece.endswith('.deb')): |
355 return BaseExtractor.basename(self) |
362 return BaseExtractor.basename(self) |
356 return '_'.join(pieces) |
363 return '_'.join(pieces) |
357 |
364 |
358 def check_contents(self): |
365 def check_contents(self): |
359 self.check_included_archives(os.listdir('.')) |
366 self.check_included_archives() |
360 self.content_type = BOMB |
367 self.content_type = BOMB |
361 |
368 |
362 |
369 |
363 class DebMetadataExtractor(DebExtractor): |
370 class DebMetadataExtractor(DebExtractor): |
364 def prepare(self): |
371 def prepare(self): |
373 def prepare(self): |
380 def prepare(self): |
374 self.pipe(['tar', '-xO', 'data.tar.gz'], "data.tar.gz extraction") |
381 self.pipe(['tar', '-xO', 'data.tar.gz'], "data.tar.gz extraction") |
375 self.pipe(['zcat'], "data.tar.gz decompression") |
382 self.pipe(['zcat'], "data.tar.gz decompression") |
376 |
383 |
377 def check_contents(self): |
384 def check_contents(self): |
378 self.check_included_archives(os.listdir('.')) |
385 self.check_included_archives() |
379 self.content_type = BOMB |
386 self.content_type = BOMB |
380 |
387 |
381 |
388 |
382 class GemMetadataExtractor(CompressionExtractor): |
389 class GemMetadataExtractor(CompressionExtractor): |
383 file_type = 'Ruby gem' |
390 file_type = 'Ruby gem' |
561 if os.path.isdir(self.extractor.target): |
568 if os.path.isdir(self.extractor.target): |
562 os.rename(source, self.target) |
569 os.rename(source, self.target) |
563 os.rmdir(self.extractor.target) |
570 os.rmdir(self.extractor.target) |
564 else: |
571 else: |
565 os.rename(self.extractor.target, self.target) |
572 os.rename(self.extractor.target, self.target) |
|
573 self.extractor.included_root = '.' |
566 |
574 |
567 |
575 |
568 class EmptyHandler(object): |
576 class EmptyHandler(object): |
569 def can_handle(contents, options): |
577 def can_handle(contents, options): |
570 return contents == EMPTY |
578 return contents == EMPTY |
924 archives = extractor.included_archives |
932 archives = extractor.included_archives |
925 self.options.recursion_policy.prep(filename, archives) |
933 self.options.recursion_policy.prep(filename, archives) |
926 if self.options.recursion_policy.ok_to_recurse(): |
934 if self.options.recursion_policy.ok_to_recurse(): |
927 for filename in archives: |
935 for filename in archives: |
928 tail_path, basename = os.path.split(filename) |
936 tail_path, basename = os.path.split(filename) |
929 directory = os.path.join(self.current_directory, |
937 directory = os.path.join(self.current_directory, action.target, |
930 action.target, tail_path) |
938 extractor.included_root, tail_path) |
931 self.archives.setdefault(directory, []).append(basename) |
939 self.archives.setdefault(directory, []).append(basename) |
932 |
940 |
933 def check_file(self, filename): |
941 def check_file(self, filename): |
934 try: |
942 try: |
935 result = os.stat(filename) |
943 result = os.stat(filename) |