Skip to content

Commit

Permalink
Merge pull request #43 from thombashi/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
thombashi committed Sep 18, 2016
2 parents c31f96b + f2999e3 commit 0406aca
Show file tree
Hide file tree
Showing 33 changed files with 853 additions and 129 deletions.
24 changes: 17 additions & 7 deletions README.rst
Expand Up @@ -26,6 +26,7 @@ Feature
- tuple
- Create table(s) from:
- CSV file/text
- HTML file/text
- JSON file/text
- Microsoft Excel :superscript:`TM` file
- `Google Sheets <https://www.google.com/intl/en_us/sheets/about/>`_
Expand Down Expand Up @@ -197,14 +198,23 @@ Installation
Dependencies
============

Python 2.7 or 3.3+
Python 2.7+ or 3.3+

- `DataPropery <https://github.com/thombashi/DataProperty>`__ (Used to extract data types)
- `jsonschema <https://github.com/Julian/jsonschema>`__
- `pathvalidate <https://github.com/thombashi/pathvalidate>`__
- `path.py <https://github.com/jaraco/path.py>`__
- `six <https://pypi.python.org/pypi/six/>`__
- `xlrd <https://github.com/python-excel/xlrd>`__
Mandatory
-----------------

- `beautifulsoup4 <https://www.crummy.com/software/BeautifulSoup/>`__
- `DataPropery <https://github.com/thombashi/DataProperty>`__ (Used to extract data types)
- `jsonschema <https://github.com/Julian/jsonschema>`__
- `pathvalidate <https://github.com/thombashi/pathvalidate>`__
- `path.py <https://github.com/jaraco/path.py>`__
- `six <https://pypi.python.org/pypi/six/>`__
- `xlrd <https://github.com/python-excel/xlrd>`__

Optional
-----------------

- `lxml <http://lxml.de/installation.html>`__ (Faster HTML convert if installed)


Test dependencies
Expand Down
13 changes: 12 additions & 1 deletion docs/conf.py
Expand Up @@ -373,6 +373,16 @@
If the open |attr_mode| is neither ``"w"`` nor ``"a"``.
"""

rp_template = u"""
.. |tnt_filename| replace:: %(filename)s
.. |tnt_format_name| replace:: %(format_name)s
.. |tnt_format_id| replace:: %(format_id)s
.. |tnt_global_id| replace:: %(global_id)s
.. |tnt_key| replace:: %(key)s
.. |tnt_title| replace:: %(title)s
.. |tnt_sheet| replace:: %(sheet)s
"""

rst_prolog = (
rp_common +
rp_builtin +
Expand All @@ -381,5 +391,6 @@
rp_module +
rp_raises +
rp_attr +
rp_method
rp_method +
rp_template
)
25 changes: 17 additions & 8 deletions docs/pages/installation.rst
Expand Up @@ -9,14 +9,23 @@ Installation
Dependencies
============

Python 2.7 or 3.3+

- `DataPropery <https://github.com/thombashi/DataProperty>`__ (Used to extract data types)
- `jsonschema <https://github.com/Julian/jsonschema>`__
- `pathvalidate <https://github.com/thombashi/pathvalidate>`__
- `path.py <https://github.com/jaraco/path.py>`__
- `six <https://pypi.python.org/pypi/six/>`__
- `xlrd <https://github.com/python-excel/xlrd>`__
Python 2.7+ or 3.3+

Mandatory
-----------------

- `beautifulsoup4 <https://www.crummy.com/software/BeautifulSoup/>`__
- `DataPropery <https://github.com/thombashi/DataProperty>`__ (Used to extract data types)
- `jsonschema <https://github.com/Julian/jsonschema>`__
- `pathvalidate <https://github.com/thombashi/pathvalidate>`__
- `path.py <https://github.com/jaraco/path.py>`__
- `six <https://pypi.python.org/pypi/six/>`__
- `xlrd <https://github.com/python-excel/xlrd>`__

Optional
-----------------

- `lxml <http://lxml.de/installation.html>`__ (Faster HTML convert if installed)


Test dependencies
Expand Down
1 change: 1 addition & 0 deletions docs/pages/introduction/feature.txt
Expand Up @@ -9,6 +9,7 @@ Feature
- tuple
- Create table(s) from:
- CSV file/text
- HTML file/text
- JSON file/text
- Microsoft Excel :superscript:`TM` file
- `Google Sheets <https://www.google.com/intl/en_us/sheets/about/>`_
18 changes: 18 additions & 0 deletions docs/pages/reference/loader.rst
Expand Up @@ -43,6 +43,24 @@ CsvTableTextLoader class
:undoc-members:
:show-inheritance:


HtmlTableFileLoader class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: simplesqlite.loader.HtmlTableFileLoader
:inherited-members:
:undoc-members:
:show-inheritance:


HtmlTableTextLoader class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: simplesqlite.loader.HtmlTableTextLoader
:inherited-members:
:undoc-members:
:show-inheritance:


JsonTableFileLoader class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions requirements/requirements.txt
@@ -1,3 +1,4 @@
beautifulsoup4
DataProperty>=0.8.1
jsonschema
pathvalidate>=0.5.1
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -23,7 +23,7 @@

setuptools.setup(
name="SimpleSQLite",
version="0.4.8",
version="0.5.0",
url="https://github.com/thombashi/SimpleSQLite",
bugtrack_url="https://github.com/thombashi/SimpleSQLite/issues",

Expand All @@ -32,7 +32,7 @@
description=summary,
include_package_data=True,
install_requires=install_requires,
keywords=["SQLite", "CSV", "JSON", "Excel", "Google Sheets"],
keywords=["SQLite", "CSV", "Excel", "Google Sheets", "HTML", "JSON"],
long_description=long_description,
license="MIT License",
packages=setuptools.find_packages(exclude=["test*"]),
Expand Down
1 change: 0 additions & 1 deletion simplesqlite/core.py
Expand Up @@ -8,7 +8,6 @@
import logging
import os
import sqlite3
import sys

import dataproperty
import pathvalidate
Expand Down
3 changes: 2 additions & 1 deletion simplesqlite/loader/__init__.py
Expand Up @@ -4,7 +4,6 @@
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""


from __future__ import absolute_import

from .error import ValidationError
Expand All @@ -13,6 +12,8 @@

from .csv.core import CsvTableFileLoader
from .csv.core import CsvTableTextLoader
from .html.core import HtmlTableFileLoader
from .html.core import HtmlTableTextLoader
from .spreadsheet.excelloader import ExcelTableFileLoader
from .spreadsheet.gsloader import GoogleSheetsTableLoader
from .json.core import JsonTableFileLoader
Expand Down
1 change: 0 additions & 1 deletion simplesqlite/loader/acceptor.py
Expand Up @@ -4,7 +4,6 @@
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""


from __future__ import absolute_import
import abc

Expand Down
19 changes: 19 additions & 0 deletions simplesqlite/loader/constant.py
@@ -0,0 +1,19 @@
# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""

from __future__ import absolute_import


class TableNameTemplate(object):
__FORMAT = "%({:s})s"
DEFAULT = __FORMAT.format("default")
FILENAME = __FORMAT.format("filename")
FORMAT_NAME = __FORMAT.format("format_name")
FORMAT_ID = __FORMAT.format("format_id")
GLOBAL_ID = __FORMAT.format("global_id")
KEY = __FORMAT.format("key")
TITLE = __FORMAT.format("title")
SHEET = __FORMAT.format("sheet")
41 changes: 27 additions & 14 deletions simplesqlite/loader/csv/core.py
Expand Up @@ -4,14 +4,12 @@
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""


from __future__ import absolute_import
import csv

import dataproperty
import path
import six

from ..constant import TableNameTemplate as tnt
from ..interface import TableLoader
from .formatter import CsvTableFormatter

Expand Down Expand Up @@ -52,6 +50,10 @@ def __init__(self, source):
self.quotechar = '"'
self.encoding = "utf-8"

@property
def format_name(self):
return "csv"

def _to_data_matrix(self):
from dataproperty.type import FloatTypeChecker

Expand All @@ -76,26 +78,25 @@ class CsvTableFileLoader(CsvTableLoader):

def __init__(self, file_path=None):
super(CsvTableFileLoader, self).__init__(file_path)
self.table_name = "%(filename)s"

def make_table_name(self):
"""
|make_table_name|
================ ===========================
format specifier value after the replacement
================ ===========================
``%(filename)s`` filename
================ ===========================
=================== ==================================
format specifier value after the replacement
=================== ==================================
``%(filename)s`` filename (without extention)
``%(format_name)s`` ``csv``
``%(format_id)s`` unique number in the same format
``%(global_id)s`` unique number in all of the format
=================== ==================================
:return: Table name.
:rtype: str
"""

self._validate()

return self.table_name.replace(
"%(filename)s", path.Path(self.source).namebase)
return self._make_file_table_name()

def load(self):
"""
Expand All @@ -122,10 +123,17 @@ def load(self):

