예제 #1
0
def installProduct(app, productName, quiet=False):
    """Install the Zope 2 product with the given name, so that it will show
    up in the Zope 2 control panel and have its ``initialize()`` hook called.

    The ``STARTUP`` layer or an equivalent layer must have been loaded first.

    If ``quiet`` is False, an error will be logged if the product cannot be
    found. By default, the function is silent.

    Note that products' ZCML is *not* loaded automatically, even if the
    product is in the Products namespace.
    """

    import sys


    from OFS.Folder import Folder
    from OFS.Application import get_folder_permissions, get_products
    from OFS.Application import install_product, install_package

    from App.class_init import InitializeClass

    import Products

    found = False

    if productName in _INSTALLED_PRODUCTS:
        return

    if productName.startswith('Products.'):
        for priority, name, index, productDir in get_products():
            if ('Products.' + name) == productName:

                install_product(app, productDir, name, [], get_folder_permissions(), raise_exc=1)
                InitializeClass(Folder)

                _INSTALLED_PRODUCTS[productName] = (priority, name, index, productDir,)

                found = True
                break

    else:
        if HAS_ZOPE213:
            packages = tuple(get_packages_to_initialize())
        else:
            packages = getattr(Products, '_packages_to_initialize', [])
        for module, init_func in packages:
            if module.__name__ == productName:
                install_package(app, module, init_func, raise_exc=1)
                if not HAS_ZOPE213:
                    Products._packages_to_initialize.remove((module, init_func))

                _INSTALLED_PRODUCTS[productName] = (module, init_func,)

                found = True
                break

    if not found and not quiet:
        sys.stderr.write("Could not install product %s\n" % productName)
        sys.stderr.flush()
예제 #2
0
def install_products(app):
    # Install a list of products into the basic folder class, so
    # that all folders know about top-level objects, aka products

    folder_permissions = get_folder_permissions()
    meta_types=[]
    done={}

    debug_mode = getConfiguration().debug_mode

    transaction.get().note('Prior to product installs')
    transaction.commit()

    products = get_products()

    for priority, product_name, index, product_dir in products:
        # For each product, we will import it and try to call the
        # intialize() method in the product __init__ module. If
        # the method doesnt exist, we put the old-style information
        # together and do a default initialization.
        if done.has_key(product_name):
            continue
        done[product_name]=1
        install_product(app, product_dir, product_name, meta_types,
                        folder_permissions, raise_exc=debug_mode)

    # Delayed install of packages-as-products
    for module, init_func in tuple(get_packages_to_initialize()):
        install_package(app, module, init_func, raise_exc=debug_mode)

    Products.meta_types=Products.meta_types+tuple(meta_types)
    InitializeClass(Folder.Folder)
예제 #3
0
 def _install_package(self, name, app):
     """Zope 2 install a given package.
     """
     if name not in self.installed_packages:
         for module, init_func in get_packages_to_initialize():
             if module.__name__ == name:
                 install_package(app, module, init_func, raise_exc=1)
                 self.installed_packages.append(name)
                 break
예제 #4
0
파일: zope.py 프로젝트: plone/plone.testing
def uninstallProduct(app, productName, quiet=False):
    """Uninstall the given Zope 2 product. This is the inverse of
    ``installProduct()`` above.
    """

    import sys

    # from OFS.Folder import Folder
    # from OFS.Application import get_folder_permissions
    # from AccessControl.class_init import InitializeClass

    from OFS.Application import Application, get_products

    global _INSTALLED_PRODUCTS
    found = False

    if productName not in _INSTALLED_PRODUCTS:
        return

    if productName.startswith('Products.'):
        for priority, name, index, productDir in get_products():
            if ('Products.' + name) == productName:

                if name in Application.misc_.__dict__:
                    delattr(Application.misc_, name)

                # TODO: Also remove permissions from get_folder_permissions?
                # Difficult to know if this would stomp on any other
                # permissions
                # InitializeClass(Folder)

                found = True
                break
    elif productName in _INSTALLED_PRODUCTS:  # must be a package

        module, init_func = _INSTALLED_PRODUCTS[productName]
        name = module.__name__

        packages = get_packages_to_initialize()
        packages.append((module, init_func))
        found = True

    if found:
        del _INSTALLED_PRODUCTS[productName]

    if not found and not quiet:
        sys.stderr.write(
            'Could not install product {0}\n'.format(productName))
        sys.stderr.flush()
