Commit d4bcf71d by Long Phan

up

parents
Aeroo Library developed by:
Alistek Ltd. <info@alistek.com>
relatorio is the work of:
Nicolas Évrard <nicoe@openhex.org>
Gaëtan de Menten <gdementen@openhex.org>
We included ideas and patches from:
Cédric Krier <cedric.krier@b2ck.com>
Udo Spallek <udono@virtual-things.biz>
1.0.0 - 20101215
Initial version
This diff is collapsed. Click to expand it.
include AUTHORS
include CHANGES
include LICENSE
Aeroo Library
=========
Aeroo Library is a templating library which provides a way to easily output several
kinds of files (odt, ods). Support for more filetypes can be easily added by
creating plugins for them.
Aeroo Library also provides a report repository allowing you to link python objects
and report together, find reports by mimetype/name/python object.
\ No newline at end of file
Metadata-Version: 1.1
Name: aeroolib
Version: 1.2.0
Summary: A templating library able to output ODF files
Home-page: http://www.alistek.com/
Author: Alistek Ltd
Author-email: info@alistek.com
License: GPL License
Description-Content-Type: UNKNOWN
Description:
aeroolib
=========
A templating library which provides a way to easily output all kind of
different files (odt, ods). Adding support for more filetype is easy:
you just have to create a plugin for this.
aeroolib also provides a report repository allowing you to link python objects
and report together, find reports by mimetypes/name/python objects.
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing
AUTHORS
CHANGES
LICENSE
MANIFEST.in
README
setup.cfg
setup.py
aeroolib/__init__.py
aeroolib/reporting.py
aeroolib.egg-info/PKG-INFO
aeroolib.egg-info/SOURCES.txt
aeroolib.egg-info/dependency_links.txt
aeroolib.egg-info/requires.txt
aeroolib.egg-info/top_level.txt
aeroolib/plugins/__init__.py
aeroolib/plugins/base.py
aeroolib/plugins/opendocument.py
\ No newline at end of file
"""
Aeroo Library
=========
A templating library which provides a way to easily output all kind of
different files (odt, ods). Adding support for more filetype is
easy: you just have to create a plugin for this.
Is based on Relatorio project
aeroolib also provides a report repository allowing you to link python objects
and report together, find reports by mimetypes/name/python objects.
"""
from aeroolib.reporting import MIMETemplateLoader, ReportRepository, Report
import plugins
__version__ = '1.2.0'
##############################################################################
#
# Copyright (c) 2010 Alistek Ltd. (http://www.alistek.com) All Rights
# Reserved.
# General contacts <info@alistek.com>
#
# DISCLAIMER: This module is licensed under GPLv3 or newer and
# is considered incompatible with OpenERP SA "AGPL + Private Use License"!
#
# Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights
# Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import traceback
import warnings
from cStringIO import StringIO
plugins = ['base', 'opendocument']
for name in plugins:
try:
__import__('aeroolib.plugins.%s' % name)
except Exception, e:
tb_file = StringIO()
print >> tb_file, ("Unable to load plugin '%s', you will not be able "
"to use it" % name)
print >> tb_file
print >> tb_file, 'Original traceback:'
print >> tb_file, '-------------------'
traceback.print_exc(file=tb_file)
print >> tb_file
warnings.warn(tb_file.getvalue())
##############################################################################
#
# Copyright (c) 2012 Alistek Ltd (http://www.alistek.com) All Rights
# Reserved.
# General contacts <info@alistek.com>
#
# DISCLAIMER: This module is licensed under GPLv3 or newer and
# is considered incompatible with OpenERP SA "AGPL + Private Use License"!
#
# Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights
# Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
__metaclass__ = type
from cStringIO import OutputType
import genshi.core
from genshi.template import NewTextTemplate, MarkupTemplate
from aeroolib.reporting import Report, MIMETemplateLoader
class AerooStream(genshi.core.Stream):
"Base class for the aeroo streams."
def render(self, method=None, encoding='utf-8', out=None, **kwargs):
"calls the serializer to render the template"
return self.serializer(self.events)
def serialize(self, method='xml', **kwargs):
"generates the bitstream corresponding to the template"
return self.render(method, **kwargs)
def __or__(self, function):
"Support for the bitwise operator"
return AerooStream(self.events | function, self.serializer)
def __str__(self):
val = self.render()
if isinstance(val, OutputType):
return val.getvalue()
else:
return val
MIMETemplateLoader.add_factory('text', NewTextTemplate)
MIMETemplateLoader.add_factory('xml', MarkupTemplate)
##############################################################################
#
# Copyright (c) 2010 Alistek Ltd. (http://www.alistek.com) All Rights
# Reserved.
# General contacts <info@alistek.com>
#
# DISCLAIMER: This module is licensed under GPLv3 or newer and
# is considered incompatible with OpenERP SA "AGPL + Private Use License"!
#
# Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights
# Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
__metaclass__ = type
import os, sys
import pkg_resources
from genshi.template import TemplateLoader
def _absolute(path):
"Compute the absolute path of path relative to the caller file"
if os.path.isabs(path):
return path
caller_fname = sys._getframe(2).f_globals['__file__']
caller_dir = os.path.dirname(caller_fname)
return os.path.abspath(os.path.join(caller_dir, path))
def _guess_type(mime):
"""
Returns the codename used by aeroolib to identify which template plugin
it should use to render a mimetype
"""
mime = mime.lower()
major, stype = mime.split('/', 1)
if major == 'application':
if 'opendocument' in stype:
return 'oo.org'
else:
return stype
elif major == 'text':
if stype in ('xml', 'html', 'xhtml'):
return 'markup'
else:
return 'text'
class MIMETemplateLoader(TemplateLoader):
"""This subclass of TemplateLoader use mimetypes to search and find
templates to load.
"""
factories = {}
mime_func = [_guess_type]
def get_type(self, mime):
"finds the codename used by aeroolib to work on a mimetype"
for func in reversed(self.mime_func):
codename = func(mime)
if codename is not None:
return codename
def load(self, path, mime=None, relative_to=None, cls=None):
"returns a template object based on path"
assert mime is not None or cls is not None
if mime is not None:
cls = self.factories[self.get_type(mime)]
return super(MIMETemplateLoader, self).load(
path, cls=cls, relative_to=relative_to)
@classmethod
def add_factory(cls, abbr_mimetype, template_factory, id_function=None):
"""adds a template factory to the already known factories"""
cls.factories[abbr_mimetype] = template_factory
if id_function is not None:
cls.mime_func.append(id_function)
default_loader = MIMETemplateLoader(auto_reload=True)
class DefaultFactory:
"""This is the default factory used by aeroolib.
It just returns a copy of the data it receives"""
def __init__(self, *args, **kwargs):
pass
def __call__(self, **kwargs):
data = kwargs.copy()
return data
default_factory = DefaultFactory()
class Report:
"""Report is a simple interface on top of a rendering template.
"""
def __init__(self, path, mimetype,
factory=default_factory, loader=default_loader):
self.fpath = path
self.mimetype = mimetype
self.data_factory = factory
self.tmpl_loader = loader
self.filters = []
def __call__(self, **kwargs):
template = self.tmpl_loader.load(self.fpath, self.mimetype)
data = self.data_factory(**kwargs)
return template.generate(**data).filter(*self.filters)
def __repr__(self):
return '<aeroo report on %s>' % self.fpath
class ReportDict:
def __init__(self, *args, **kwargs):
self.mimetypes = {}
self.ids = {}
class ReportRepository:
"""ReportRepository stores the report definition associated to objects.
The report are indexed in this object by the object class they are working
on and the name given to it by the user.
"""
def __init__(self, datafactory=DefaultFactory):
self.classes = {}
self.default_factory = datafactory
self.loader = default_loader
def add_report(self, klass, mimetype, template_path, data_factory=None,
report_name='default', description=''):
"""adds a report to the repository.
You will be able to find the report via
- the class it is working on
- the mimetype it outputs
- the name of the report
You also have the opportunity to define a specific data_factory.
"""
if data_factory is None:
data_factory = self.default_factory
reports = self.classes.setdefault(klass, ReportDict())
report = Report(_absolute(template_path), mimetype,
data_factory(klass, mimetype), self.loader)
reports.ids[report_name] = report, mimetype, description
reports.mimetypes.setdefault(mimetype, []) \
.append((report, report_name))
def by_mime(self, klass, mimetype):
"""gets a list of report related to a class by specifying the mimetype
"""
return self.classes[klass].mimetypes[mimetype]
def by_id(self, klass, id):
"""get a report related to a class by its id
"""
return self.classes[klass].ids[id]
"""
Aeroo Library
=========
A templating library which provides a way to easily output all kind of
different files (odt, ods). Adding support for more filetype is
easy: you just have to create a plugin for this.
Is based on Relatorio project
aeroolib also provides a report repository allowing you to link python objects
and report together, find reports by mimetypes/name/python objects.
"""
from aeroolib.reporting import MIMETemplateLoader, ReportRepository, Report
import plugins
__version__ = '1.2.0'
##############################################################################
#
# Copyright (c) 2010 Alistek Ltd. (http://www.alistek.com) All Rights
# Reserved.
# General contacts <info@alistek.com>
#
# DISCLAIMER: This module is licensed under GPLv3 or newer and
# is considered incompatible with OpenERP SA "AGPL + Private Use License"!
#
# Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights
# Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import traceback
import warnings
from cStringIO import StringIO
plugins = ['base', 'opendocument']
for name in plugins:
try:
__import__('aeroolib.plugins.%s' % name)
except Exception, e:
tb_file = StringIO()
print >> tb_file, ("Unable to load plugin '%s', you will not be able "
"to use it" % name)
print >> tb_file
print >> tb_file, 'Original traceback:'
print >> tb_file, '-------------------'
traceback.print_exc(file=tb_file)
print >> tb_file
warnings.warn(tb_file.getvalue())
##############################################################################
#
# Copyright (c) 2012 Alistek Ltd (http://www.alistek.com) All Rights
# Reserved.
# General contacts <info@alistek.com>
#
# DISCLAIMER: This module is licensed under GPLv3 or newer and
# is considered incompatible with OpenERP SA "AGPL + Private Use License"!
#
# Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights
# Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
__metaclass__ = type
from cStringIO import OutputType
import genshi.core
from genshi.template import NewTextTemplate, MarkupTemplate
from aeroolib.reporting import Report, MIMETemplateLoader
class AerooStream(genshi.core.Stream):
"Base class for the aeroo streams."
def render(self, method=None, encoding='utf-8', out=None, **kwargs):
"calls the serializer to render the template"
return self.serializer(self.events)
def serialize(self, method='xml', **kwargs):
"generates the bitstream corresponding to the template"
return self.render(method, **kwargs)
def __or__(self, function):
"Support for the bitwise operator"
return AerooStream(self.events | function, self.serializer)
def __str__(self):
val = self.render()
if isinstance(val, OutputType):
return val.getvalue()
else:
return val
MIMETemplateLoader.add_factory('text', NewTextTemplate)
MIMETemplateLoader.add_factory('xml', MarkupTemplate)
##############################################################################
#
# Copyright (c) 2010 Alistek Ltd. (http://www.alistek.com) All Rights
# Reserved.
# General contacts <info@alistek.com>
#
# DISCLAIMER: This module is licensed under GPLv3 or newer and
# is considered incompatible with OpenERP SA "AGPL + Private Use License"!
#
# Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights
# Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
__metaclass__ = type
import os, sys
import pkg_resources
from genshi.template import TemplateLoader
def _absolute(path):
"Compute the absolute path of path relative to the caller file"
if os.path.isabs(path):
return path
caller_fname = sys._getframe(2).f_globals['__file__']
caller_dir = os.path.dirname(caller_fname)
return os.path.abspath(os.path.join(caller_dir, path))
def _guess_type(mime):
"""
Returns the codename used by aeroolib to identify which template plugin
it should use to render a mimetype
"""
mime = mime.lower()
major, stype = mime.split('/', 1)
if major == 'application':
if 'opendocument' in stype:
return 'oo.org'
else:
return stype
elif major == 'text':
if stype in ('xml', 'html', 'xhtml'):
return 'markup'
else:
return 'text'
class MIMETemplateLoader(TemplateLoader):
"""This subclass of TemplateLoader use mimetypes to search and find
templates to load.
"""
factories = {}
mime_func = [_guess_type]
def get_type(self, mime):
"finds the codename used by aeroolib to work on a mimetype"
for func in reversed(self.mime_func):
codename = func(mime)
if codename is not None:
return codename
def load(self, path, mime=None, relative_to=None, cls=None):
"returns a template object based on path"
assert mime is not None or cls is not None
if mime is not None:
cls = self.factories[self.get_type(mime)]
return super(MIMETemplateLoader, self).load(
path, cls=cls, relative_to=relative_to)
@classmethod
def add_factory(cls, abbr_mimetype, template_factory, id_function=None):
"""adds a template factory to the already known factories"""
cls.factories[abbr_mimetype] = template_factory
if id_function is not None:
cls.mime_func.append(id_function)
default_loader = MIMETemplateLoader(auto_reload=True)
class DefaultFactory:
"""This is the default factory used by aeroolib.
It just returns a copy of the data it receives"""
def __init__(self, *args, **kwargs):
pass
def __call__(self, **kwargs):
data = kwargs.copy()
return data
default_factory = DefaultFactory()
class Report:
"""Report is a simple interface on top of a rendering template.
"""
def __init__(self, path, mimetype,
factory=default_factory, loader=default_loader):
self.fpath = path
self.mimetype = mimetype
self.data_factory = factory
self.tmpl_loader = loader
self.filters = []
def __call__(self, **kwargs):
template = self.tmpl_loader.load(self.fpath, self.mimetype)
data = self.data_factory(**kwargs)
return template.generate(**data).filter(*self.filters)
def __repr__(self):
return '<aeroo report on %s>' % self.fpath
class ReportDict:
def __init__(self, *args, **kwargs):
self.mimetypes = {}
self.ids = {}
class ReportRepository:
"""ReportRepository stores the report definition associated to objects.
The report are indexed in this object by the object class they are working
on and the name given to it by the user.
"""
def __init__(self, datafactory=DefaultFactory):
self.classes = {}
self.default_factory = datafactory
self.loader = default_loader
def add_report(self, klass, mimetype, template_path, data_factory=None,
report_name='default', description=''):
"""adds a report to the repository.
You will be able to find the report via
- the class it is working on
- the mimetype it outputs
- the name of the report
You also have the opportunity to define a specific data_factory.
"""
if data_factory is None:
data_factory = self.default_factory
reports = self.classes.setdefault(klass, ReportDict())
report = Report(_absolute(template_path), mimetype,
data_factory(klass, mimetype), self.loader)
reports.ids[report_name] = report, mimetype, description
reports.mimetypes.setdefault(mimetype, []) \
.append((report, report_name))
def by_mime(self, klass, mimetype):
"""gets a list of report related to a class by specifying the mimetype
"""
return self.classes[klass].mimetypes[mimetype]
def by_id(self, klass, id):
"""get a report related to a class by its id
"""
return self.classes[klass].ids[id]
[egg_info]
import os
import re
from setuptools import setup, find_packages
def get_version():
init = open(os.path.join(os.path.dirname(__file__), 'aeroolib',
'__init__.py')).read()
return re.search(r"""__version__ = '([0-9.\sA-Za-z]*)'""", init).group(1)
setup(
name="aeroolib",
url="http://www.alistek.com/",
author="Alistek Ltd",
author_email="info@alistek.com",
maintainer=u"Alistek Ltd",
maintainer_email="info@alistek.com",
description="A templating library able to output ODF files",
long_description="""
aeroolib
=========
A templating library which provides a way to easily output all kind of
different files (odt, ods). Adding support for more filetype is easy:
you just have to create a plugin for this.
aeroolib also provides a report repository allowing you to link python objects
and report together, find reports by mimetypes/name/python objects.
""",
license="GPL License",
version=get_version(),
packages=find_packages(),
install_requires=[
"Genshi >= 0.5",
"lxml >= 2.0"
],
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing",
],
test_suite="nose.collector",
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment