Added a persistent utility to store ZEO connection settings ZTK-1.1
authorThierry Florac <tflorac@ulthar.net>
Thu, 20 Sep 2012 17:06:22 +0200
branchZTK-1.1
changeset 169 b4b587dd45ca
parent 168 c02d355d3ffd
child 170 a08e9a1c5b07
Added a persistent utility to store ZEO connection settings
docs/HISTORY.txt
src/ztfy/utils/browser/configure.zcml
src/ztfy/utils/browser/zodb.py
src/ztfy/utils/configure.zcml
src/ztfy/utils/interfaces.py
src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.mo
src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.po
src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.mo
src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.po
src/ztfy/utils/locales/ztfy.utils.pot
src/ztfy/utils/zodb.py
src/ztfy/utils/zodb.zcml
--- a/docs/HISTORY.txt	Thu Sep 13 10:56:25 2012 +0200
+++ b/docs/HISTORY.txt	Thu Sep 20 17:06:22 2012 +0200
@@ -4,6 +4,7 @@
 0.3.13
 ------
  - added "ztfy.utils.container" utility module
+ - added a persistent utility to store ZEO connection settings
  - added "TextLine list" schema field and widget
  - added Python 2.7 compatibility code and timeout parameter to XML-RPC
    protocol helper
--- a/src/ztfy/utils/browser/configure.zcml	Thu Sep 13 10:56:25 2012 +0200
+++ b/src/ztfy/utils/browser/configure.zcml	Thu Sep 20 17:06:22 2012 +0200
@@ -1,8 +1,33 @@
 <configure
 	xmlns="http://namespaces.zope.org/zope"
+	xmlns:browser="http://namespaces.zope.org/browser"
 	xmlns:z3c="http://namespaces.zope.org/z3c"
 	i18n_domain="ztfy.i18n">
 
+	<!-- ZEO connection views -->
+	<browser:addMenuItem
+		title="ZEO connection"
+		description="A simple utility used to store ZEO connection settings"
+		class="..zodb.ZEOConnectionUtility"
+		permission="zope.ManageServices" />
+
+	<z3c:pagelet
+		name="properties.html"
+		for="..interfaces.IZEOConnection"
+		class=".zodb.ZEOConnectionEditForm"
+		layer="ztfy.skin.layer.IZTFYBrowserLayer"
+		permission="ztfy.ViewManagementScreens" />
+
+	<browser:viewlet
+		name="Properties"
+		viewURL="@@properties.html"
+		for="..interfaces.IZEOConnection"
+		manager="ztfy.skin.viewlets.actions.interfaces.IActionsViewletManager"
+		class="ztfy.skin.menu.PropertiesMenuItem"
+		permission="ztfy.ViewManagementScreens"
+		layer="ztfy.skin.layer.IZTFYBackLayer"
+		weight="10" />
+
 	<!-- Encoding selection widget -->
 	<adapter
 		factory=".encoding.EncodingSelectFieldWidget" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ztfy/utils/browser/zodb.py	Thu Sep 20 17:06:22 2012 +0200
@@ -0,0 +1,39 @@
+### -*- coding: utf-8 -*- ####################################################
+##############################################################################
+#
+# Copyright (c) 2012 Thierry Florac <tflorac AT ulthar.net>
+# 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.
+#
+##############################################################################
+
+
+# import standard packages
+
+# import Zope3 interfaces
+
+# import local interfaces
+from ztfy.skin.interfaces import IPropertiesMenuTarget
+from ztfy.utils.interfaces import IZEOConnection
+
+# import Zope3 packages
+from z3c.form import field
+from zope.interface import implements
+
+# import local packages
+from ztfy.skin.form import EditForm
+
+
+class ZEOConnectionEditForm(EditForm):
+    """Sequential ID utility edit form"""
+
+    implements(IPropertiesMenuTarget)
+
+    fields = field.Fields(IZEOConnection)
+    autocomplete = 'off'
--- a/src/ztfy/utils/configure.zcml	Thu Sep 13 10:56:25 2012 +0200
+++ b/src/ztfy/utils/configure.zcml	Thu Sep 20 17:06:22 2012 +0200
@@ -6,8 +6,7 @@
 	<i18n:registerTranslations directory="locales" />
 
 	<!-- IPersistent adapters copied from zc.twist package -->
