348 self.pipe(['zcat'], "metadata.gz decompression") |
347 self.pipe(['zcat'], "metadata.gz decompression") |
349 |
348 |
350 def basename(self): |
349 def basename(self): |
351 return os.path.basename(self.filename) + '-metadata.txt' |
350 return os.path.basename(self.filename) + '-metadata.txt' |
352 |
351 |
|
352 |
|
353 class SevenExtractor(BaseExtractor): |
|
354 border_re = re.compile('^[- ]+$') |
|
355 |
|
356 def __init__(self, filename, encoding): |
|
357 BaseExtractor.__init__(self, '/dev/null', None) |
|
358 self.filename = os.path.realpath(filename) |
|
359 |
|
360 def get_filenames(self): |
|
361 self.pipe(['7z', 'l', self.filename], "listing") |
|
362 self.run_pipes() |
|
363 self.archive.seek(0, 0) |
|
364 fn_index = None |
|
365 for line in self.archive: |
|
366 if self.border_re.match(line): |
|
367 if fn_index is not None: |
|
368 break |
|
369 else: |
|
370 fn_index = line.rindex(' ') + 1 |
|
371 elif fn_index is not None: |
|
372 yield line[fn_index:-1] |
|
373 self.archive.close() |
|
374 |
|
375 def extract_archive(self): |
|
376 self.pipe(['7z', 'x', self.filename]) |
|
377 self.run_pipes() |
|
378 |
353 |
379 |
354 class BaseHandler(object): |
380 class BaseHandler(object): |
355 def __init__(self, extractor, options): |
381 def __init__(self, extractor, options): |
356 self.extractor = extractor |
382 self.extractor = extractor |
357 self.options = options |
383 self.options = options |
544 'zip': (ZipExtractor, None), |
570 'zip': (ZipExtractor, None), |
545 'deb': (DebExtractor, DebMetadataExtractor), |
571 'deb': (DebExtractor, DebMetadataExtractor), |
546 'rpm': (RPMExtractor, None), |
572 'rpm': (RPMExtractor, None), |
547 'cpio': (CpioExtractor, None), |
573 'cpio': (CpioExtractor, None), |
548 'gem': (GemExtractor, GemMetadataExtractor), |
574 'gem': (GemExtractor, GemMetadataExtractor), |
549 'compress': (CompressionExtractor, None)} |
575 'compress': (CompressionExtractor, None), |
|
576 '7z': (SevenExtractor, None)} |
550 |
577 |
551 mimetype_map = {} |
578 mimetype_map = {} |
552 for mapping in (('tar', 'x-tar'), |
579 for mapping in (('tar', 'x-tar'), |
553 ('zip', 'x-msdos-program', 'zip'), |
580 ('zip', 'x-msdos-program', 'zip'), |
554 ('deb', 'x-debian-package'), |
581 ('deb', 'x-debian-package'), |
555 ('rpm', 'x-redhat-package-manager', 'x-rpm'), |
582 ('rpm', 'x-redhat-package-manager', 'x-rpm'), |
556 ('cpio', 'x-cpio'), |
583 ('cpio', 'x-cpio'), |
557 ('gem', 'x-ruby-gem')): |
584 ('gem', 'x-ruby-gem'), |
|
585 ('7z', 'x-7z-compressed')): |
558 for mimetype in mapping[1:]: |
586 for mimetype in mapping[1:]: |
559 if '/' not in mimetype: |
587 if '/' not in mimetype: |
560 mimetype = 'application/' + mimetype |
588 mimetype = 'application/' + mimetype |
561 mimetype_map[mimetype] = mapping[0] |
589 mimetype_map[mimetype] = mapping[0] |
562 |
590 |
563 magic_mime_map = {} |
591 magic_mime_map = {} |
564 for mapping in (('deb', 'Debian binary package'), |
592 for mapping in (('deb', 'Debian binary package'), |
565 ('cpio', 'cpio archive'), |
593 ('cpio', 'cpio archive'), |
566 ('tar', 'POSIX tar archive'), |
594 ('tar', 'POSIX tar archive'), |
567 ('zip', 'Zip archive'), |
595 ('zip', 'Zip archive'), |
568 ('rpm', 'RPM')): |
596 ('rpm', 'RPM'), |
|
597 ('7z', '7-zip archive')): |
569 for pattern in mapping[1:]: |
598 for pattern in mapping[1:]: |
570 magic_mime_map[re.compile(pattern)] = mapping[0] |
599 magic_mime_map[re.compile(pattern)] = mapping[0] |
571 |
600 |
572 magic_encoding_map = {} |
601 magic_encoding_map = {} |
573 for mapping in (('bzip2', 'bzip2 compressed'), |
602 for mapping in (('bzip2', 'bzip2 compressed'), |
582 ('zip', None, 'zip', 'exe'), |
611 ('zip', None, 'zip', 'exe'), |
583 ('deb', None, 'deb'), |
612 ('deb', None, 'deb'), |
584 ('rpm', None, 'rpm'), |
613 ('rpm', None, 'rpm'), |
585 ('cpio', None, 'cpio'), |
614 ('cpio', None, 'cpio'), |
586 ('gem', None, 'gem'), |
615 ('gem', None, 'gem'), |
587 ('compress', None, 'gz', 'bz2')): |
616 ('compress', None, 'gz', 'bz2'), |
|
617 ('7z', None, '7z')): |
588 for extension in mapping[2:]: |
618 for extension in mapping[2:]: |
589 extension_map[extension] = mapping[:2] |
619 extension_map[extension] = mapping[:2] |
590 |
620 |
591 def __init__(self, filename, options): |
621 def __init__(self, filename, options): |
592 self.filename = filename |
622 self.filename = filename |