[Zope-Checkins] SVN: Zope/trunk/ Changed product install so it won't write persistent changes only to abort them. Instead we don't make any database changes in the first place.
Hanno Schlichting
hannosch at hannosch.eu
Sun Jun 27 08:44:22 EDT 2010
Log message for revision 113926:
Changed product install so it won't write persistent changes only to abort them. Instead we don't make any database changes in the first place.
Changed:
U Zope/trunk/doc/CHANGES.rst
U Zope/trunk/src/App/FactoryDispatcher.py
U Zope/trunk/src/App/Product.py
U Zope/trunk/src/App/ProductContext.py
U Zope/trunk/src/OFS/Application.py
-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst 2010-06-27 11:44:28 UTC (rev 113925)
+++ Zope/trunk/doc/CHANGES.rst 2010-06-27 12:44:22 UTC (rev 113926)
@@ -18,6 +18,11 @@
Features Added
++++++++++++++
+- Changed product install so it won't write persistent changes only to abort
+ them. Instead we don't make any database changes in the first place.
+
+- Disabled persistent product installation in the default test configuration.
+
- Directly extend and use the Zope Toolkit KGS release 1.0dev-r113891 from
http://download.zope.org/zopetoolkit/index/.
Modified: Zope/trunk/src/App/FactoryDispatcher.py
===================================================================
--- Zope/trunk/src/App/FactoryDispatcher.py 2010-06-27 11:44:28 UTC (rev 113925)
+++ Zope/trunk/src/App/FactoryDispatcher.py 2010-06-27 12:44:22 UTC (rev 113926)
@@ -23,7 +23,9 @@
from Acquisition import Acquired
from Acquisition import aq_base
from Acquisition import Implicit
+from ExtensionClass import Base
+
def _product_packages():
"""Returns all product packages including the regularly defined
zope2 packages and those without the Products namespace package.
@@ -41,7 +43,7 @@
return packages
-class Product(object):
+class Product(Base):
"""Model a non-persistent product wrapper.
"""
Modified: Zope/trunk/src/App/Product.py
===================================================================
--- Zope/trunk/src/App/Product.py 2010-06-27 11:44:28 UTC (rev 113925)
+++ Zope/trunk/src/App/Product.py 2010-06-27 12:44:22 UTC (rev 113926)
@@ -36,8 +36,6 @@
import os
-import transaction
-
from AccessControl.class_init import InitializeClass
from AccessControl.owner import UnownableOwner
from AccessControl.SecurityInfo import ClassSecurityInfo
@@ -204,13 +202,16 @@
def initializeProduct(productp, name, home, app):
- # Initialize a levered product
+ # Initialize a persistent product
+ assert doInstall()
+
import Globals # to set data
- products = app.Control_Panel.Products
fver = ''
- if hasattr(productp, '__import_error__'): ie=productp.__import_error__
- else: ie=None
+ if hasattr(productp, '__import_error__'):
+ ie = productp.__import_error__
+ else:
+ ie = None
# Retrieve version number from any suitable version.txt
for fname in ('version.txt', 'VERSION.txt', 'VERSION.TXT'):
@@ -223,32 +224,33 @@
except IOError:
continue
- old=None
+ old = None
+ products = app.Control_Panel.Products
try:
- if ihasattr(products,name):
+ if ihasattr(products, name):
old=getattr(products, name)
if ihasattr(old,'version') and old.version==fver:
if hasattr(old, 'import_error_') and \
old.import_error_==ie:
# Version hasn't changed. Don't reinitialize.
return old
- except: pass
+ except:
+ pass
f = fver and (" (%s)" % fver)
- product=Product(name, 'Installed product %s%s' % (name,f))
+ product=Product(name, 'Installed product %s%s' % (name, f))
if old is not None:
app._manage_remove_product_meta_type(product)
products._delObject(name)
for id, v in old.objectItems():
- try: product._setObject(id, v)
- except: pass
+ try:
+ product._setObject(id, v)
+ except:
+ pass
products._setObject(name, product)
- product.icon='p_/InstalledProduct_icon'
- product.version=fver
- product.home=home
- product.thisIsAnInstalledProduct=1
+ product.home = home
if ie:
product.import_error_=ie
@@ -277,12 +279,9 @@
{'label':'Refresh', 'action':'manage_refresh',
'help': ('OFSP','Product_Refresh.stx')},)
- if not doInstall():
- transaction.abort()
- return product
-
return product
+
def ihasattr(o, name):
return hasattr(o, name) and o.__dict__.has_key(name)
Modified: Zope/trunk/src/App/ProductContext.py
===================================================================
--- Zope/trunk/src/App/ProductContext.py 2010-06-27 11:44:28 UTC (rev 113925)
+++ Zope/trunk/src/App/ProductContext.py 2010-06-27 12:44:22 UTC (rev 113926)
@@ -24,7 +24,6 @@
from AccessControl.PermissionRole import PermissionRole
from App.Common import package_home
from App.ImageFile import ImageFile
-from App.Product import doInstall
from DateTime.DateTime import DateTime
from HelpSys import APIHelpTopic
from HelpSys import HelpTopic
@@ -50,14 +49,15 @@
class ProductContext:
def __init__(self, product, app, package):
- self.__prod=product
- self.__app=app
- self.__pack=package
+ self.__prod = product
+ # app is None by default which signals disabled product installation
+ self.__app = app
+ self.__pack = package
def registerClass(self, instance_class=None, meta_type='',
permission=None, constructors=(),
icon=None, permissions=None, legacy=(),
- visibility="Global",interfaces=_marker,
+ visibility="Global", interfaces=_marker,
container_filter=None
):
"""Register a constructor
@@ -140,7 +140,7 @@
else:
default = ('Manager',)
- pr=PermissionRole(permission,default)
+ pr = PermissionRole(permission,default)
registerPermissions(((permission, (), default),))
############################################################
@@ -168,7 +168,7 @@
else:
name = initial.__name__
- fd=getattr(pack, '__FactoryDispatcher__', None)
+ fd = getattr(pack, '__FactoryDispatcher__', None)
if fd is None:
class __FactoryDispatcher__(FactoryDispatcher):
"Factory Dispatcher for a Specific Product"
@@ -231,6 +231,8 @@
"""
Returns the ProductHelp associated with the current Product.
"""
+ if self.__app is None:
+ return self.__prod.getProductHelp()
return self.__prod.__of__(self.__app.Control_Panel.Products).getProductHelp()
def registerHelpTopic(self, id, topic):
@@ -267,7 +269,7 @@
.py -- APIHelpTopic
"""
- if not doInstall():
+ if not self.__app:
return
help=self.getProductHelp()
Modified: Zope/trunk/src/OFS/Application.py
===================================================================
--- Zope/trunk/src/OFS/Application.py 2010-06-27 11:44:28 UTC (rev 113925)
+++ Zope/trunk/src/OFS/Application.py 2010-06-27 12:44:22 UTC (rev 113926)
@@ -30,6 +30,7 @@
from Acquisition import aq_base
from App.ApplicationManager import ApplicationManager
from App.config import getConfiguration
+from App import FactoryDispatcher
from App.Product import doInstall
from DateTime import DateTime
from HelpSys.HelpSys import HelpSys
@@ -676,24 +677,26 @@
# expected to implement a method named 'initialize' in
# their __init__.py that takes the ProductContext as an
# argument.
- productObject = App.Product.initializeProduct(
- product, product_name, package_dir, app)
- context = ProductContext(productObject, app, product)
+ do_install = doInstall()
+ if do_install:
+ productObject = App.Product.initializeProduct(
+ product, product_name, package_dir, app)
+ context = ProductContext(productObject, app, product)
+ else:
+ # avoid any persistent connection
+ productObject = FactoryDispatcher.Product(product_name)
+ context = ProductContext(productObject, None, product)
# Look for an 'initialize' method in the product.
initmethod = pgetattr(product, 'initialize', None)
if initmethod is not None:
initmethod(context)
- if not doInstall():
- transaction.abort()
- else:
+ if do_install:
transaction.get().note('Installed product ' + product_name)
transaction.commit()
- except KeyboardInterrupt:
- raise
- except:
+ except Exception:
if log_exc:
LOG.error('Couldn\'t install %s' % product_name,
exc_info=sys.exc_info())
@@ -706,23 +709,27 @@
"""Installs a Python package like a product."""
from App.ProductContext import ProductContext
try:
- product = App.Product.initializeProduct(module,
- module.__name__,
- module.__path__[0],
- app)
- product.package_name = module.__name__
+ do_install = doInstall()
+ name = module.__name__
+ if do_install:
+ product = App.Product.initializeProduct(module,
+ name,
+ module.__path__[0],
+ app)
+ else:
+ product = FactoryDispatcher.Product(name)
+ app = None
+
+ product.package_name = name
+
if init_func is not None:
newContext = ProductContext(product, app, module)
init_func(newContext)
- if not doInstall():
- transaction.abort()
- else:
+ if do_install:
transaction.get().note('Installed package %s' % module.__name__)
transaction.commit()
- except KeyboardInterrupt:
- raise
- except:
+ except Exception:
if log_exc:
LOG.error("Couldn't install %s" % module.__name__,
exc_info=True)
More information about the Zope-Checkins
mailing list