diff --git a/.travis.yml b/.travis.yml index b457dd1..9cb4e91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ python: stages: - lint - - moban - test @@ -23,16 +22,6 @@ stages: stage: lint script: make lint -.moban: &moban - python: 3.6 - env: - - MINREQ=0 - stage: moban - install: pip install moban gitfs2 pypifs moban-jinja2-github moban-ansible - script: - - moban - - git diff --exit-code - jobs: include: - *moban diff --git a/pyexcel-ods3.yml b/pyexcel-ods3.yml index 9209539..de6d545 100644 --- a/pyexcel-ods3.yml +++ b/pyexcel-ods3.yml @@ -14,5 +14,6 @@ test_dependencies: - pyexcel - psutil - pyexcel-xls -description: | - A wrapper library to read, manipulate and write data in ods format \ No newline at end of file +moban_command: false +description: |- + A wrapper library to read, manipulate and write data in ods format diff --git a/pyexcel_ods3/odsr.py b/pyexcel_ods3/odsr.py index da1a011..3250a7d 100644 --- a/pyexcel_ods3/odsr.py +++ b/pyexcel_ods3/odsr.py @@ -11,37 +11,35 @@ import ezodf import pyexcel_io.service as service -from pyexcel_io.plugin_api.abstract_sheet import ISheet -from pyexcel_io.plugin_api.abstract_reader import IReader +from pyexcel_io.plugin_api import ISheet, IReader, NamedContent class ODSSheet(ISheet): """ODS sheet representation""" - def __init__(self, sheet, auto_detect_int=True, **keywords): + def __init__(self, sheet, auto_detect_int=True): self.auto_detect_int = auto_detect_int - self._native_sheet = sheet - self._keywords = keywords + self.ods_sheet = sheet @property def name(self): - return self._native_sheet.name + return self.ods_sheet.name def row_iterator(self): """ Number of rows in the xls sheet """ - return range(self._native_sheet.nrows()) + return range(self.ods_sheet.nrows()) def column_iterator(self, row): """ Number of columns in the xls sheet """ - for column in range(self._native_sheet.ncols()): + for column in range(self.ods_sheet.ncols()): yield self.cell_value(row, column) def cell_value(self, row, column): - cell = self._native_sheet.get_cell((row, column)) + cell = self.ods_sheet.get_cell((row, column)) cell_type = cell.value_type ret = None if cell_type == "currency": @@ -67,19 +65,19 @@ def cell_value(self, row, column): class ODSBook(IReader): def __init__(self, file_alike_object, file_type, **keywords): - self._native_book = ezodf.opendoc(file_alike_object) + self.ods_book = ezodf.opendoc(file_alike_object) self._keywords = keywords self.content_array = [ - NameObject(sheet.name, sheet) for sheet in self._native_book.sheets + NamedContent(sheet.name, sheet) for sheet in self.ods_book.sheets ] def read_sheet(self, native_sheet_index): - native_sheet = self.content_array[native_sheet_index].sheet + native_sheet = self.content_array[native_sheet_index].payload sheet = ODSSheet(native_sheet, **self._keywords) return sheet def close(self): - self._native_book = None + self.ods_book = None class ODSBookInContent(ODSBook): @@ -90,9 +88,3 @@ class ODSBookInContent(ODSBook): def __init__(self, file_content, file_type, **keywords): io = BytesIO(file_content) super().__init__(io, file_type, **keywords) - - -class NameObject(object): - def __init__(self, name, sheet): - self.name = name - self.sheet = sheet diff --git a/pyexcel_ods3/odsw.py b/pyexcel_ods3/odsw.py index 183cd36..474ca43 100644 --- a/pyexcel_ods3/odsw.py +++ b/pyexcel_ods3/odsw.py @@ -4,7 +4,7 @@ ods writer using ezodf - :copyright: (c) 2015-2017 by Onni Software Ltd. & its contributors + :copyright: (c) 2015-2020 by Onni Software Ltd. & its contributors :license: New BSD License """ import types @@ -13,8 +13,7 @@ import pyexcel_io.service as service from pyexcel_io.constants import MAX_INTEGER from pyexcel_io.exceptions import IntegerAccuracyLossError -from pyexcel_io.plugin_api.abstract_sheet import ISheetWriter -from pyexcel_io.plugin_api.abstract_writer import IWriter +from pyexcel_io.plugin_api import IWriter, ISheetWriter class ODSSheetWriter(ISheetWriter): @@ -23,12 +22,12 @@ class ODSSheetWriter(ISheetWriter): """ def __init__(self, ods_book, ods_sheet, sheet_name, **keywords): - self._native_book = ods_book - self._native_sheet = ezodf.Sheet(sheet_name) + self.ods_book = ods_book + self.ods_sheet = ezodf.Sheet(sheet_name) self.current_row = 0 def _set_size(self, size): - self._native_sheet.reset(size=size) + self.ods_sheet.reset(size=size) def write_row(self, array): """ @@ -48,7 +47,7 @@ def write_row(self, array): elif value_type == "float": if cell > MAX_INTEGER: raise IntegerAccuracyLossError("%s is too big" % cell) - self._native_sheet[self.current_row, count].set_value( + self.ods_sheet[self.current_row, count].set_value( cell, value_type=value_type ) count += 1 @@ -71,7 +70,7 @@ def close(self): This call writes file """ - self._native_book.sheets += self._native_sheet + self.ods_book.sheets += self.ods_sheet class ODSWriter(IWriter): @@ -84,23 +83,23 @@ def __init__( self, file_alike_object, file_type, skip_backup=True, **keywords ): """open a file for writing ods""" - self._native_book = ezodf.newdoc( + self.ods_book = ezodf.newdoc( doctype=file_type, filename=file_alike_object ) if skip_backup: - self._native_book.backup = False + self.ods_book.backup = False def create_sheet(self, name): """ write a row into the file """ - return ODSSheetWriter(self._native_book, None, name) + return ODSSheetWriter(self.ods_book, None, name) def close(self): """ This call writes file """ - self._native_book.save() - self._native_book = None + self.ods_book.save() + self.ods_book = None diff --git a/tests/test_ods_reader.py b/tests/test_ods_reader.py index 075bf5a..d32cd01 100644 --- a/tests/test_ods_reader.py +++ b/tests/test_ods_reader.py @@ -1,15 +1,14 @@ import os from base import ODSCellTypes -from pyexcel_ods3.odsr import ODSBook +from pyexcel_io.reader import Reader from pyexcel_ods3.odsw import ODSWriter class TestODSReader(ODSCellTypes): def setUp(self): - r = ODSBook( - os.path.join("tests", "fixtures", "ods_formats.ods"), "ods" - ) + r = Reader("ods") + r.open(os.path.join("tests", "fixtures", "ods_formats.ods")) self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) @@ -18,20 +17,23 @@ def setUp(self): class TestODSWriter(ODSCellTypes): def setUp(self): - r = ODSBook( + r = Reader("ods") + r.open( os.path.join("tests", "fixtures", "ods_formats.ods"), - "ods", skip_empty_rows=True, ) self.data1 = r.read_all() + r.close() self.testfile = "odswriter.ods" w = ODSWriter(self.testfile, "ods") w.write(self.data1) w.close() - r2 = ODSBook(self.testfile, "ods") - self.data = r2.read_all() + r.open(self.testfile) + self.data = r.read_all() + for key in self.data.keys(): self.data[key] = list(self.data[key]) + r.close() def tearDown(self): if os.path.exists(self.testfile): diff --git a/tests/test_writer.py b/tests/test_writer.py index 8435a1f..739515c 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -1,7 +1,7 @@ import os from base import PyexcelWriterBase, PyexcelHatWriterBase -from pyexcel_ods3.odsr import ODSBook as Reader +from pyexcel_ods3 import get_data from pyexcel_ods3.odsw import ODSWriter as Writer @@ -16,12 +16,10 @@ def test_write_book(self): writer = Writer(self.testfile, "ods") writer.write(self.content) writer.close() - reader = Reader(self.testfile, "ods") - content = reader.read_all() + content = get_data(self.testfile) for key in content.keys(): content[key] = list(content[key]) assert content == self.content - reader.close() def tearDown(self): if os.path.exists(self.testfile):