예제 #5
0
def uninstallProduct(app, productName, quiet=False):
    """Uninstall the given Zope 2 product. This is the inverse of
    ``installProduct()`` above.
    """

    import sys

    # from OFS.Folder import Folder
    # from OFS.Application import get_folder_permissions
    # from AccessControl.class_init import InitializeClass

    from OFS.Application import Application, get_products

    global _INSTALLED_PRODUCTS
    found = False

    if productName not in _INSTALLED_PRODUCTS:
        return

    if productName.startswith('Products.'):
        for priority, name, index, productDir in get_products():
            if ('Products.' + name) == productName:

                if name in Application.misc_.__dict__:
                    delattr(Application.misc_, name)

                # TODO: Also remove permissions from get_folder_permissions?
                # Difficult to know if this would stomp on any other
                # permissions
                # InitializeClass(Folder)

                found = True
                break
    elif productName in _INSTALLED_PRODUCTS:  # must be a package

        module, init_func = _INSTALLED_PRODUCTS[productName]
        name = module.__name__

        packages = get_packages_to_initialize()
        packages.append((module, init_func))
        found = True

    if found:
        del _INSTALLED_PRODUCTS[productName]

    if not found and not quiet:
        sys.stderr.write('Could not install product {0}\n'.format(productName))
        sys.stderr.flush()
예제 #6
0
def _installPackage(name, quiet=0):
    '''Installs a registered Python package.'''
    from OFS.metaconfigure import get_packages_to_initialize
    start = time.time()
    if _patched and not _installedPackages.has_key(name):
        for module, init_func in get_packages_to_initialize():
            if module.__name__ == name:
                if not quiet:
                    _print('Installing %s ... ' % module.__name__)
                install_package(_theApp, module, init_func)
                _installedPackages[module.__name__] = 1
                if not quiet:
                    _print('done (%.3fs)\n' % (time.time() - start))
                break
        else:
            if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
예제 #7
0
def _installPackage(name, quiet=0):
    '''Installs a registered Python package.'''
    from OFS.metaconfigure import get_packages_to_initialize
    start = time.time()
    if _patched and not _installedPackages.has_key(name):
        for module, init_func in get_packages_to_initialize():
            if module.__name__ == name:
                if not quiet: _print('Installing %s ... ' % module.__name__)
                # We want to fail immediately if a package throws an exception
                # during install, so we set the raise_exc flag.
                install_package(_theApp, module, init_func, raise_exc=1)
                _installedPackages[module.__name__] = 1
                if not quiet:
                    _print('done (%.3fs)\n' % (time.time() - start))
                break
        else:
            if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
예제 #8
0
def _installPackage(name, quiet=0):
    '''Installs a registered Python package.'''
    from OFS.metaconfigure import get_packages_to_initialize
    start = time.time()
    if _patched and not _installedPackages.has_key(name):
        for module, init_func in get_packages_to_initialize():
            if module.__name__ == name:
                if not quiet: _print('Installing %s ... ' % module.__name__)
                # We want to fail immediately if a package throws an exception
                # during install, so we set the raise_exc flag.
                install_package(_theApp, module, init_func, raise_exc=1)
                _installedPackages[module.__name__] = 1
                if not quiet:
                    _print('done (%.3fs)\n' % (time.time() - start))
                break
        else:
            if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
def install_products(app=None):
    folder_permissions = get_folder_permissions()
    meta_types = []
    done = {}
    for priority, product_name, index, product_dir in get_products():
        # For each product, we will import it and try to call the
        # intialize() method in the product __init__ module. If
        # the method doesnt exist, we put the old-style information
        # together and do a default initialization.
        if product_name in done:
            continue
        done[product_name] = 1
        install_product(app, product_dir, product_name, meta_types,
                        folder_permissions)

    # Delayed install of packages-as-products
    for module, init_func in tuple(get_packages_to_initialize()):
        install_package(app, module, init_func)

    Products.meta_types = Products.meta_types + tuple(meta_types)
    InitializeClass(Folder.Folder)