-	<adapter
-		factory=".zodb.transactionManager" />
+	<include file="zodb.zcml" />
 
 	<!-- Encodings management -->
 	<utility
--- a/src/ztfy/utils/interfaces.py	Thu Sep 13 10:56:25 2012 +0200
+++ b/src/ztfy/utils/interfaces.py	Thu Sep 20 17:06:22 2012 +0200
@@ -24,9 +24,12 @@
 
 # import Zope3 packages
 from zope.interface import Interface
+from zope.schema import TextLine, Int, Password
 
 # import local packages
 
+from ztfy.utils import _
+
 
 class INewSiteManagerEvent(IObjectEvent):
     """Event interface for new site manager event"""
@@ -140,3 +143,41 @@
 
 class IDict(IDictInfo, IDictWriter):
     """Marker interface for dict-like components"""
+
+
+#
+# ZEO connection settings interface
+#
+
+class IZEOConnection(Interface):
+    """ZEO connection settings interface"""
+
+    server_name = TextLine(title=_("ZEO server name"),
+                           description=_("Hostname of ZEO server"),
+                           required=True,
+                           default=u'localhost')
+
+    server_port = Int(title=_("ZEO server port"),
+                      description=_("Port number of ZEO server"),
+                      required=True,
+                      default=8100)
+
+    storage = TextLine(title=_("ZEO server storage"),
+                       description=_("Storage name on ZEO server"),
+                       required=True,
+                       default=u'1')
+
+    username = TextLine(title=_("ZEO user name"),
+                        description=_("User name on ZEO server"),
+                        required=False)
+
+    password = Password(title=_("ZEO password"),
+                        description=_("User password on ZEO server"),
+                        required=False)
+
+    server_realm = TextLine(title=_("ZEO server realm"),
+                            description=_("Realm name on ZEO server"),
+                            required=False)
+
+    def getConnection(self, wait=False):
+        """Open ZEO connection with given settings"""
Binary file src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.mo has changed
--- a/src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.po	Thu Sep 13 10:56:25 2012 +0200
+++ b/src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.po	Thu Sep 20 17:06:22 2012 +0200
@@ -14,7 +14,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: ZTFY.utils\n"
-"POT-Creation-Date: Thu Apr 12 00:21:57 2012\n"
+"POT-Creation-Date: Thu Sep 20 17:01:57 2012\n"
 "PO-Revision-Date: 2009-08-14 18:14+0200\n"
 "Last-Translator: Thierry Florac <tflorac@ulthar.net>\n"
 "Language-Team: French <traduc@traduc.org>\n"
Binary file src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.mo has changed
--- a/src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.po	Thu Sep 13 10:56:25 2012 +0200
+++ b/src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.po	Thu Sep 20 17:06:22 2012 +0200
@@ -16,7 +16,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: ZTFY.utils\n"
-"POT-Creation-Date: Thu Apr 12 00:21:57 2012\n"
+"POT-Creation-Date: Thu Sep 20 17:01:57 2012\n"
 "PO-Revision-Date: 2012-03-26 14:18+0200\n"
 "Last-Translator: Thierry Florac <thierry.florac@onf.fr>\n"
 "Language-Team: français <>\n"
@@ -460,19 +460,72 @@
 msgid "Arabic (iso8859_6)"
 msgstr "Arabe (iso8859-6)"
 
+#: ztfy/utils/interfaces.py:155
+msgid "ZEO server name"
+msgstr "Nom du serveur"
+
+#: ztfy/utils/interfaces.py:156
+msgid "Hostname of ZEO server"
+msgstr "Nom ou adresse IP du serveur ZEO"
+
+#: ztfy/utils/interfaces.py:160
+msgid "ZEO server port"
+msgstr "Numéro de port"
+
+#: ztfy/utils/interfaces.py:161
+msgid "Port number of ZEO server"
+msgstr "N° du port TCP d'écoute du serveur ZEO"
+
+#: ztfy/utils/interfaces.py:165
+msgid "ZEO server storage"
+msgstr "Nom du stockage"
+
+#: ztfy/utils/interfaces.py:166
+msgid "Storage name on ZEO server"
+msgstr "Nom du stockage ZEO"
+
+#: ztfy/utils/interfaces.py:170
+msgid "ZEO user name"
+msgstr "Code utilisateur"
+
+#: ztfy/utils/interfaces.py:171
+msgid "User name on ZEO server"
+msgstr "Code utilisateur de connexion au serveur ZEO"
+
+#: ztfy/utils/interfaces.py:174
+msgid "ZEO password"
+msgstr "Mot de passe"
+
+#: ztfy/utils/interfaces.py:175
+msgid "User password on ZEO server"
+msgstr "Mot de passe de connexion au serveur ZEO"
+
+#: ztfy/utils/interfaces.py:178
+msgid "ZEO server realm"
+msgstr "Royaume"
+
+#: ztfy/utils/interfaces.py:179
+msgid "Realm name on ZEO server"
+msgstr "Nom du royaume du serveur ZEO, si nécessaire"
+
 #: ztfy/utils/request.py:40
 msgid "No Request in interaction !"
 msgstr "Pas de requête en cours !"
 
-#: ztfy/utils/schema.py:58
+#: ztfy/utils/schema.py:66
 msgid "Color length must be 3 or 6 characters"
 msgstr "La longueur du code couleur doit être de 3 ou 6 caractères"
 
-#: ztfy/utils/schema.py:61
+#: ztfy/utils/schema.py:69
 msgid ""
 "Color value must contain only valid color codes (numbers or letters between "
 "'A' end 'F')"
-msgstr "Une couleur ne doit contenir que des caractères hexadécimaux (nombres et lettres de 'A' à 'F')"
+msgstr "Une couleur ne doit contenir que des caractères hexadécimaux (nombres et "
+"lettres de 'A' à 'F')"
+
+#: ztfy/utils/schema.py:92
+msgid "The entered value is not a valid decimal literal."
+msgstr "La valeur indiquée n'est pas une valeur décimale correcte !"
 
 #: ztfy/utils/security.py:71
 msgid "< missing principal %s >"
--- a/src/ztfy/utils/locales/ztfy.utils.pot	Thu Sep 13 10:56:25 2012 +0200
+++ b/src/ztfy/utils/locales/ztfy.utils.pot	Thu Sep 20 17:06:22 2012 +0200
@@ -14,7 +14,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: Meaningless\n"
-"POT-Creation-Date: Thu Apr 12 00:21:57 2012\n"
+"POT-Creation-Date: Thu Sep 20 17:01:57 2012\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: Zope 3 Developers <zope-dev@zope.org>\n"
@@ -455,18 +455,70 @@
 msgid "Arabic (iso8859_6)"
 msgstr ""
 
+#: ztfy/utils/interfaces.py:155
+msgid "ZEO server name"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:156
+msgid "Hostname of ZEO server"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:160
+msgid "ZEO server port"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:161
+msgid "Port number of ZEO server"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:165
+msgid "ZEO server storage"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:166
+msgid "Storage name on ZEO server"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:170
+msgid "ZEO user name"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:171
+msgid "User name on ZEO server"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:174
+msgid "ZEO password"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:175
+msgid "User password on ZEO server"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:178
+msgid "ZEO server realm"
+msgstr ""
+
+#: ztfy/utils/interfaces.py:179
+msgid "Realm name on ZEO server"
+msgstr ""
+
 #: ztfy/utils/request.py:40
 msgid "No Request in interaction !"
 msgstr ""
 
