Skip to content

Commit c9f9f9e

Browse files
committed
make v0.4.x as master branch
2 parents af39fff + cd84aed commit c9f9f9e

16 files changed

+208
-147
lines changed

.moban.d/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{%extends 'README.rst.jj2' %}
22

3+
4+
{%block documentation_link%}
5+
{%endblock%}
6+
37
{%block description%}
48
**pyexcel-ods3** is a tiny wrapper library to read, manipulate and write data in ods
59
format. You are likely to use `pyexcel <https://github.com/pyexcel/pyexcel>`__ together

.moban.d/tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% extends 'tests/requirements.txt.jj2' %}
22
{%block extras %}
3+
psutil
34
pyexcel
45
pyexcel-xls
56
{%endblock%}

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ python:
1010
- 2.7
1111
- 2.6
1212
before_install:
13+
- cd $HOME
14+
- "if [[ $TRAVIS_PYTHON_VERSION == 'pypy' ]]; then deactivate && wget https://bitbucket.org/squeaky/portable-pypy/downloads/pypy-5.7.1-linux_x86_64-portable.tar.bz2 -O - | tar -jxf - && echo 'Setting up aliases...' && ln -s pypy-5.7.1-linux_x86_64-portable pypy2-latest && export PATH=$HOME/pypy2-latest/bin/:$PATH && virtualenv --no-site-packages --python ~/pypy2-latest/bin/pypy pypy2-env && echo 'Creating custom env...' && source pypy2-env/bin/activate && python -V; fi"
15+
- cd -
1316
- if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install ordereddict; fi
1417
- if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install weakrefset; fi
1518
- if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install flake8==2.6.2; fi
1619
- if [[ -f min_requirements.txt && "$MINREQ" -eq 1 ]]; then
1720
mv min_requirements.txt requirements.txt ;
1821
fi
19-
- pip install --upgrade setuptools "pip==7.1"
2022
- test ! -f rnd_requirements.txt || pip install --no-deps -r rnd_requirements.txt
2123
- test ! -f rnd_requirements.txt || pip install -r rnd_requirements.txt ;
2224
- pip install -r tests/requirements.txt

README.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ pyexcel-ods3 - Let you focus on data, instead of ods format
1111
.. image:: https://codecov.io/github/pyexcel/pyexcel-ods3/coverage.png
1212
:target: https://codecov.io/github/pyexcel/pyexcel-ods3
1313

14-
.. image:: https://readthedocs.org/projects/pyexcel-ods3/badge/?version=latest
15-
:target: http://pyexcel-ods3.readthedocs.org/en/latest/
1614

1715
**pyexcel-ods3** is a tiny wrapper library to read, manipulate and write data in ods
1816
format. You are likely to use `pyexcel <https://github.com/pyexcel/pyexcel>`__ together
@@ -40,10 +38,25 @@ or clone it and install it:
4038

4139
.. code-block:: bash
4240
43-
$ git clone http://github.com/pyexcel/pyexcel-ods3.git
41+
$ git clone https://github.com/pyexcel/pyexcel-ods3.git
4442
$ cd pyexcel-ods3
4543
$ python setup.py install
4644
45+
Support the project
46+
================================================================================
47+
48+
If your company has embedded pyexcel and its components into a revenue generating
49+
product, please `support me on patreon <https://www.patreon.com/bePatron?u=5537627>`_ to
50+
maintain the project and develop it further.
51+
52+
If you are an individual, you are welcome to support me too on patreon and for however long
53+
you feel like to. As a patreon, you will receive
54+
`early access to pyexcel related contents <https://www.patreon.com/pyexcel/posts>`_.
55+
56+
With your financial support, I will be able to invest
57+
a little bit more time in coding, documentation and writing interesting posts.
58+
59+
4760
Usage
4861
================================================================================
4962

@@ -351,9 +364,3 @@ The installation of `lxml` will be tricky on Windows platform. It is recommended
351364
>>> import os
352365
>>> os.unlink("your_file.ods")
353366
>>> os.unlink("another_file.ods")
354-
355-
Support the project
356-
================================================================================
357-
358-
If your company has embedded pyexcel and its components into a revenue generating
359-
product, please `support me on patreon <https://www.patreon.com/pyexcel>`_.

