This commit is contained in:
chfw 2020-09-26 22:36:29 +01:00
commit 3aa802f878
11 changed files with 45 additions and 53 deletions

View File

@ -1,3 +1,2 @@
pip install flake8
flake8 . --exclude=.moban.d,docs,setup.py --builtins=unicode,xrange,long
python setup.py checkdocs
flake8 . --exclude=.moban.d,docs,setup.py --builtins=unicode,xrange,long && python setup.py checkdocs

View File

@ -12,15 +12,7 @@ from pyexcel_io.constants import DB_SQL, DB_DJANGO
NewIOPluginInfoChain(__name__).add_a_reader(
relative_plugin_class_path="exporters.django.DjangoBookReader",
location="file",
file_types=[DB_DJANGO],
).add_a_reader(
relative_plugin_class_path="exporters.django.DjangoBookReader",
location="memory",
file_types=[DB_DJANGO],
).add_a_reader(
relative_plugin_class_path="exporters.django.DjangoBookReader",
location="content",
locations=["file", "memory", "content"],
file_types=[DB_DJANGO],
).add_a_writer(
relative_plugin_class_path="importers.django.DjangoBookWriter",
@ -28,15 +20,7 @@ NewIOPluginInfoChain(__name__).add_a_reader(
file_types=[DB_DJANGO],
).add_a_reader(
relative_plugin_class_path="exporters.sqlalchemy.SQLBookReader",
location="file",
file_types=[DB_SQL],
).add_a_reader(
relative_plugin_class_path="exporters.sqlalchemy.SQLBookReader",
location="memory",
file_types=[DB_SQL],
).add_a_reader(
relative_plugin_class_path="exporters.sqlalchemy.SQLBookReader",
location="content",
locations=["file", "memory", "content"],
file_types=[DB_SQL],
).add_a_writer(
relative_plugin_class_path="importers.sqlalchemy.SQLBookWriter",

View File

@ -10,7 +10,6 @@
import logging
import pyexcel_io.constants as constants
from pyexcel_io.book import BookWriter
from pyexcel_io.sheet import SheetWriter
from pyexcel_io.utils import is_empty_array, swap_empty_string_for_none

View File

@ -8,7 +8,6 @@
:license: New BSD License, see LICENSE for more details
"""
import pyexcel_io.constants as constants
from pyexcel_io.book import BookWriter
from pyexcel_io.sheet import SheetWriter
from pyexcel_io.utils import is_empty_array, swap_empty_string_for_none

View File

@ -71,7 +71,7 @@ class NewIOPluginInfoChain(PluginInfoChain):
def add_a_reader(
self,
relative_plugin_class_path=None,
location="file",
locations=(),
file_types=None,
stream_type=None,
):
@ -79,7 +79,11 @@ class NewIOPluginInfoChain(PluginInfoChain):
a_plugin_info = IOPluginInfo(
NEW_READER_PLUGIN,
self._get_abs_path(relative_plugin_class_path),
file_types=[f"{location}-{file_type}" for file_type in file_types],
file_types=[
f"{location}-{file_type}"
for file_type in file_types
for location in locations
],
stream_type=stream_type,
)
return self.add_a_plugin_instance(a_plugin_info)

View File

@ -11,52 +11,42 @@ from pyexcel_io.plugins import NewIOPluginInfoChain
NewIOPluginInfoChain(__name__).add_a_reader(
relative_plugin_class_path="csv_in_file.FileReader",
location="file",
locations=["file"],
file_types=["csv"],
stream_type="text",
).add_a_reader(
relative_plugin_class_path="csv_content.ContentReader",
location="content",
locations=["content"],
file_types=["csv"],
stream_type="text",
).add_a_reader(
relative_plugin_class_path="csv_in_memory.MemoryReader",
location="memory",
locations=["memory"],
file_types=["csv"],
stream_type="text",
).add_a_reader(
relative_plugin_class_path="tsv.TSVMemoryReader",
location="memory",
locations=["memory"],
file_types=["tsv"],
stream_type="text",
).add_a_reader(
relative_plugin_class_path="tsv.TSVFileReader",
location="file",
locations=["file"],
file_types=["tsv"],
stream_type="text",
).add_a_reader(
relative_plugin_class_path="tsv.TSVContentReader",
location="content",
locations=["content"],
file_types=["tsv"],
stream_type="text",
).add_a_reader(
relative_plugin_class_path="csvz.FileReader",
file_types=["csvz"],
location="file",
stream_type="binary",
).add_a_reader(
relative_plugin_class_path="csvz.FileReader",
file_types=["csvz"],
location="memory",
locations=["file", "memory"],
stream_type="binary",
).add_a_reader(
relative_plugin_class_path="tsvz.TSVZipFileReader",
file_types=["tsvz"],
location="file",
stream_type="binary",
).add_a_reader(
relative_plugin_class_path="tsvz.TSVZipFileReader",
file_types=["tsvz"],
location="memory",
locations=["file", "memory"],
stream_type="binary",
)

View File

@ -1,7 +1,4 @@
from pyexcel_io.plugins import NEW_WRITERS
from pyexcel_io._compact import isstream
from .constants import MESSAGE_ERROR_03
class Writer(object):
@ -31,13 +28,7 @@ class Writer(object):
self.writer = writer_class(file_stream, **keywords)
def write(self, incoming_dict):
for sheet_name in incoming_dict:
sheet_writer = self.writer.create_sheet(sheet_name)
if sheet_writer:
sheet_writer.write_array(incoming_dict[sheet_name])
sheet_writer.close()
else:
raise Exception("Cannot create a sheet writer!")
self.writer.write(incoming_dict)
def close(self):
self.writer.close()

View File

@ -18,6 +18,15 @@ class CsvFileWriter:
self.__index = self.__index + 1
return self.writer
def write(self, incoming_dict):
for sheet_name in incoming_dict:
sheet_writer = self.create_sheet(sheet_name)
if sheet_writer:
sheet_writer.write_array(incoming_dict[sheet_name])
sheet_writer.close()
else:
raise Exception("Cannot create a sheet writer!")
def close(self):
if self.writer:
self.writer.close()

View File

@ -18,5 +18,14 @@ class CsvMemoryWriter:
self.__index = self.__index + 1
return writer
def write(self, incoming_dict):
for sheet_name in incoming_dict:
sheet_writer = self.create_sheet(sheet_name)
if sheet_writer:
sheet_writer.write_array(incoming_dict[sheet_name])
sheet_writer.close()
else:
raise Exception("Cannot create a sheet writer!")
def close(self):
pass

View File

@ -27,6 +27,15 @@ class CsvZipWriter(object):
)
return writer
def write(self, incoming_dict):
for sheet_name in incoming_dict:
sheet_writer = self.create_sheet(sheet_name)
if sheet_writer:
sheet_writer.write_array(incoming_dict[sheet_name])
sheet_writer.close()
else:
raise Exception("Cannot create a sheet writer!")
def close(self):
if self.zipfile:
self.zipfile.close()

View File

@ -6,7 +6,6 @@ from pyexcel_io.book import (
)
from pyexcel_io._compact import BytesIO, StringIO
from nose import SkipTest
from nose.tools import raises