return formatter.to_table_data()

def _get_default_table_name_template(self):
return tnt.FILENAME


class CsvTableTextLoader(CsvTableLoader):
"""
Concrete class of CSV text loader.
.. py:attribute:: table_name
Table name string. Defaults to ``%(format_name)s%(format_id)s``.
"""

def __init__(self, text):
Expand All @@ -140,7 +148,9 @@ def load(self):
:raises simplesqlite.loader.InvalidDataError:
If the CSV data is invalid.
.. seealso:: :py:func:`csv.reader`
.. seealso::
:py:func:`csv.reader`
:py:meth:`~.CsvTableFileLoader.make_table_name`
"""

self._validate()
Expand All @@ -152,3 +162,6 @@ def load(self):
formatter.accept(self)

return formatter.to_table_data()

def _get_default_table_name_template(self):
return "{:s}{:s}".format(tnt.FORMAT_NAME, tnt.FORMAT_ID)
3 changes: 2 additions & 1 deletion simplesqlite/loader/csv/formatter.py
Expand Up @@ -4,7 +4,6 @@
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""


from __future__ import absolute_import

import dataproperty
Expand Down Expand Up @@ -38,6 +37,8 @@ def to_table_data(self):
raise InvalidDataError(
"data row must be greater or equal than one")

self._loader.inc_table_count()

yield TableData(
self._loader.make_table_name(),
header_list, data_matrix)
Expand Down
1 change: 0 additions & 1 deletion simplesqlite/loader/data.py
Expand Up @@ -4,7 +4,6 @@
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""


from __future__ import absolute_import
import collections

Expand Down
3 changes: 1 addition & 2 deletions simplesqlite/loader/error.py
Expand Up @@ -4,7 +4,6 @@
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""


from __future__ import absolute_import


Expand All @@ -14,7 +13,7 @@ class ValidationError(Exception):
"""


class InvalidDataError(Exception):
class InvalidDataError(ValueError):
"""
Raised when data is invalid to load.
"""
Expand Down
3 changes: 1 addition & 2 deletions simplesqlite/loader/formatter.py
Expand Up @@ -4,10 +4,9 @@
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""


from __future__ import absolute_import

import abc

import six

from .acceptor import LoaderAcceptor
Expand Down
Empty file.

0 comments on commit 0406aca

Please sign in to comment.