docs/source/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
]
1212

1313
intersphinx_mapping = {
14-
'pyexcel': ('http://pyexcel.readthedocs.org/en/latest/', None)
14+
'pyexcel': ('http://pyexcel.readthedocs.org/en/latest/', None),
1515
}
1616
spelling_word_list_filename = 'spelling_wordlist.txt'
1717
templates_path = ['_templates']
@@ -20,8 +20,8 @@
2020

2121
project = u'pyexcel-ods3'
2222
copyright = u'2015-2017 Onni Software Ltd.'
23-
version = '0.3.2'
24-
release = '0.3.2'
23+
version = '0.4.0'
24+
release = '0.4.0'
2525
exclude_patterns = []
2626
pygments_style = 'sphinx'
2727
html_theme = 'default'

pyexcel_ods3.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
overrides: "pyexcel.yaml"
22
name: "pyexcel-ods3"
33
nick_name: ods3
4-
version: 0.3.2
5-
release: 0.3.2
4+
version: 0.4.0
5+
release: 0.4.0
66
file_type: ods
77
dependencies:
8-
- pyexcel-io>=0.3.0
8+
- pyexcel-io>=0.4.0
99
- lxml
1010
- ezodf>=0.3.2
1111
- weakrefset;python_version<"2.7"

pyexcel_ods3/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
# flake8: noqa
1111
# this line has to be place above all else
1212
# because of dynamic import
13-
__FILE_TYPE__ = 'ods'
14-
__META__ = {
15-
'submodule': __FILE_TYPE__,
16-
'file_types': [__FILE_TYPE__],
17-
'stream_type': 'binary'
18-
}
19-
__pyexcel_io_plugins__ = [__META__]
20-
21-
13+
from pyexcel_io.plugins import IOPluginInfoChain
2214
from pyexcel_io.io import get_data as read_data, isstream, store_data as write_data
2315

16+
__FILE_TYPE__ = 'ods'
17+
IOPluginInfoChain(__name__).add_a_reader(
18+
relative_plugin_class_path='odsr.ODSBook',
19+
file_types=[__FILE_TYPE__],
20+
stream_type='binary'
21+
).add_a_writer(
22+
relative_plugin_class_path='odsw.ODSWriter',
23+
file_types=[__FILE_TYPE__],
24+
stream_type='binary'
25+
)
26+
2427

2528
def save_data(afile, data, file_type=None, **keywords):
2629
"""standalone module function for writing module supported file type"""
Lines changed: 11 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
"""
2-
pyexcel_ods3.ods
2+
pyexcel_ods3.odsr
33
~~~~~~~~~~~~~~~~~~~
44
5-
ODS format plugin for pyexcel
5+
ods reader
66
77
:copyright: (c) 2015-2017 by Onni Software Ltd. & its contributors
88
:license: New BSD License
99
"""
10-
import sys
1110
import math
12-
import types
1311

1412
import ezodf
15-
from pyexcel_io.book import BookReader, BookWriter
16-
from pyexcel_io.sheet import SheetReader, SheetWriter
1713

18-
import pyexcel_ods3.converter as converter
14+
from pyexcel_io.sheet import SheetReader
15+
from pyexcel_io.book import BookReader
16+
from pyexcel_io._compact import OrderedDict
1917

20-
PY27_BELOW = sys.version_info[0] == 2 and sys.version_info[1] < 7
21-
if PY27_BELOW:
22-
from ordereddict import OrderedDict
23-
else:
24-
from collections import OrderedDict
18+
import pyexcel_ods3.converter as converter
2519

2620

2721
class ODSSheet(SheetReader):
@@ -73,7 +67,6 @@ def cell_value(self, row, column):
7367

