Esempio n. 1
0
    def load_data(self, source):
        try:
            archive = rarfile.RarFile(source)
        except (rarfile.NotRarFile, rarfile.BadRarFile) as e:
            try:
                os.remove(source)
            except OSError:
                print("FIAS Error while deleting file ", source)
            raise BadArchiveError('Archive: `{0}`, ver: `{1}` corrupted'
                                  ' or is not rar-archive'.format(source))

        if not archive.namelist():
            try:
                os.remove(source)
            except OSError:
                print("FIAS Error while deleting file ", source)
            raise BadArchiveError('Archive: `{0}`, ver: `{1}` is empty'
                                  ''.format(source))

        first_name = archive.namelist()[0]
        if table_dbf_re.match(first_name) or table_dbt_re.match(first_name):
            pre_unpack.send(sender=self.__class__, archive=archive)

            path = LocalArchiveTableList.unpack(archive=archive, tempdir=self.tempdir)

            post_unpack.send(sender=self.__class__, archive=archive, dst=path)

            return DirectoryTableList.wrapper_class(source=path, is_temporary=True)

        return self.wrapper_class(source=archive)
Esempio n. 2
0
    def load_data(self, source):
        try:
            archive = rarfile.RarFile(source)
        # except (rarfile.NotRarFile, rarfile.BadRarFile) as e:
        except Exception as e1:
            try:
                archive = zipfile.ZipFile(source)
            except Exception as e2:
                raise BadArchiveError(
                    'Archive: `{}` corrupted or is not rar,zip-archive; {}; {}'
                    .format(source, e1, e2))

        if not archive.namelist():
            raise BadArchiveError('Archive: `{}`, is empty'.format(source))

        first_name = archive.namelist()[0]
        if table_dbf_re.match(first_name) or table_dbt_re.match(first_name):
            pre_unpack.send(sender=self.__class__, archive=archive)

            path = LocalArchiveTableList.unpack(archive=archive,
                                                tempdir=self.tempdir)

            post_unpack.send(sender=self.__class__, archive=archive, dst=path)

            return DirectoryTableList.wrapper_class(source=path,
                                                    is_temporary=True)

        return self.wrapper_class(source=archive)
Esempio n. 3
0
    def load_data(self, source):
        try:
            archive = rarfile.RarFile(source)
        except (rarfile.NotRarFile, rarfile.BadRarFile) as e:
            raise BadArchiveError('Archive: `{0}`, ver: `{1}` corrupted'
                                  ' or is not rar-archive'.format(source))

        if not archive.namelist():
            raise BadArchiveError('Archive: `{0}`, ver: `{1}` is empty'
                                  ''.format(source))

        first_name = archive.namelist()[0]
        if table_dbf_re.match(first_name) or table_dbt_re.match(first_name):
            pre_unpack.send(sender=self.__class__, archive=archive)

            path = LocalArchiveTableList.unpack(archive=archive, tempdir=self.tempdir)

            post_unpack.send(sender=self.__class__, archive=archive, dst=path)

            return DirectoryTableList.wrapper_class(source=path, is_temporary=True)

        return self.wrapper_class(source=archive)