Skip to content

Commit

Permalink
make v0.4.x as master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Jun 15, 2017
2 parents f83f41f + ab98fe8 commit def9003
Show file tree
Hide file tree
Showing 20 changed files with 218 additions and 146 deletions.
3 changes: 3 additions & 0 deletions .moban.d/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{%extends 'README.rst.jj2' %}

{%block documentation_link%}
{%endblock%}

{%block description%}
**pyexcel-ods** is a tiny wrapper library to read, manipulate and write data in
ods format using python 2.6 and python 2.7. You are likely to use it with
Expand Down
1 change: 1 addition & 0 deletions .moban.d/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends 'tests/requirements.txt.jj2' %}
{%block extras %}
psutil
pyexcel
pyexcel-xls
{%endblock%}
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ python:
- 2.7
- 2.6
before_install:
- cd $HOME
- "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"
- cd -
- if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install flake8==2.6.2; fi
- if [[ -f min_requirements.txt && "$MINREQ" -eq 1 ]]; then
mv min_requirements.txt requirements.txt ;
fi
- pip install --upgrade setuptools "pip==7.1"
- test ! -f rnd_requirements.txt || pip install --no-deps -r rnd_requirements.txt
- test ! -f rnd_requirements.txt || pip install -r rnd_requirements.txt ;
- pip install -r tests/requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Updated
0.3.1 - 02.02.2017
--------------------------------------------------------------------------------

Updated
Added
********************************************************************************

#. Recognize currency type
Expand Down
23 changes: 16 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pyexcel-ods - Let you focus on data, instead of ods format
.. image:: https://codecov.io/github/pyexcel/pyexcel-ods/coverage.png
:target: https://codecov.io/github/pyexcel/pyexcel-ods


**pyexcel-ods** is a tiny wrapper library to read, manipulate and write data in
ods format using python 2.6 and python 2.7. You are likely to use it with
`pyexcel <https://github.com/pyexcel/pyexcel>`_.
Expand Down Expand Up @@ -41,6 +42,21 @@ or clone it and install it:
$ cd pyexcel-ods
$ python setup.py install
Support the project
================================================================================

If your company has embedded pyexcel and its components into a revenue generating
product, please `support me on patreon <https://www.patreon.com/bePatron?u=5537627>`_ to
maintain the project and develop it further.

If you are an individual, you are welcome to support me too on patreon and for however long
you feel like to. As a patreon, you will receive
`early access to pyexcel related contents <https://www.patreon.com/pyexcel/posts>`_.

With your financial support, I will be able to invest
a little bit more time in coding, documentation and writing interesting posts.


Usage
================================================================================

Expand Down Expand Up @@ -345,10 +361,3 @@ ODSReader is originally written by `Marco Conti <https://github.com/marcoconti83
>>> import os
>>> os.unlink("your_file.ods")
>>> os.unlink("another_file.ods")

Support the project
================================================================================

If your company has embedded pyexcel and its components into a revenue generating
product, please `support me on patreon <https://www.patreon.com/pyexcel>`_ to
maintain the project and develop it further.
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]

intersphinx_mapping = {
'pyexcel': ('http://pyexcel.readthedocs.org/en/latest/', None)
'pyexcel': ('http://pyexcel.readthedocs.org/en/latest/', None),
}
spelling_word_list_filename = 'spelling_wordlist.txt'
templates_path = ['_templates']
Expand All @@ -20,8 +20,8 @@

project = u'pyexcel-ods'
copyright = u'2015-2017 Onni Software Ltd.'
version = '0.3.3'
release = '0.3.3'
version = '0.4.0'
release = '0.4.0'
exclude_patterns = []
pygments_style = 'sphinx'
html_theme = 'default'
Expand Down
6 changes: 3 additions & 3 deletions pyexcel_ods.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
overrides: "pyexcel.yaml"
name: "pyexcel-ods"
nick_name: ods
version: 0.3.3
release: 0.3.3
version: 0.4.0
release: 0.4.0
file_type: ods
dependencies:
- pyexcel-io>=0.3.0
- pyexcel-io>=0.4.0
- odfpy>=1.3.3
description: A wrapper library to read, manipulate and write data in ods format
21 changes: 12 additions & 9 deletions pyexcel_ods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
# flake8: noqa
# this line has to be place above all else
# because of dynamic import
__FILE_TYPE__ = 'ods'
__META__ = {
'submodule': __FILE_TYPE__,
'file_types': [__FILE_TYPE__],
'stream_type': 'binary'
}
__pyexcel_io_plugins__ = [__META__]


from pyexcel_io.plugins import IOPluginInfoChain
from pyexcel_io.io import get_data as read_data, isstream, store_data as write_data

