Commit 6dd9d6ff authored by Hanno Schlichting's avatar Hanno Schlichting

Added a new API to ``OFS.metaconfigure.get_registered_packages`` which...

Added a new API to ``OFS.metaconfigure.get_registered_packages`` which replaces any direct access to ``Products._registered_packages``.
parent 01beaca6
...@@ -18,6 +18,9 @@ Bugs Fixed ...@@ -18,6 +18,9 @@ Bugs Fixed
Features Added Features Added
++++++++++++++ ++++++++++++++
- Added a new API to ``OFS.metaconfigure.get_registered_packages`` which
replaces any direct access to ``Products._registered_packages``.
- Changed product install so it won't write persistent changes only to abort - 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. them. Instead we don't make any database changes in the first place.
......
...@@ -24,6 +24,7 @@ from Acquisition import Acquired ...@@ -24,6 +24,7 @@ from Acquisition import Acquired
from Acquisition import aq_base from Acquisition import aq_base
from Acquisition import Implicit from Acquisition import Implicit
from ExtensionClass import Base from ExtensionClass import Base
from OFS.metaconfigure import get_registered_packages
def _product_packages(): def _product_packages():
...@@ -37,9 +38,9 @@ def _product_packages(): ...@@ -37,9 +38,9 @@ def _product_packages():
if isinstance(m, types.ModuleType): if isinstance(m, types.ModuleType):
packages[x] = m packages[x] = m
for m in getattr(Products, '_registered_packages', []): for m in get_registered_packages():
packages[m.__name__] = m packages[m.__name__] = m
return packages return packages
......
...@@ -71,17 +71,21 @@ def loadProductsOverrides(_context, file=None, files=None, package=None): ...@@ -71,17 +71,21 @@ def loadProductsOverrides(_context, file=None, files=None, package=None):
handleBrokenProduct(product) handleBrokenProduct(product)
def get_registered_packages():
packages = getattr(Products, '_registered_packages', None)
if packages is None:
packages = Products._registered_packages = []
return packages
def _registerPackage(module_, init_func=None): def _registerPackage(module_, init_func=None):
"""Registers the given python package as a Zope 2 style product """Registers the given python package as a Zope 2 style product
""" """
if not hasattr(module_, '__path__'): if not hasattr(module_, '__path__'):
raise ValueError("Must be a package and the " \ raise ValueError("Must be a package and the " \
"package must be filesystem based") "package must be filesystem based")
registered_packages = getattr(Products, '_registered_packages', None) registered_packages = get_registered_packages()
if registered_packages is None:
registered_packages = Products._registered_packages = []
registered_packages.append(module_) registered_packages.append(module_)
# Delay the actual setup until the usual product loading time in # Delay the actual setup until the usual product loading time in
......
...@@ -56,9 +56,10 @@ def test_registerPackage(): ...@@ -56,9 +56,10 @@ def test_registerPackage():
>>> install_products(app) >>> install_products(app)
pythonproduct2 initialized pythonproduct2 initialized
Make sure it shows up in ``Products._registered_packages``. Make sure it is registered:
>>> [x.__name__ for x in getattr(Products, '_registered_packages', [])] >>> from OFS.metaconfigure import get_registered_packages
>>> [x.__name__ for x in get_registered_packages()]
['pythonproduct2'] ['pythonproduct2']
Clean up: Clean up:
......
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