예제 #10
0
def install_products(app=None):
    folder_permissions = get_folder_permissions()
    meta_types = []
    done = {}
    for priority, product_name, index, product_dir in get_products():
        # For each product, we will import it and try to call the
        # intialize() method in the product __init__ module. If
        # the method doesnt exist, we put the old-style information
        # together and do a default initialization.
        if product_name in done:
            continue
        done[product_name] = 1
        install_product(app, product_dir, product_name, meta_types,
                        folder_permissions)

    # Delayed install of packages-as-products
    for module, init_func in tuple(get_packages_to_initialize()):
        install_package(app, module, init_func)

    Products.meta_types = Products.meta_types + tuple(meta_types)
    InitializeClass(Folder.Folder)
예제 #11
0
def install_products(app):
    # Install a list of products into the basic folder class, so
    # that all folders know about top-level objects, aka products

    folder_permissions = get_folder_permissions()
    meta_types = []
    done = {}

    debug_mode = getConfiguration().debug_mode

    transaction.get().note('Prior to product installs')
    transaction.commit()

    products = get_products()

    for priority, product_name, index, product_dir in products:
        # For each product, we will import it and try to call the
        # intialize() method in the product __init__ module. If
        # the method doesnt exist, we put the old-style information
        # together and do a default initialization.
        if done.has_key(product_name):
            continue
        done[product_name] = 1
        install_product(app,
                        product_dir,
                        product_name,
                        meta_types,
                        folder_permissions,
                        raise_exc=debug_mode)

    # Delayed install of packages-as-products
    for module, init_func in tuple(get_packages_to_initialize()):
        install_package(app, module, init_func, raise_exc=debug_mode)

    Products.meta_types = Products.meta_types + tuple(meta_types)
    InitializeClass(Folder.Folder)
예제 #12
0
def installProduct(app, productName, quiet=False, multiinit=False):
    """Install the Zope 2 product with the given name, so that it will show
    up in the Zope 2 control panel and have its ``initialize()`` hook called.

    The ``STARTUP`` layer or an equivalent layer must have been loaded first.

    If ``quiet`` is False, an error will be logged if the product cannot be
    found. By default, the function is silent.

    Note that products' ZCML is *not* loaded automatically, even if the
    product is in the Products namespace.
    """
    from App.class_init import InitializeClass
    from OFS.Application import get_folder_permissions
    from OFS.Application import get_products
    from OFS.Application import install_package
    from OFS.Application import install_product
    from OFS.Folder import Folder
    import Products
    import sys

    found = False

    if productName in _INSTALLED_PRODUCTS:
        return

    if productName.startswith('Products.'):
        for priority, name, index, productDir in get_products():
            if ('Products.' + name) == productName:

                install_product(app,
                                productDir,
                                name, [],
                                get_folder_permissions(),
                                raise_exc=1)
                InitializeClass(Folder)

                _INSTALLED_PRODUCTS[productName] = (
                    priority,
                    name,
                    index,
                    productDir,
                )

                found = True
                break

    else:
        if HAS_ZOPE213:
            packages = tuple(get_packages_to_initialize())
        else:
            packages = getattr(Products, '_packages_to_initialize', [])
        for module, init_func in packages:
            if module.__name__ == productName:
                install_package(app, module, init_func, raise_exc=1)
                if not HAS_ZOPE213:
                    Products._packages_to_initialize.remove(
                        (module, init_func))

                _INSTALLED_PRODUCTS[productName] = (
                    module,
                    init_func,
                )

                found = True
                if not multiinit:
                    break

    if not found and not quiet:
        sys.stderr.write("Could not install product %s\n" % productName)
        sys.stderr.flush()