__FILE_TYPE__ = 'ods'
IOPluginInfoChain(__name__).add_a_reader(
relative_plugin_class_path='odsr.ODSBook',
file_types=[__FILE_TYPE__],
stream_type='binary'
).add_a_writer(
relative_plugin_class_path='odsw.ODSWriter',
file_types=[__FILE_TYPE__],
stream_type='binary'
)


def save_data(afile, data, file_type=None, **keywords):
"""standalone module function for writing module supported file type"""
Expand Down
115 changes: 16 additions & 99 deletions pyexcel_ods/ods.py → pyexcel_ods/odsr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
"""
pyexcel_ods.odsr
~~~~~~~~~~~~~~~~~~~~~
ods reader
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
# Copyright 2011 Marco Conti

# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,27 +22,19 @@
# limitations under the License.

# Thanks to grt for the fixes
import sys
import math

from odf.table import TableRow, TableCell, Table
from odf.text import P
from odf.namespaces import OFFICENS
from odf.opendocument import OpenDocumentSpreadsheet, load
from odf.opendocument import load

from pyexcel_io.book import BookReader, BookWriter
from pyexcel_io.sheet import SheetReader, SheetWriter
from pyexcel_io.book import BookReader
from pyexcel_io.sheet import SheetReader
from pyexcel_io._compact import OrderedDict, PY2

import pyexcel_ods.converter as converter

PY2 = sys.version_info[0] == 2

PY27_BELOW = PY2 and sys.version_info[1] < 7
if PY27_BELOW:
from ordereddict import OrderedDict
else:
from collections import OrderedDict


class ODSSheet(SheetReader):
"""native ods sheet"""
Expand Down Expand Up @@ -115,7 +116,6 @@ def __read_cell(self, cell):

class ODSBook(BookReader):
"""read ods book"""

def open(self, file_name, **keywords):
"""open ods file"""
BookReader.open(self, file_name, **keywords)
Expand Down Expand Up @@ -160,99 +160,16 @@ def read_sheet(self, native_sheet):
sheet = ODSSheet(native_sheet, **self._keywords)
return {sheet.name: sheet.to_array()}

def close(self):
self._native_book = None

def _load_from_memory(self):
self._native_book = load(self._file_stream)

def _load_from_file(self):
self._native_book = load(self._file_name)


class ODSSheetWriter(SheetWriter):
"""
ODS sheet writer
"""
def set_sheet_name(self, name):
"""initialize the native table"""
self._native_sheet = Table(name=name)

def set_size(self, size):
"""not used in this class but used in ods3"""
pass

def write_cell(self, row, cell):
"""write a native cell"""
cell_to_be_written = TableCell()
cell_type = type(cell)
cell_odf_type = converter.ODS_WRITE_FORMAT_COVERSION.get(
cell_type, "string")
cell_to_be_written.setAttrNS(OFFICENS, "value-type", cell_odf_type)
cell_odf_value_token = converter.VALUE_TOKEN.get(
cell_odf_type, "value")
converter_func = converter.ODS_VALUE_CONVERTERS.get(
cell_odf_type, None)
if converter_func:
cell = converter_func(cell)
if cell_odf_type != 'string':
cell_to_be_written.setAttrNS(OFFICENS, cell_odf_value_token, cell)
cell_to_be_written.addElement(P(text=cell))
else:
lines = cell.split('\n')
for line in lines:
cell_to_be_written.addElement(P(text=line))
row.addElement(cell_to_be_written)

def write_row(self, array):
"""
write a row into the file
"""
row = TableRow()
self._native_sheet.addElement(row)
for cell in array:
self.write_cell(row, cell)

def close(self):
"""
This call writes file
"""
self._native_book.spreadsheet.addElement(self._native_sheet)


class ODSWriter(BookWriter):
"""
open document spreadsheet writer
"""
def __init__(self):
BookWriter.__init__(self)
self._native_book = OpenDocumentSpreadsheet()

def create_sheet(self, name):
"""
write a row into the file
"""
return ODSSheetWriter(self._native_book, None, name)

def close(self):
"""
This call writes file
"""
self._native_book.write(self._file_alike_object)


def is_integer_ok_for_xl_float(value):
"""check if a float had zero value in digits"""
return value == math.floor(value)


_ods_registry = {
"file_type": "ods",
"reader": ODSBook,
"writer": ODSWriter,
"stream_type": "binary",
"mime_type": "application/vnd.oasis.opendocument.spreadsheet",
"library": "pyexcel-ods"
}

exports = (_ods_registry,)
Loading

0 comments on commit def9003

Please sign in to comment.