7468
class ODSBook(BookReader):
7569
"""read a ods book out"""
76-
7770
def open(self, file_name, **keywords):
7871
"""load ods from file"""
7972
BookReader.open(self, file_name, **keywords)
@@ -103,8 +96,8 @@ def read_sheet_by_index(self, sheet_index):
10396
if sheet_index < length:
10497
return self.read_sheet(sheets[sheet_index])
10598
else:
106-
raise IndexError("Index %d of out bound %d." % (sheet_index,
107-
length))
99+
raise IndexError("Index %d of out bound %d." % (
100+
sheet_index, length))
108101

109102
def read_all(self):
110103
"""read all available sheets"""
@@ -118,110 +111,16 @@ def read_sheet(self, native_sheet):
118111
sheet = ODSSheet(native_sheet, **self._keywords)
119112
return {native_sheet.name: sheet.to_array()}
120113

114+
def close(self):
115+
self._native_book = None
116+
121117
def _load_from_file(self):
122118
self._native_book = ezodf.opendoc(self._file_name)
123119

124120
def _load_from_memory(self):
125121
self._native_book = ezodf.opendoc(self._file_stream)
126122

127123

128-
class ODSSheetWriter(SheetWriter):
129-
"""
130-
ODS sheet writer
131-
"""
132-
def set_sheet_name(self, name):
133-
self._native_sheet = ezodf.Sheet(name)
134-
self.current_row = 0
135-
136-
def set_size(self, size):
137-
self._native_sheet.reset(size=size)
138-
139-
def write_row(self, array):
140-
"""
141-
write a row into the file
142-
"""
143-
count = 0
144-
for cell in array:
145-
value_type = converter.ODS_WRITE_FORMAT_COVERSION[type(cell)]
146-
if value_type == "time":
147-
cell = cell.strftime("PT%HH%MM%SS")
148-
elif value_type == "timedelta":
149-
hours = cell.days * 24 + cell.seconds // 3600
150-
minutes = (cell.seconds // 60) % 60
151-
seconds = cell.seconds % 60
152-
cell = "PT%02dH%02dM%02dS" % (hours, minutes, seconds)
153-
value_type = "time"
154-
self._native_sheet[self.current_row, count].set_value(
155-
cell,
156-
value_type=value_type)
157-
count += 1
158-
self.current_row += 1
159-
160-
def write_array(self, table):
161-
to_write_data = table
162-
if isinstance(to_write_data, types.GeneratorType):
163-
to_write_data = list(table)
164-
rows = len(to_write_data)
165-
if rows < 1:
166-
return
167-
columns = max([len(row) for row in to_write_data])
168-
self.set_size((rows, columns))
169-
for row in to_write_data:
170-
self.write_row(row)
171-
172-
def close(self):
173-
"""
174-
This call writes file
175-
176-
"""
177-
self._native_book.sheets += self._native_sheet
178-
179-
180-
class ODSWriter(BookWriter):
181-
"""
182-
open document spreadsheet writer
183-
184-
"""
185-
def __init__(self):
186-
BookWriter.__init__(self)
187-
self._native_book = None
188-
189-
def open(self, file_name, **keywords):
190-
"""open a file for writing ods"""
191-
BookWriter.open(self, file_name, **keywords)
192-
self._native_book = ezodf.newdoc(
193-
doctype="ods", filename=self._file_alike_object)
194-
195-
skip_backup_flag = self._keywords.get('skip_backup', True)
196-
if skip_backup_flag:
197-
self._native_book.backup = False
198-
199-
def create_sheet(self, name):
200-
"""
201-
write a row into the file
202-
"""
203-
return ODSSheetWriter(self._native_book, None, name)
204-
205-
def close(self):
206-
"""
207-
This call writes file
208-
209-
"""
210-
self._native_book.save()
211-
212-
213124
def is_integer_ok_for_xl_float(value):
214125
"""check if a float had zero value in digits"""
215126
return value == math.floor(value)
216-
217-
218-
_ods_registry = {
219-
"file_type": "ods",
220-
"reader": ODSBook,
221-
"writer": ODSWriter,
222-
"stream_type": "binary",
223-
"mime_type": "application/vnd.oasis.opendocument.spreadsheet",
224-
"library": "pyexcel-ods3"
225-
}
226-
227-
exports = (_ods_registry, )

0 commit comments

Comments
 (0)