예제 #13
0
def uninstallProduct(app, productName, quiet=False):
    """Uninstall the given Zope 2 product. This is the inverse of
    ``installProduct()`` above.
    """

    import sys

    # from OFS.Folder import Folder
    # from OFS.Application import get_folder_permissions
    # from App.class_init import InitializeClass

    from OFS.Application import Application, get_products
    import Products

    global _INSTALLED_PRODUCTS
    found = False

    if productName not in _INSTALLED_PRODUCTS:
        return

    if productName.startswith('Products.'):
        for priority, name, index, productDir in get_products():
            if ('Products.' + name) == productName:

                if name in Application.misc_.__dict__:
                    del Application.misc_.__dict__[name]

                try:
                    cp = app['Control_Panel']['Products']
                except KeyError:
                    # Zope 4
                    pass
                else:
                    if name in cp:
                        product = cp[name]

                        app._manage_remove_product_meta_type(product)
                        app._manage_remove_product_permission(product)

                        del cp[name]

                # TODO: Also remove permissions from get_folder_permissions?
                # Difficult to know if this would stomp on any other
                # permissions
                # InitializeClass(Folder)

                found = True
                break
    elif productName in _INSTALLED_PRODUCTS:  # must be a package

        module, init_func = _INSTALLED_PRODUCTS[productName]
        name = module.__name__

        try:
            cp = app['Control_Panel']['Products']
        except KeyError:
            # Zope 4
            pass
        else:
            if name in cp:
                product = cp[name]

                app._manage_remove_product_meta_type(product)
                app._manage_remove_product_permission(product)

                del cp[name]

        if HAS_ZOPE213:
            packages = get_packages_to_initialize()
        else:
            packages = Products._packages_to_initialize
        packages.append((module, init_func))
        found = True

    if found:
        del _INSTALLED_PRODUCTS[productName]

    if not found and not quiet:
        sys.stderr.write("Could not install product %s\n" % productName)
        sys.stderr.flush()
예제 #14
0
def uninstallProduct(app, productName, quiet=False):
    """Uninstall the given Zope 2 product. This is the inverse of
    ``installProduct()`` above.
    """

    import sys

    # from OFS.Folder import Folder
    # from OFS.Application import get_folder_permissions
    # from App.class_init import InitializeClass

    from OFS.Application import Application, get_products
    import Products

    global _INSTALLED_PRODUCTS
    found = False

    if productName not in _INSTALLED_PRODUCTS:
        return

    if productName.startswith('Products.'):
        for priority, name, index, productDir in get_products():
            if ('Products.' + name) == productName:

                if name in Application.misc_.__dict__:
                    del Application.misc_.__dict__[name]

                if name in app['Control_Panel']['Products']:
                    product = app['Control_Panel']['Products'][name]

                    app._manage_remove_product_meta_type(product)
                    app._manage_remove_product_permission(product)

                    del app['Control_Panel']['Products'][name]

                # TODO: Also remove permissions from get_folder_permissions?
                # Difficult to know if this would stomp on any other permissions
                # InitializeClass(Folder)

                found = True
                break
    elif productName in _INSTALLED_PRODUCTS: # must be a package

        module, init_func = _INSTALLED_PRODUCTS[productName]
        name = module.__name__

        if name in app['Control_Panel']['Products']:
            product = app['Control_Panel']['Products'][name]

            app._manage_remove_product_meta_type(product)
            app._manage_remove_product_permission(product)

            del app['Control_Panel']['Products'][name]

        if HAS_ZOPE213:
            packages = get_packages_to_initialize()
        else:
            packages = Products._packages_to_initialize
        packages.append((module, init_func))
        found = True

    if found:
        del _INSTALLED_PRODUCTS[productName]

    if not found and not quiet:
        sys.stderr.write("Could not install product %s\n" % productName)
        sys.stderr.flush()
예제 #15
0
def handler(product, package, class_, permission_id):
    Products.Archetypes.atapi.registerType(class_, product)
    registration = Registration(product, class_, permission_id)
    to_initialize = get_packages_to_initialize()
    to_initialize.append((package, registration))