From bb8b97f7fd80f6c599742ff7c3ab76db123a28b2 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 25 Aug 2017 08:21:26 +0100 Subject: [PATCH] :fire: remove useless code as it is now handled in pyexcel-io --- pyexcel_ods/converter.py | 135 --------------------------------------- pyexcel_ods/odsr.py | 17 ++--- rnd_requirements.txt | 4 +- 3 files changed, 7 insertions(+), 149 deletions(-) delete mode 100644 pyexcel_ods/converter.py diff --git a/pyexcel_ods/converter.py b/pyexcel_ods/converter.py deleted file mode 100644 index fad8b9b..0000000 --- a/pyexcel_ods/converter.py +++ /dev/null @@ -1,135 +0,0 @@ -import sys -import datetime - -PY2 = sys.version_info[0] == 2 - - -def float_value(value): - """convert a value to float""" - ret = float(value) - return ret - - -def date_value(value): - """convert to data value accroding ods specification""" - ret = "invalid" - try: - # catch strptime exceptions only - if len(value) == 10: - ret = datetime.datetime.strptime( - value, - "%Y-%m-%d") - ret = ret.date() - elif len(value) == 19: - ret = datetime.datetime.strptime( - value, - "%Y-%m-%dT%H:%M:%S") - elif len(value) > 19: - ret = datetime.datetime.strptime( - value[0:26], - "%Y-%m-%dT%H:%M:%S.%f") - except ValueError: - pass - if ret == "invalid": - raise Exception("Bad date value %s" % value) - return ret - - -def ods_date_value(value): - return value.strftime("%Y-%m-%d") - - -def time_value(value): - """convert to time value accroding the specification""" - import re - results = re.match('PT(\d+)H(\d+)M(\d+)S', value) - hour = int(results.group(1)) - minute = int(results.group(2)) - second = int(results.group(3)) - if hour < 24: - ret = datetime.time(hour, minute, second) - else: - ret = datetime.timedelta(hours=hour, minutes=minute, seconds=second) - return ret - - -def ods_time_value(value): - return value.strftime("PT%HH%MM%SS") - - -def boolean_value(value): - """get bolean value""" - if value == "true": - ret = True - else: - ret = False - return ret - - -def ods_bool_value(value): - """convert a boolean value to text""" - if value is True: - return "true" - else: - return "false" - - -def ods_timedelta_value(cell): - """convert a cell value to time delta""" - hours = cell.days * 24 + cell.seconds // 3600 - minutes = (cell.seconds // 60) % 60 - seconds = cell.seconds % 60 - return "PT%02dH%02dM%02dS" % (hours, minutes, seconds) - - -ODS_FORMAT_CONVERSION = { - "float": float, - "date": datetime.date, - "time": datetime.time, - 'timedelta': datetime.timedelta, - "boolean": bool, - "percentage": float, - "currency": float -} - - -ODS_WRITE_FORMAT_COVERSION = { - float: "float", - int: "float", - str: "string", - datetime.date: "date", - datetime.time: "time", - datetime.timedelta: "timedelta", - bool: "boolean" -} - -if PY2: - ODS_WRITE_FORMAT_COVERSION[unicode] = "string" - -VALUE_CONVERTERS = { - "float": float_value, - "date": date_value, - "time": time_value, - "timedelta": time_value, - "boolean": boolean_value, - "percentage": float_value, - "currency": float_value -} - -ODS_VALUE_CONVERTERS = { - "date": ods_date_value, - "time": ods_time_value, - "boolean": ods_bool_value, - "timedelta": ods_timedelta_value -} - - -VALUE_TOKEN = { - "float": "value", - "date": "date-value", - "time": "time-value", - "boolean": "boolean-value", - "percentage": "value", - "currency": "value", - "timedelta": "time-value" -} diff --git a/pyexcel_ods/odsr.py b/pyexcel_ods/odsr.py index 4b191cf..1e13a62 100644 --- a/pyexcel_ods/odsr.py +++ b/pyexcel_ods/odsr.py @@ -22,7 +22,6 @@ # limitations under the License. # Thanks to grt for the fixes -import math from io import UnsupportedOperation from odf.teletype import extractText @@ -34,8 +33,7 @@ from pyexcel_io.book import BookReader from pyexcel_io.sheet import SheetReader from pyexcel_io._compact import OrderedDict, BytesIO - -import pyexcel_ods.converter as converter +import pyexcel_io.service as service class ODSSheet(SheetReader): @@ -65,7 +63,7 @@ def column_iterator(self, row): def __read_cell(self, cell): cell_type = cell.getAttrNS(OFFICENS, "value-type") - value_token = converter.VALUE_TOKEN.get(cell_type, "value") + value_token = service.VALUE_TOKEN.get(cell_type, "value") ret = None if cell_type == "string": text_content = self.__read_text_cell(cell) @@ -75,11 +73,11 @@ def __read_cell(self, cell): currency = cell.getAttrNS(OFFICENS, cell_type) ret = value + ' ' + currency else: - if cell_type in converter.VALUE_CONVERTERS: + if cell_type in service.VALUE_CONVERTERS: value = cell.getAttrNS(OFFICENS, value_token) - n_value = converter.VALUE_CONVERTERS[cell_type](value) + n_value = service.VALUE_CONVERTERS[cell_type](value) if cell_type == 'float' and self.__auto_detect_int: - if _is_integer_ok_for_xl_float(n_value): + if service.has_no_digits_in_float(n_value): n_value = int(n_value) ret = n_value else: @@ -161,8 +159,3 @@ def _load_from_memory(self): def _load_from_file(self): self._native_book = load(self._file_name) - - -def _is_integer_ok_for_xl_float(value): - """check if a float had zero value in digits""" - return value == math.floor(value) diff --git a/rnd_requirements.txt b/rnd_requirements.txt index 0e70294..3d8132d 100644 --- a/rnd_requirements.txt +++ b/rnd_requirements.txt @@ -1,4 +1,4 @@ https://github.com/chfw/lml/archive/master.zip -https://github.com/pyexcel/pyexcel-io/archive/master.zip +https://github.com/pyexcel/pyexcel-io/archive/dev.zip https://github.com/pyexcel/pyexcel/archive/master.zip -https://github.com/pyexcel/pyexcel-xls/archive/master.zip +https://github.com/pyexcel/pyexcel-xls/archive/dev.zip