# HG changeset patch # User Thierry Florac # Date 1425399178 -3600 # Node ID 17f6c240cd7b9492676bc8356a0f970c40ab8469 First commit diff -r 000000000000 -r 17f6c240cd7b .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,19 @@ + +syntax: regexp +^develop-eggs$ +syntax: regexp +^parts$ +syntax: regexp +^bin$ +syntax: regexp +^\.installed\.cfg$ +syntax: regexp +^\.settings$ +syntax: regexp +^build$ +syntax: regexp +^dist$ +syntax: regexp +^\.idea$ +syntax: regexp +.*\.pyc$ diff -r 000000000000 -r 17f6c240cd7b .installed.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.installed.cfg Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,72 @@ +[buildout] +installed_develop_eggs = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/develop-eggs/pyams-alchemy.egg-link +parts = package i18n pyflakes test + +[package] +__buildout_installed__ = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/proutes + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/pdistreport + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/pcreate + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/pshell + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/pserve + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/prequest + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/ptweens + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/pviews +__buildout_signature__ = zc.recipe.egg-2.0.1-py3.4.egg setuptools-12.3-py3.4.egg zc.buildout-2.3.1-py3.4.egg +_b = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin +_d = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/develop-eggs +_e = /var/local/env/pyams/eggs +bin-directory = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin +develop-eggs-directory = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/develop-eggs +eggs = pyams_alchemy + pyramid + sqlalchemy + zope.component + zope.interface +eggs-directory = /var/local/env/pyams/eggs +recipe = zc.recipe.egg + +[i18n] +__buildout_installed__ = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/pybabel + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/pot-create + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/polint +__buildout_signature__ = zc.recipe.egg-2.0.1-py3.4.egg setuptools-12.3-py3.4.egg zc.buildout-2.3.1-py3.4.egg +_b = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin +_d = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/develop-eggs +_e = /var/local/env/pyams/eggs +bin-directory = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin +develop-eggs-directory = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/develop-eggs +eggs = babel + lingua +eggs-directory = /var/local/env/pyams/eggs +recipe = zc.recipe.egg + +[pyflakes] +__buildout_installed__ = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/pyflakes + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/pyflakes +__buildout_signature__ = zc.recipe.egg-2.0.1-py3.4.egg setuptools-12.3-py3.4.egg zc.buildout-2.3.1-py3.4.egg +_b = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin +_d = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/develop-eggs +_e = /var/local/env/pyams/eggs +bin-directory = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin +develop-eggs-directory = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/develop-eggs +eggs = pyflakes +eggs-directory = /var/local/env/pyams/eggs +entry-points = pyflakes=pyflakes.scripts.pyflakes:main +initialization = if not sys.argv[1:]: sys.argv[1:] = ["src"] +recipe = zc.recipe.egg +scripts = pyflakes + +[test] +__buildout_installed__ = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/parts/test + /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/test +__buildout_signature__ = zc.recipe.testrunner-2.0.0-py3.4.egg zc.recipe.egg-2.0.1-py3.4.egg setuptools-12.3-py3.4.egg zope.testrunner-4.4.6-py3.4.egg zc.buildout-2.3.1-py3.4.egg zope.interface-4.1.2-py3.4-linux-x86_64.egg zope.exceptions-4.0.7-py3.4.egg six-8ad56e9feeb914de21341cbb261cc34e +_b = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin +_d = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/develop-eggs +_e = /var/local/env/pyams/eggs +bin-directory = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin +develop-eggs-directory = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/develop-eggs +eggs = pyams_alchemy [test] +eggs-directory = /var/local/env/pyams/eggs +location = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/parts/test +recipe = zc.recipe.testrunner +script = /home/borax/Dropbox/src/PyAMS/pyams_alchemy/bin/test diff -r 000000000000 -r 17f6c240cd7b LICENSE --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,42 @@ +Zope Public License (ZPL) Version 2.1 +===================================== + +A copyright notice accompanies this license document that identifies +the copyright holders. + +This license has been certified as open source. It has also been designated +as GPL compatible by the Free Software Foundation (FSF). + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions in source code must retain the accompanying copyright + notice, this list of conditions, and the following disclaimer. + 2. Redistributions in binary form must reproduce the accompanying copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Names of the copyright holders must not be used to endorse or promote + products derived from this software without prior written permission + from the copyright holders. + 4. The right to distribute this software or to use it for any purpose does + not give you the right to use Servicemarks (sm) or Trademarks (tm) of the + copyright holders. Use of them is covered by separate agreement with the + copyright holders. + 5. If any files are modified, you must cause the modified files to carry + prominent notices stating that you changed the files and the date of any + change. + + +Disclaimer +========== + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff -r 000000000000 -r 17f6c240cd7b bootstrap.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bootstrap.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,178 @@ +############################################################################## +# +# Copyright (c) 2006 Zope Foundation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +"""Bootstrap a buildout-based project + +Simply run this script in a directory containing a buildout.cfg. +The script accepts buildout command-line options, so you can +use the -c option to specify an alternate configuration file. +""" + +import os +import shutil +import sys +import tempfile + +from optparse import OptionParser + +tmpeggs = tempfile.mkdtemp() + +usage = '''\ +[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] + +Bootstraps a buildout-based project. + +Simply run this script in a directory containing a buildout.cfg, using the +Python that you want bin/buildout to use. + +Note that by using --find-links to point to local resources, you can keep +this script from going over the network. +''' + +parser = OptionParser(usage=usage) +parser.add_option("-v", "--version", help="use a specific zc.buildout version") + +parser.add_option("-t", "--accept-buildout-test-releases", + dest='accept_buildout_test_releases', + action="store_true", default=False, + help=("Normally, if you do not specify a --version, the " + "bootstrap script and buildout gets the newest " + "*final* versions of zc.buildout and its recipes and " + "extensions for you. If you use this flag, " + "bootstrap and buildout will get the newest releases " + "even if they are alphas or betas.")) +parser.add_option("-c", "--config-file", + help=("Specify the path to the buildout configuration " + "file to be used.")) +parser.add_option("-f", "--find-links", + help=("Specify a URL to search for buildout releases")) +parser.add_option("--allow-site-packages", + action="store_true", default=False, + help=("Let bootstrap.py use existing site packages")) + + +options, args = parser.parse_args() + +###################################################################### +# load/install setuptools + +try: + if options.allow_site_packages: + import setuptools + import pkg_resources + from urllib.request import urlopen +except ImportError: + from urllib2 import urlopen + +ez = {} +exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez) + +if not options.allow_site_packages: + # ez_setup imports site, which adds site packages + # this will remove them from the path to ensure that incompatible versions + # of setuptools are not in the path + import site + # inside a virtualenv, there is no 'getsitepackages'. + # We can't remove these reliably + if hasattr(site, 'getsitepackages'): + for sitepackage_path in site.getsitepackages(): + sys.path[:] = [x for x in sys.path if sitepackage_path not in x] + +setup_args = dict(to_dir=tmpeggs, download_delay=0) +ez['use_setuptools'](**setup_args) +import setuptools +import pkg_resources + +# This does not (always?) update the default working set. We will +# do it. +for path in sys.path: + if path not in pkg_resources.working_set.entries: + pkg_resources.working_set.add_entry(path) + +###################################################################### +# Install buildout + +ws = pkg_resources.working_set + +cmd = [sys.executable, '-c', + 'from setuptools.command.easy_install import main; main()', + '-mZqNxd', tmpeggs] + +find_links = os.environ.get( + 'bootstrap-testing-find-links', + options.find_links or + ('http://downloads.buildout.org/' + if options.accept_buildout_test_releases else None) + ) +if find_links: + cmd.extend(['-f', find_links]) + +setuptools_path = ws.find( + pkg_resources.Requirement.parse('setuptools')).location + +requirement = 'zc.buildout' +version = options.version +if version is None and not options.accept_buildout_test_releases: + # Figure out the most recent final version of zc.buildout. + import setuptools.package_index + _final_parts = '*final-', '*final' + + def _final_version(parsed_version): + for part in parsed_version: + if (part[:1] == '*') and (part not in _final_parts): + return False + return True + index = setuptools.package_index.PackageIndex( + search_path=[setuptools_path]) + if find_links: + index.add_find_links((find_links,)) + req = pkg_resources.Requirement.parse(requirement) + if index.obtain(req) is not None: + best = [] + bestv = None + for dist in index[req.project_name]: + distv = dist.parsed_version + if _final_version(distv): + if bestv is None or distv > bestv: + best = [dist] + bestv = distv + elif distv == bestv: + best.append(dist) + if best: + best.sort() + version = best[-1].version +if version: + requirement = '=='.join((requirement, version)) +cmd.append(requirement) + +import subprocess +if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0: + raise Exception( + "Failed to execute command:\n%s" % repr(cmd)[1:-1]) + +###################################################################### +# Import and run buildout + +ws.add_entry(tmpeggs) +ws.require(requirement) +import zc.buildout.buildout + +if not [a for a in args if '=' not in a]: + args.append('bootstrap') + +# if -c was provided, we push it back into args for buildout' main function +if options.config_file is not None: + args[0:0] = ['-c', options.config_file] + +zc.buildout.buildout.main(args) +shutil.rmtree(tmpeggs) diff -r 000000000000 -r 17f6c240cd7b buildout.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/buildout.cfg Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,61 @@ +[buildout] +eggs-directory = /var/local/env/pyams/eggs + +socket-timeout = 3 +show-picked-versions = true +newest = false + +allow-hosts = + bitbucket.org + *.python.org + *.sourceforge.net + github.com + +#extends = http://download.ztfy.org/webapp/ztfy.webapp.dev.cfg +versions = versions +newest = false +#allow-picked-versions = false + +src = src +develop = . + +parts = + package + i18n + pyflakes + test + +[package] +recipe = zc.recipe.egg +eggs = + pyams_alchemy + pyramid + sqlalchemy + zope.component + zope.interface + zope.sqlalchemy + +[i18n] +recipe = zc.recipe.egg +eggs = + babel + lingua + +[pyflakes] +recipe = zc.recipe.egg +eggs = pyflakes +scripts = pyflakes +entry-points = pyflakes=pyflakes.scripts.pyflakes:main +initialization = if not sys.argv[1:]: sys.argv[1:] = ["${buildout:src}"] + +[pyflakesrun] +recipe = collective.recipe.cmd +on_install = true +cmds = ${buildout:develop}/bin/${pyflakes:scripts} + +[test] +recipe = zc.recipe.testrunner +eggs = pyams_alchemy [test] + +[versions] +pyams_base = 0.1.0 diff -r 000000000000 -r 17f6c240cd7b docs/HISTORY.txt diff -r 000000000000 -r 17f6c240cd7b docs/README.txt diff -r 000000000000 -r 17f6c240cd7b setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,67 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +""" +This module contains pyams_alchemy package +""" +import os +from setuptools import setup, find_packages + +DOCS = os.path.join(os.path.dirname(__file__), + 'docs') + +README = os.path.join(DOCS, 'README.txt') +HISTORY = os.path.join(DOCS, 'HISTORY.txt') + +version = '0.1.0' +long_description = open(README).read() + '\n\n' + open(HISTORY).read() + +tests_require = [] + +setup(name='pyams_alchemy', + version=version, + description="PyAMS interfaces and classes for SQLAlchemy integration", + long_description=long_description, + classifiers=[ + "License :: OSI Approved :: Zope Public License", + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Framework :: Pyramid", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + keywords='Pyramid PyAMS SQLALchemy', + author='Thierry Florac', + author_email='tflorac@ulthar.net', + url='http://hg.ztfy.org/pyams/pyams_alchemy', + license='ZPL', + packages=find_packages('src'), + package_dir={'': 'src'}, + namespace_packages=[], + include_package_data=True, + package_data={'': ['*.zcml', '*.txt', '*.pt', '*.pot', '*.po', '*.mo', '*.png', '*.gif', '*.jpeg', '*.jpg', '*.css', '*.js']}, + zip_safe=False, + # uncomment this to be able to run tests with setup.py + test_suite="pyams_alchemy.tests.test_utilsdocs.test_suite", + tests_require=tests_require, + extras_require=dict(test=tests_require), + install_requires=[ + 'setuptools', + # -*- Extra requirements: -*- + 'pyramid', + 'sqlalchemy', + 'zope.component', + 'zope.interface', + ], + entry_points=""" + # -*- Entry points: -*- + """, + ) diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy.egg-info/PKG-INFO --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy.egg-info/PKG-INFO Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,18 @@ +Metadata-Version: 1.1 +Name: pyams-alchemy +Version: 0.1.0 +Summary: PyAMS interfaces and classes for SQLAlchemy integration +Home-page: http://hg.ztfy.org/pyams/pyams_alchemy +Author: Thierry Florac +Author-email: tflorac@ulthar.net +License: ZPL +Description: + + +Keywords: Pyramid PyAMS SQLALchemy +Platform: UNKNOWN +Classifier: License :: OSI Approved :: Zope Public License +Classifier: Development Status :: 4 - Beta +Classifier: Programming Language :: Python +Classifier: Framework :: Pyramid +Classifier: Topic :: Software Development :: Libraries :: Python Modules diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy.egg-info/SOURCES.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy.egg-info/SOURCES.txt Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,25 @@ +MANIFEST.in +setup.py +docs/HISTORY.txt +docs/README.txt +src/pyams_alchemy/__init__.py +src/pyams_alchemy/configure.zcml +src/pyams_alchemy/engine.py +src/pyams_alchemy/meta.zcml +src/pyams_alchemy/metaconfigure.py +src/pyams_alchemy/metadirectives.py +src/pyams_alchemy.egg-info/PKG-INFO +src/pyams_alchemy.egg-info/SOURCES.txt +src/pyams_alchemy.egg-info/dependency_links.txt +src/pyams_alchemy.egg-info/entry_points.txt +src/pyams_alchemy.egg-info/namespace_packages.txt +src/pyams_alchemy.egg-info/not-zip-safe +src/pyams_alchemy.egg-info/requires.txt +src/pyams_alchemy.egg-info/top_level.txt +src/pyams_alchemy/doctests/README.txt +src/pyams_alchemy/interfaces/__init__.py +src/pyams_alchemy/tests/__init__.py +src/pyams_alchemy/tests/test_utilsdocs.py +src/pyams_alchemy/tests/test_utilsdocstrings.py +src/pyams_alchemy/zmi/__init__.py +src/pyams_alchemy/zmi/engine.py \ No newline at end of file diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy.egg-info/dependency_links.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy.egg-info/dependency_links.txt Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,1 @@ + diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy.egg-info/entry_points.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy.egg-info/entry_points.txt Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,3 @@ + + # -*- Entry points: -*- + \ No newline at end of file diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy.egg-info/namespace_packages.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy.egg-info/namespace_packages.txt Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,1 @@ + diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy.egg-info/not-zip-safe --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy.egg-info/not-zip-safe Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,1 @@ + diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy.egg-info/requires.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy.egg-info/requires.txt Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,7 @@ +setuptools +pyramid +sqlalchemy +zope.component +zope.interface + +[test] diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy.egg-info/top_level.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy.egg-info/top_level.txt Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,1 @@ +pyams_alchemy diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/__init__.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,35 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +from pyramid.i18n import TranslationStringFactory +_ = TranslationStringFactory('pyams_alchemy') + + +def includeme(config): + """Pyramid include""" + + # add translations + config.add_translation_dirs('pyams_alchemy:locales') + + # load registry components + try: + import pyams_zmi + except ImportError: + config.scan(ignore='pyams_alchemy.zmi') + else: + config.scan() + + if hasattr(config, 'load_zcml'): + config.load_zcml('configure.zcml') diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/configure.zcml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/configure.zcml Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/doctests/README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/doctests/README.txt Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,3 @@ +===================== +pyams_alchemy package +===================== diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/engine.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/engine.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,166 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library +import sqlalchemy +from sqlalchemy.orm.scoping import scoped_session +from sqlalchemy.orm.session import sessionmaker + +# import interfaces +from pyams_alchemy.interfaces import REQUEST_SESSION_KEY, IAlchemyEngineUtility +from pyams_utils.interfaces.site import IOptionalUtility +from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent +from zope.schema.interfaces import IVocabularyFactory + +# import packages +from persistent import Persistent +from persistent.dict import PersistentDict +from pyams_utils.registry import query_utility +from pyams_utils.request import check_request, get_request_data, set_request_data +from pyramid.events import subscriber +from zope.componentvocabulary.vocabulary import UtilityVocabulary +from zope.container.contained import Contained +from zope.interface import implementer, provider +from zope.schema.fieldproperty import FieldProperty +from zope.schema.vocabulary import getVocabularyRegistry +from zope.sqlalchemy.datamanager import _SESSION_STATE, STATUS_READONLY, STATUS_ACTIVE, \ + ZopeTransactionExtension, join_transaction + + +@implementer(IAlchemyEngineUtility, IOptionalUtility) +class AlchemyEngineUtility(object): + """SQLAlchemy engine utility""" + + name = FieldProperty(IAlchemyEngineUtility['name']) + dsn = FieldProperty(IAlchemyEngineUtility['dsn']) + echo = FieldProperty(IAlchemyEngineUtility['echo']) + pool_size = FieldProperty(IAlchemyEngineUtility['pool_size']) + pool_recycle = FieldProperty(IAlchemyEngineUtility['pool_recycle']) + encoding = FieldProperty(IAlchemyEngineUtility['encoding']) + convert_unicode = FieldProperty(IAlchemyEngineUtility['convert_unicode']) + + def __init__(self, name='', dsn='', echo=False, pool_size=25, pool_recycle=-1, + encoding='utf-8', convert_unicode=False, **kwargs): + self.name = name + self.dsn = dsn + self.echo = echo + self.pool_size = pool_size + self.pool_recycle = pool_recycle + self.encoding = encoding + self.convert_unicode = convert_unicode + self.kw = PersistentDict() + self.kw.update(kwargs) + + def __setattr__(self, key, value): + super(AlchemyEngineUtility, self).__setattr__(key, value) + if (key != '_v_engine') and hasattr(self, '_v_engine'): + delattr(self, '_v_engine') + + def get_engine(self): + engine = getattr(self, '_v_engine', None) + if engine is not None: + return engine + kw = {} + kw.update(self.kw) + self._v_engine = sqlalchemy.create_engine(self.dsn, + echo=self.echo, + pool_size=self.pool_size, + pool_recycle=self.pool_recycle, + encoding=self.encoding, + convert_unicode=self.convert_unicode, + strategy='threadlocal', + **kw) + return self._v_engine + + +class PersistentAlchemyEngineUtility(Persistent, AlchemyEngineUtility, Contained): + """Persistent implementation of SQLAlchemy engine utility""" + + +@subscriber(IObjectAddedEvent, context_selector=IAlchemyEngineUtility) +def handle_added_engine(event): + """Register new SQLAlchemy engine when added""" + manager = event.newParent + manager.registerUtility(event.object, IAlchemyEngineUtility, name=event.object.name or '') + + +@subscriber(IObjectRemovedEvent, context_selector=IAlchemyEngineUtility) +def handle_removed_engine(event): + """Un-register an SQLAlchemy engine when deleted""" + manager = event.oldParent + manager.unregisterUtility(event.object, IAlchemyEngineUtility, name=event.object.name or '') + + +def get_engine(engine): + """Get engine matching given utility name""" + if isinstance(engine, str): + engine = query_utility(IAlchemyEngineUtility, name=engine) + if engine is not None: + return engine.get_engine() + + +def get_session(engine, join=True, status=STATUS_ACTIVE, request=None, alias=None, + twophase=True, use_zope_extension=True): + """Get a new SQLALchemy session + + Session is stored in request and in session storage + """ + if request is None: + request = check_request() + if not alias: + alias = engine + session_data = get_request_data(request, REQUEST_SESSION_KEY, {}) + session = session_data.get(alias) + if session is None: + _engine = get_engine(engine) + if use_zope_extension: + factory = scoped_session(sessionmaker(bind=_engine, + twophase=twophase, + extension=ZopeTransactionExtension())) + else: + factory = sessionmaker(bind=_engine, twophase=twophase) + session = factory() + if join: + join_transaction(session, initial_state=status) + if status != STATUS_READONLY: + _SESSION_STATE[id(session)] = session + if session is not None: + session_data[alias] = session + set_request_data(request, REQUEST_SESSION_KEY, session_data) + return session + + +def get_user_session(engine, join=True, status=STATUS_ACTIVE, request=None, alias=None, + twophase=True, use_zope_extension=True): + """Get a new SQLAlchemy session + + `engine` can be a session name or an already created session (in which case it's + returned as-is). + """ + if isinstance(engine, str): + session = get_session(engine, join, status, request, alias, twophase, use_zope_extension) + else: + session = engine + return session + + +@provider(IVocabularyFactory) +class EnginesVocabulary(UtilityVocabulary): + """SQLAlchemy engines vocabulary""" + + interface = IAlchemyEngineUtility + nameOnly = True + +getVocabularyRegistry().register('PyAMS SQLAlchemy engines', EnginesVocabulary) diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/interfaces/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/interfaces/__init__.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,67 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from zope.interface import Interface + +# import packages +from zope.schema import TextLine, Bool, Int, Choice + +from pyams_alchemy import _ + + +REQUEST_SESSION_KEY = 'pyams_alchemy.session' + + +class IAlchemyEngineUtility(Interface): + """SQLALchemy engine definition interface""" + + name = TextLine(title=_("Engine name"), + description=_("Keep empty if this engine is the default engine..."), + required=False, + default='') + + dsn = TextLine(title=_('DSN'), + description=_('RFC-1738 compliant URL for the database connection'), + required=True, + default=u'sqlite://') + + echo = Bool(title=_('Echo SQL'), + required=True, + default=False) + + pool_size = Int(title=_("Pool size"), + description=_("SQLAlchemy connections pool size"), + required=False, + default=25) + + pool_recycle = Int(title=_("Pool recycle time"), + description=_("SQLAlchemy connection recycle time (-1 for none)"), + required=False, + default=-1) + + encoding = Choice(title=_('Encoding'), + required=True, + vocabulary='PyAMS encodings', + default='utf-8') + + convert_unicode = Bool(title=_('Convert Unicode'), + required=True, + default=False) + + def get_engine(self): + """Get SQLAlchemy engine""" diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/locales/fr/LC_MESSAGES/pyams_alchemy.mo Binary file src/pyams_alchemy/locales/fr/LC_MESSAGES/pyams_alchemy.mo has changed diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/locales/fr/LC_MESSAGES/pyams_alchemy.po --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/locales/fr/LC_MESSAGES/pyams_alchemy.po Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,110 @@ +# +# French translations for PACKAGE package +# This file is distributed under the same license as the PACKAGE package. +# Thierry Florac , 2015. +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE 1.0\n" +"POT-Creation-Date: 2015-03-03 16:56+0100\n" +"PO-Revision-Date: 2015-03-03 16:56+0100\n" +"Last-Translator: Thierry Florac \n" +"Language-Team: French \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Lingua 3.8\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: src/pyams_alchemy/metadirectives.py:30 +#: src/pyams_alchemy/interfaces/__init__.py:33 +msgid "Engine name" +msgstr "Nom de la connexion" + +#: src/pyams_alchemy/metadirectives.py:31 +msgid "Empty if this engine is the default engine." +msgstr "Laisser ce nom vide s'il s'agit de la connexion par défaut" + +#: src/pyams_alchemy/metadirectives.py:35 +msgid "Database URL" +msgstr "URI" + +#: src/pyams_alchemy/metadirectives.py:36 +#: src/pyams_alchemy/interfaces/__init__.py:39 +msgid "RFC-1738 compliant URL for the database connection" +msgstr "URI au format RFC-1738 pour la connexion à la base de données" + +#: src/pyams_alchemy/metadirectives.py:39 +msgid "Echo SQL statements" +msgstr "Tracer les instructions SQL" + +#: src/pyams_alchemy/metadirectives.py:43 +#: src/pyams_alchemy/interfaces/__init__.py:47 +msgid "Pool size" +msgstr "Taille du pool" + +#: src/pyams_alchemy/metadirectives.py:44 +#: src/pyams_alchemy/interfaces/__init__.py:48 +msgid "SQLAlchemy connections pool size" +msgstr "Taille du pool de connexions SQLALchemy" + +#: src/pyams_alchemy/metadirectives.py:48 +#: src/pyams_alchemy/interfaces/__init__.py:52 +msgid "Pool recycle time" +msgstr "Durée de recyclage" + +#: src/pyams_alchemy/metadirectives.py:49 +#: src/pyams_alchemy/interfaces/__init__.py:53 +msgid "SQLAlchemy connection recycle time (-1 for none)" +msgstr "Durée de vie des connexions avant leur recyclage ; indiquer -1 pour conserver les connexions" + +#: src/pyams_alchemy/metadirectives.py:53 +#: src/pyams_alchemy/interfaces/__init__.py:57 +msgid "Encoding" +msgstr "Encodage" + +#: src/pyams_alchemy/metadirectives.py:58 +#: src/pyams_alchemy/interfaces/__init__.py:62 +msgid "Convert Unicode" +msgstr "Conversion Unicode" + +#: src/pyams_alchemy/zmi/engine.py:49 +msgid "Add SQLAlchemy engine..." +msgstr "Ajouter un moteur SQLAlchemy..." + +#: src/pyams_alchemy/zmi/engine.py:59 +msgid "Utilities" +msgstr "Utilitaires" + +#: src/pyams_alchemy/zmi/engine.py:60 +msgid "Add SQLAlchemy engine" +msgstr "Ajout d'un moteur SQLAlchemy" + +#: src/pyams_alchemy/zmi/engine.py:106 +msgid "Update SQLAlchemy engine properties" +msgstr "Modification des propriétés d'un moteur SQLAlchemy" + +#: src/pyams_alchemy/zmi/engine.py:85 +msgid "Specified engine name is already used!" +msgstr "Le nom indiqué pour ce moteur est déjà utilisé !" + +#: src/pyams_alchemy/zmi/engine.py:88 +msgid "An SQLAlchemy engine is already registered with this name!" +msgstr "Un moteur SQLAlchemy est déjà enregistré avec ce nom !" + +#: src/pyams_alchemy/zmi/engine.py:104 +#, python-format +msgid "SQLAlchemy engine: {0}" +msgstr "Moteur SQLAlchemy : {0}" + +#: src/pyams_alchemy/interfaces/__init__.py:34 +msgid "Keep empty if this engine is the default engine..." +msgstr "Laisser ce nom vide s'il s'agit du moteur par défaut..." + +#: src/pyams_alchemy/interfaces/__init__.py:38 +msgid "DSN" +msgstr "DSN" + +#: src/pyams_alchemy/interfaces/__init__.py:43 +msgid "Echo SQL" +msgstr "Écho SQL" diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/locales/pyams_alchemy.pot --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/locales/pyams_alchemy.pot Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,110 @@ +# +# SOME DESCRIPTIVE TITLE +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , 2015. +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE 1.0\n" +"POT-Creation-Date: 2015-03-03 16:56+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Lingua 3.8\n" + +#: ./src/pyams_alchemy/metadirectives.py:30 +#: ./src/pyams_alchemy/interfaces/__init__.py:33 +msgid "Engine name" +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:31 +msgid "Empty if this engine is the default engine." +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:35 +msgid "Database URL" +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:36 +#: ./src/pyams_alchemy/interfaces/__init__.py:39 +msgid "RFC-1738 compliant URL for the database connection" +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:39 +msgid "Echo SQL statements" +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:43 +#: ./src/pyams_alchemy/interfaces/__init__.py:47 +msgid "Pool size" +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:44 +#: ./src/pyams_alchemy/interfaces/__init__.py:48 +msgid "SQLAlchemy connections pool size" +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:48 +#: ./src/pyams_alchemy/interfaces/__init__.py:52 +msgid "Pool recycle time" +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:49 +#: ./src/pyams_alchemy/interfaces/__init__.py:53 +msgid "SQLAlchemy connection recycle time (-1 for none)" +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:53 +#: ./src/pyams_alchemy/interfaces/__init__.py:57 +msgid "Encoding" +msgstr "" + +#: ./src/pyams_alchemy/metadirectives.py:58 +#: ./src/pyams_alchemy/interfaces/__init__.py:62 +msgid "Convert Unicode" +msgstr "" + +#: ./src/pyams_alchemy/zmi/engine.py:49 +msgid "Add SQLAlchemy engine..." +msgstr "" + +#: ./src/pyams_alchemy/zmi/engine.py:59 +msgid "Utilities" +msgstr "" + +#: ./src/pyams_alchemy/zmi/engine.py:60 +msgid "Add SQLAlchemy engine" +msgstr "" + +#: ./src/pyams_alchemy/zmi/engine.py:106 +msgid "Update SQLAlchemy engine properties" +msgstr "" + +#: ./src/pyams_alchemy/zmi/engine.py:85 +msgid "Specified engine name is already used!" +msgstr "" + +#: ./src/pyams_alchemy/zmi/engine.py:88 +msgid "An SQLAlchemy engine is already registered with this name!" +msgstr "" + +#: ./src/pyams_alchemy/zmi/engine.py:104 +#, python-format +msgid "SQLAlchemy engine: {0}" +msgstr "" + +#: ./src/pyams_alchemy/interfaces/__init__.py:34 +msgid "Keep empty if this engine is the default engine..." +msgstr "" + +#: ./src/pyams_alchemy/interfaces/__init__.py:38 +msgid "DSN" +msgstr "" + +#: ./src/pyams_alchemy/interfaces/__init__.py:43 +msgid "Echo SQL" +msgstr "" diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/meta.zcml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/meta.zcml Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,14 @@ + + + + + + + + + diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/metaconfigure.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/metaconfigure.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,29 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from pyams_alchemy.interfaces import IAlchemyEngineUtility + +# import packages +from pyams_alchemy.engine import AlchemyEngineUtility +from zope.component import zcml + + +def engine_directive(context, name='', dsn='', echo=False, pool_size=25, pool_recycle=-2, encoding='utf-8', + convert_unicode=False, **kwargs): + engine = AlchemyEngineUtility(name, dsn, echo, pool_size, pool_recycle, encoding, convert_unicode, **kwargs) + zcml.utility(context, IAlchemyEngineUtility, engine, name=name) diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/metadirectives.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/metadirectives.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,60 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces + +# import packages +from zope.interface import Interface +from zope.schema import TextLine, Bool, Int, Choice + +from pyams_alchemy import _ + + +class IEngineDirective(Interface): + """Define a new SQLAlchemy engine""" + + name = TextLine(title=_('Engine name'), + description=_('Empty if this engine is the default engine.'), + required=False, + default='') + + dsn = TextLine(title=_('Database URL'), + description=_('RFC-1738 compliant URL for the database connection'), + required=True) + + echo = Bool(title=_('Echo SQL statements'), + required=False, + default=False) + + pool_size = Int(title=_("Pool size"), + description=_("SQLAlchemy connections pool size"), + required=False, + default=25) + + pool_recycle = Int(title=_("Pool recycle time"), + description=_("SQLAlchemy connection recycle time (-1 for none)"), + required=False, + default=-1) + + encoding = Choice(title=_('Encoding'), + required=True, + vocabulary='PyAMS encodings', + default='utf-8') + + convert_unicode = Bool(title=_('Convert Unicode'), + required=True, + default=False) diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/tests/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/tests/__init__.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,1 @@ + diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/tests/test_utilsdocs.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/tests/test_utilsdocs.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,59 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +""" +Generic Test case for pyams_alchemy doctest +""" +__docformat__ = 'restructuredtext' + +import unittest +import doctest +import sys +import os + + +current_dir = os.path.dirname(__file__) + +def doc_suite(test_dir, setUp=None, tearDown=None, globs=None): + """Returns a test suite, based on doctests found in /doctest.""" + suite = [] + if globs is None: + globs = globals() + + flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | + doctest.REPORT_ONLY_FIRST_FAILURE) + + package_dir = os.path.split(test_dir)[0] + if package_dir not in sys.path: + sys.path.append(package_dir) + + doctest_dir = os.path.join(package_dir, 'doctests') + + # filtering files on extension + docs = [os.path.join(doctest_dir, doc) for doc in + os.listdir(doctest_dir) if doc.endswith('.txt')] + + for test in docs: + suite.append(doctest.DocFileSuite(test, optionflags=flags, + globs=globs, setUp=setUp, + tearDown=tearDown, + module_relative=False)) + + return unittest.TestSuite(suite) + +def test_suite(): + """returns the test suite""" + return doc_suite(current_dir) + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') + diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/tests/test_utilsdocstrings.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/tests/test_utilsdocstrings.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,62 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +""" +Generic Test case for pyams_alchemy doc strings +""" +__docformat__ = 'restructuredtext' + +import unittest +import doctest +import sys +import os + + +current_dir = os.path.abspath(os.path.dirname(__file__)) + +def doc_suite(test_dir, globs=None): + """Returns a test suite, based on doc tests strings found in /*.py""" + suite = [] + if globs is None: + globs = globals() + + flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | + doctest.REPORT_ONLY_FIRST_FAILURE) + + package_dir = os.path.split(test_dir)[0] + if package_dir not in sys.path: + sys.path.append(package_dir) + + # filtering files on extension + docs = [doc for doc in + os.listdir(package_dir) if doc.endswith('.py')] + docs = [doc for doc in docs if not doc.startswith('__')] + + for test in docs: + fd = open(os.path.join(package_dir, test)) + content = fd.read() + fd.close() + if '>>> ' not in content: + continue + test = test.replace('.py', '') + location = 'pyams_alchemy.%s' % test + suite.append(doctest.DocTestSuite(location, optionflags=flags, + globs=globs)) + + return unittest.TestSuite(suite) + +def test_suite(): + """returns the test suite""" + return doc_suite(current_dir) + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/zmi/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/zmi/__init__.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,20 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces + +# import packages diff -r 000000000000 -r 17f6c240cd7b src/pyams_alchemy/zmi/engine.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_alchemy/zmi/engine.py Tue Mar 03 17:12:58 2015 +0100 @@ -0,0 +1,122 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from pyams_alchemy.interfaces import IAlchemyEngineUtility +from pyams_skin.interfaces.viewlet import IToolbarAddingMenu +from pyams_skin.layer import IPyAMSLayer +from pyams_zmi.layer import IAdminLayer +from z3c.form.interfaces import IDataExtractedEvent, DISPLAY_MODE +from zope.component.interfaces import ISite + +# import packages +from pyams_alchemy.engine import PersistentAlchemyEngineUtility +from pyams_form.form import AJAXEditForm, AJAXAddForm +from pyams_pagelet.pagelet import pagelet_config +from pyams_skin.viewlet.toolbar import ToolbarMenuItem +from pyams_utils.registry import query_utility +from pyams_utils.url import absolute_url +from pyams_viewlet.viewlet import viewlet_config +from pyams_zmi.control_panel import UtilitiesTable +from pyams_zmi.form import AdminDialogEditForm, AdminDialogAddForm +from pyramid.events import subscriber +from pyramid.view import view_config +from z3c.form import field +from zope.interface import Invalid + +from pyams_alchemy import _ + + +@viewlet_config(name='add-sqlalchemy-engine.menu', context=ISite, layer=IAdminLayer, + view=UtilitiesTable, manager=IToolbarAddingMenu, permission='system.manage') +class AlchemyEngineAddMenu(ToolbarMenuItem): + """SQLAlchemy engine add menu""" + + label = _("Add SQLAlchemy engine...") + label_css_class = 'fa fa-fw fa-database' + url = 'add-sqlalchemy-engine.html' + modal_target = True + + +@pagelet_config(name='add-sqlalchemy-engine.html', context=ISite, layer=IPyAMSLayer, permission='system.manage') +class AlchemyEngineAddForm(AdminDialogAddForm): + """SQLAlchemy engine add form""" + + title = _("Utilities") + legend = _("Add SQLAlchemy engine") + icon_css_class = 'fa fa-fw fa-database' + + fields = field.Fields(IAlchemyEngineUtility) + ajax_handler = 'add-sqlalchemy-engine.json' + edit_permission = None + + def create(self, data): + return PersistentAlchemyEngineUtility() + + def add(self, object): + manager = self.context.getSiteManager() + name = (object.name or '').lower() or '__DEFAULT__' + manager['sql::{0}'.format(name)] = object + + def nextURL(self): + return absolute_url(self.context, self.request, 'utilities.html') + + +@subscriber(IDataExtractedEvent, form_selector=AlchemyEngineAddForm) +def handle_new_engine_data_extraction(event): + """Handle new engine data extraction""" + manager = event.form.context.getSiteManager() + name = event.data['name'] or '' + if 'sql::{0}'.format(name.lower() or '__DEFAULT__') in manager: + event.form.widgets.errors += (Invalid(_("Specified engine name is already used!")), ) + engine = query_utility(IAlchemyEngineUtility, name=name) + if engine is not None: + event.form.widgets.errors += (Invalid(_("An SQLAlchemy engine is already registered with this name!")), ) + + +@view_config(name='add-sqlalchemy-engine.json', context=ISite, request_type=IPyAMSLayer, + permission='system.manage', renderer='json', xhr=True) +class AlchemyEngineAJAXAddForm(AJAXAddForm, AlchemyEngineAddForm): + """SQLAlchemy engine add form, AJAX view""" + + +@pagelet_config(name='properties.html', context=IAlchemyEngineUtility, layer=IPyAMSLayer, permission='system.view') +class AlchemyEnginePropertiesEditForm(AdminDialogEditForm): + """SQLAlchemy engine properties edit form""" + + @property + def title(self): + translate = self.request.localizer.translate + return translate(_("SQLAlchemy engine: {0}")).format(self.context.name) + + legend = _("Update SQLAlchemy engine properties") + icon_css_class = 'fa fa-fw fa-database' + + fields = field.Fields(IAlchemyEngineUtility) + ajax_handler = 'properties.json' + edit_permission = 'system.manage' + + def updateWidgets(self, prefix=None): + super(AlchemyEnginePropertiesEditForm, self).updateWidgets(prefix) + self.widgets['name'].mode = DISPLAY_MODE + self.widgets['encoding'].addClass('select2') + + +@view_config(name='properties.json', context=IAlchemyEngineUtility, request_type=IPyAMSLayer, + permission='system.manage', renderer='json', xhr=True) +class AlchemyEnginePropertiesAJAXEditForm(AJAXEditForm, AlchemyEnginePropertiesEditForm): + """SQLAlchemy engine properties edit form, AJAX view"""