def _iter_contents(self, archive, root=None):
     self._archive_list.append(archive)
     self._archive_root[archive] = root
     supported_archive_regexp = archive_tools.get_supported_archive_regex()
     for f in archive.iter_contents():
         if supported_archive_regexp.search(f):
             # Extract sub-archive.
             destination_dir = os.path.join(self._destination_dir,
                                            'sub-archives')
             if root is not None:
                 destination_dir = os.path.join(destination_dir, root)
             archive.extract(f, destination_dir)
             # And open it and list its contents.
             sub_archive_path = os.path.join(destination_dir, f)
             sub_archive = archive_tools.get_archive_handler(
                 sub_archive_path)
             if sub_archive is None:
                 log.warning('Non-supported archive format: %s' %
                             os.path.basename(sub_archive_path))
                 continue
             sub_root = f
             if root is not None:
                 sub_root = os.path.join(root, sub_root)
             for name in self._iter_contents(sub_archive, sub_root):
                 yield name
         else:
             name = f
             if root is not None:
                 name = os.path.join(root, name)
             self._entry_mapping[name] = (archive, f)
             yield name
Example #2
0
 def _iter_contents(self, archive, root=None):
     self._archive_list.append(archive)
     self._archive_root[archive] = root
     supported_archive_regexp = archive_tools.get_supported_archive_regex()
     for f in archive.iter_contents():
         if supported_archive_regexp.search(f):
             # Extract sub-archive.
             destination_dir = os.path.join(self._destination_dir, 'sub-archives')
             if root is not None:
                 destination_dir = os.path.join(destination_dir, root)
             archive.extract(f, destination_dir)
             # And open it and list its contents.
             sub_archive_path = os.path.join(destination_dir, f)
             sub_archive = archive_tools.get_archive_handler(sub_archive_path)
             if sub_archive is None:
                 log.warning('Non-supported archive format: %s' %
                             os.path.basename(sub_archive_path))
                 continue
             sub_root = f
             if root is not None:
                 sub_root = os.path.join(root, sub_root)
             for name in self._iter_contents(sub_archive, sub_root):
                 yield name
         else:
             name = f
             if root is not None:
                 name = os.path.join(root, name)
             self._entry_mapping[name] = (archive, f)
             yield name
Example #3
0
 def _iter_contents(self, archive, root=None, decrypt=True):
     if archive.is_encrypted and not decrypt:
         return
     if not root:
         root = os.path.join(self.destdir, 'main_archive')
     self._archive_list.append(archive)
     self._archive_root[archive] = root
     sub_archive_list = []
     for f in archive.iter_contents():
         if archive_tools.is_archive_file(f):
             # We found a sub-archive, don't try to extract it now, as we
             # must finish listing the containing archive contents before
             # any extraction can be done.
             sub_archive_list.append(f)
             name = f if root is None else os.path.join(root, f)
             self._entry_mapping[name] = (archive, f)
             self._sub_archives.add(name)
             continue
         name = f
         if root is not None:
             name = os.path.join(root, name)
         self._entry_mapping[name] = (archive, f)
         yield name
     for f in sub_archive_list:
         # Extract sub-archive.
         destination_dir = self.destdir
         if root is not None:
             destination_dir = os.path.join(destination_dir, root)
         sub_archive_path = archive.extract(f, destination_dir)
         # And open it and list its contents.
         sub_archive = archive_tools.get_archive_handler(sub_archive_path)
         if sub_archive is None:
             log.warning('Non-supported archive format: %s',
                         os.path.basename(sub_archive_path))
             continue
         sub_tempdir = tempfile.TemporaryDirectory(
             prefix='sub_archive.{:04}.'.format(len(self._archive_list)),
             dir=self.destdir)
         sub_root = sub_tempdir.name
         self._sub_tempdirs.append(sub_tempdir)
         for name in self._iter_contents(sub_archive, sub_root):
             yield name
         os.remove(sub_archive_path)
Example #4
0
 def _iter_contents(self, archive, root=None):
     self._archive_list.append(archive)
     self._archive_root[archive] = root
     sub_archive_list = []
     for f in archive.iter_contents():
         if archive_tools.is_archive_file(f):
             # We found a sub-archive, don't try to extract it now, as we
             # must finish listing the containing archive contents before
             # any extraction can be done.
             sub_archive_list.append(f)
             continue
         name = f
         if root is not None:
             name = os.path.join(root, name)
         self._entry_mapping[name] = (archive, f)
         yield name
     for f in sub_archive_list:
         # Extract sub-archive.
         destination_dir = self._destination_dir
         if root is not None:
             destination_dir = os.path.join(destination_dir, root)
         archive.extract(f, destination_dir)
         sub_archive_ext = os.path.splitext(f)[1].lower()[1:]
         sub_archive_path = os.path.join(
             self._destination_dir, 'sub-archives',
             '%04u.%s' % (len(self._archive_list), sub_archive_ext
         ))
         self._create_directory(os.path.dirname(sub_archive_path))
         os.rename(os.path.join(destination_dir, f), sub_archive_path)
         # And open it and list its contents.
         sub_archive = archive_tools.get_archive_handler(sub_archive_path)
         if sub_archive is None:
             log.warning('Non-supported archive format: %s',
                         os.path.basename(sub_archive_path))
             continue
         sub_root = f
         if root is not None:
             sub_root = os.path.join(root, sub_root)
         for name in self._iter_contents(sub_archive, sub_root):
             yield name
Example #5
0
 def _iter_contents(self, archive, root=None):
     self._archive_list.append(archive)
     self._archive_root[archive] = root
     sub_archive_list = []
     for f in archive.iter_contents():
         if archive_tools.is_archive_file(f):
             # We found a sub-archive, don't try to extract it now, as we
             # must finish listing the containing archive contents before
             # any extraction can be done.
             sub_archive_list.append(f)
             continue
         name = f
         if root is not None:
             name = os.path.join(root, name)
         self._entry_mapping[name] = (archive, f)
         yield name
     for f in sub_archive_list:
         # Extract sub-archive.
         destination_dir = self._destination_dir
         if root is not None:
             destination_dir = os.path.join(destination_dir, root)
         archive.extract(f, destination_dir)
         sub_archive_ext = os.path.splitext(f)[1].lower()[1:]
         sub_archive_path = os.path.join(
             self._destination_dir, 'sub-archives',
             '%04u.%s' % (len(self._archive_list), sub_archive_ext))
         self._create_directory(os.path.dirname(sub_archive_path))
         os.rename(os.path.join(destination_dir, f), sub_archive_path)
         # And open it and list its contents.
         sub_archive = archive_tools.get_archive_handler(sub_archive_path)
         if sub_archive is None:
             log.warning('Non-supported archive format: %s',
                         os.path.basename(sub_archive_path))
             continue
         sub_root = f
         if root is not None:
             sub_root = os.path.join(root, sub_root)
         for name in self._iter_contents(sub_archive, sub_root):
             yield name
Example #6
0
    def setup(self, src, dst, type=None):
        """Setup the extractor with archive <src> and destination dir <dst>.
        Return a threading.Condition related to the is_ready() method, or
        None if the format of <src> isn't supported.
        """
        self._src = src
        self._dst = dst
        self._type = type or archive_tools.archive_mime_type(src)
        self._files = []
        self._extracted = {}
        self._stop = False
        self._extract_thread = None
        self._condition = threading.Condition()

        self._archive = archive_tools.get_archive_handler(src)

        if self._archive:
            self._files = self._archive.list_contents()
            self._setupped = True
            return self._condition
        else:
            msg = _('Non-supported archive format: %s') % os.path.basename(src)
            log.warning(msg)
            raise ArchiveException(msg)
Example #7
0
    def setup(self, src, dst, type=None):
        """Setup the extractor with archive <src> and destination dir <dst>.
        Return a threading.Condition related to the is_ready() method, or
        None if the format of <src> isn't supported.
        """
        self._src = src
        self._dst = dst
        self._type = type or archive_tools.archive_mime_type(src)
        self._files = []
        self._extracted = {}
        self._stop = False
        self._extract_thread = None
        self._condition = threading.Condition()

        self._archive = archive_tools.get_archive_handler(src)

        if self._archive:
            self._files = self._archive.list_contents()
            self._setupped = True
            return self._condition
        else:
            msg = _('Non-supported archive format: %s') % os.path.basename(src)
            log.warning(msg)
            raise ArchiveException(msg)