def install_product(app, product_dir, product_name, meta_types,
                    folder_permissions, raise_exc=None):
    if not _is_package(product_dir, product_name):
        return

    __traceback_info__ = product_name
    global_dict = globals()
    product = __import__("Products.%s" % product_name,
                         global_dict, global_dict, ('__doc__', ))

    # Install items into the misc_ namespace, used by products
    # and the framework itself to store common static resources
    # like icon images.
    misc_ = pgetattr(product, 'misc_', {})
    if misc_:
        if isinstance(misc_, dict):
            misc_ = Misc_(product_name, misc_)
        setattr(Application.misc_, product_name, misc_)

    productObject = FactoryDispatcher.Product(product_name)
    context = ProductContext(productObject, app, product)

    # Look for an 'initialize' method in the product.
    initmethod = pgetattr(product, 'initialize', None)
    if initmethod is not None:
        initmethod(context)
Beispiel #2
0
def install_package(app, module, init_func, raise_exc=False, log_exc=True):
    """Installs a Python package like a product."""
    from App.ProductContext import ProductContext
    try:
        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)

        package_initialized(module, init_func)

        if do_install:
            transaction.get().note('Installed package %s' % module.__name__)
            transaction.commit()
    except Exception:
        if log_exc:
            LOG.error("Couldn't install %s" % module.__name__, exc_info=True)
        transaction.abort()
        if raise_exc:
            raise
def install_package(app, module, init_func, raise_exc=None):
    """Installs a Python package like a product."""
    name = module.__name__
    product = FactoryDispatcher.Product(name)
    product.package_name = name

    if init_func is not None:
        newContext = ProductContext(product, app, module)
        init_func(newContext)

    package_initialized(module, init_func)
Beispiel #4
0
def install_product(app,
                    product_dir,
                    product_name,
                    meta_types,
                    folder_permissions,
                    raise_exc=None):

    from App.ProductContext import ProductContext
    path_join = os.path.join
    isdir = os.path.isdir
    exists = os.path.exists
    global_dict = globals()

    package_dir = path_join(product_dir, product_name)
    __traceback_info__ = product_name
    if not isdir(package_dir): return
    if not exists(path_join(package_dir, '__init__.py')):
        if not exists(path_join(package_dir, '__init__.pyc')):
            if not exists(path_join(package_dir, '__init__.pyo')):
                return

    product = __import__("Products.%s" % product_name, global_dict,
                         global_dict, ('__doc__', ))

    # Install items into the misc_ namespace, used by products
    # and the framework itself to store common static resources
    # like icon images.
    misc_ = pgetattr(product, 'misc_', {})
    if misc_:
        if isinstance(misc_, dict):
            misc_ = Misc_(product_name, misc_)
        Application.misc_.__dict__[product_name] = misc_

    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)
Beispiel #5
0
def install_product(app,
                    product_dir,
                    product_name,
                    meta_types,
                    folder_permissions,
                    raise_exc=0,
                    log_exc=1):

    from App.ProductContext import ProductContext
    path_join = os.path.join
    isdir = os.path.isdir
    exists = os.path.exists
    global_dict = globals()
    silly = ('__doc__', )

    if 1:  # Preserve indentation for diff :-)
        package_dir = path_join(product_dir, product_name)
        __traceback_info__ = product_name
        if not isdir(package_dir): return
        if not exists(path_join(package_dir, '__init__.py')):
            if not exists(path_join(package_dir, '__init__.pyc')):
                if not exists(path_join(package_dir, '__init__.pyo')):
                    return
        try:
            product = __import__("Products.%s" % product_name, global_dict,
                                 global_dict, silly)

            # Install items into the misc_ namespace, used by products
            # and the framework itself to store common static resources
            # like icon images.
            misc_ = pgetattr(product, 'misc_', {})
            if misc_:
                if isinstance(misc_, dict):
                    misc_ = Misc_(product_name, misc_)
                Application.misc_.__dict__[product_name] = misc_

            # Here we create a ProductContext object which contains
            # information about the product and provides an interface
            # for registering things like classes and help topics that
            # should be associated with that product. Products are
            # expected to implement a method named 'initialize' in
            # their __init__.py that takes the ProductContext as an
            # argument.
            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 do_install:
                transaction.get().note('Installed product ' + product_name)
                transaction.commit()

        except Exception:
            if log_exc:
                LOG.error('Couldn\'t install %s' % product_name,
                          exc_info=sys.exc_info())
            transaction.abort()
            if raise_exc:
                raise