-#: ztfy/utils/schema.py:58
+#: ztfy/utils/schema.py:66
 msgid "Color length must be 3 or 6 characters"
 msgstr ""
 
-#: ztfy/utils/schema.py:61
+#: ztfy/utils/schema.py:69
 msgid "Color value must contain only valid color codes (numbers or letters between 'A' end 'F')"
 msgstr ""
 
+#: ztfy/utils/schema.py:92
+msgid "The entered value is not a valid decimal literal."
+msgstr ""
+
 #: ztfy/utils/security.py:71
 msgid "< missing principal %s >"
 msgstr ""
--- a/src/ztfy/utils/zodb.py	Thu Sep 13 10:56:25 2012 +0200
+++ b/src/ztfy/utils/zodb.py	Thu Sep 20 17:06:22 2012 +0200
@@ -16,6 +16,7 @@
 __docformat__ = "restructuredtext"
 
 # import standard packages
+from persistent import Persistent
 
 # import Zope3 interfaces
 from persistent.interfaces import IPersistent
@@ -23,14 +24,48 @@
 from ZODB.interfaces import IConnection
 
 # import local interfaces
+from ztfy.utils.interfaces import IZEOConnection
 
 # import Zope3 packages
+from ZEO import ClientStorage
+from ZODB import DB
 from zope.component import adapter
-from zope.interface import implementer
+from zope.container.contained import Contained
+from zope.interface import implementer, implements
+from zope.schema.fieldproperty import FieldProperty
 
 # import local packages
 
 
+class ZEOConnectionInfo(object):
+    """ZEO connection info"""
+
+    implements(IZEOConnection)
+
+    server_name = FieldProperty(IZEOConnection['server_name'])
+    server_port = FieldProperty(IZEOConnection['server_port'])
+    storage = FieldProperty(IZEOConnection['storage'])
+    username = FieldProperty(IZEOConnection['username'])
+    password = FieldProperty(IZEOConnection['password'])
+    server_realm = FieldProperty(IZEOConnection['server_realm'])
+
+    def getConnection(self, wait=False, get_storage=False):
+        """Get a tuple made of storage and DB connection for given settings"""
+        storage = ClientStorage.ClientStorage((str(self.server_name), self.server_port),
+                                              storage=self.server_storage,
+                                              username=self.server_username or '',
+                                              password=self.server_password or '',
+                                              realm=self.server_realm,
+                                              wait=wait)
+        db = DB(storage)
+        return (storage, db) if get_storage else db
+
+
+class ZEOConnectionUtility(ZEOConnectionInfo, Persistent, Contained):
+    """Persistent ZEO connection settings utility"""
+
+
+
 # IPersistent adapters copied from zc.twist package
 # also register this for adapting from IConnection
 @adapter(IPersistent)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ztfy/utils/zodb.zcml	Thu Sep 20 17:06:22 2012 +0200
@@ -0,0 +1,21 @@
+<configure
+	xmlns="http://namespaces.zope.org/zope"
+	xmlns:i18n="http://namespaces.zope.org/i18n"
+	i18n_domain="ztfy.utils">
+
+	<!-- IPersistent adapters copied from zc.twist package -->
+	<adapter
+		factory=".zodb.transactionManager" />
+
+	<class class=".zodb.ZEOConnectionUtility">
+		<implements
+			interface="zope.annotation.interfaces.IAttributeAnnotatable" />
+		<require
+			interface=".interfaces.IZEOConnection"
+			permission="zope.View" />
+		<require
+			set_schema=".interfaces.IZEOConnection"
+			permission="zope.ManageServices" />
+	</class>
+
+</configure>
\ No newline at end of file