Exemple #1
0
    def install_cp_and_products(self):
        app = self.getApp()

        # Ensure that Control Panel exists.
        if not hasattr(app, 'Control_Panel'):
            cpl = ApplicationManager()
            cpl._init()
            app._setObject('Control_Panel', cpl)
            self.commit('Added Control_Panel')
        else:
            # Inline migration of old databases
            cp = app.Control_Panel
            ids = [i['id'] for i in cp._objects]
            if 'Versions' in ids:
                new = []
                for entry in cp._objects:
                    if entry['id'] != 'Versions':
                        new.append(entry)
                cp._objects = tuple(new)
                self.commit('Removed Control_Panel.Versions')

        # b/c: Ensure that a ProductFolder exists.
        if not hasattr(aq_base(app.Control_Panel), 'Products'):
            app.Control_Panel.Products = App.Product.ProductFolder()
            self.commit('Added Control_Panel.Products')
    def install_cp_and_products(self):
        app = self.getApp()

        # Ensure that Control Panel exists.
        if not hasattr(app, 'Control_Panel'):
            cpl = ApplicationManager()
            cpl._init()
            app._setObject('Control_Panel', cpl)
            self.commit('Added Control_Panel')
        else:
            # Inline migration of old databases
            cp = app.Control_Panel
            ids = [i['id'] for i in cp._objects]
            if 'Versions' in ids:
                new = []
                for entry in cp._objects:
                    if entry['id'] != 'Versions':
                        new.append(entry)
                cp._objects = tuple(new)
                self.commit('Removed Control_Panel.Versions')

        # b/c: Ensure that a ProductFolder exists.
        if not hasattr(aq_base(app.Control_Panel), 'Products'):
            app.Control_Panel.Products=App.Product.ProductFolder()
            self.commit('Added Control_Panel.Products')
    def __init__(self):
        # Initialize users
        uf=UserFolder()
        self.__allow_groups__=uf
        self._setObject('acl_users', uf)

        # Initialize control panel
        cpl=ApplicationManager()
        cpl._init()
        self._setObject('Control_Panel', cpl)
        get_transaction().note("Created Zope Application")
Exemple #4
0
    def __init__(self):
        # Initialize users
        uf = UserFolder()
        self.__allow_groups__ = uf
        self._setObject('acl_users', uf)

        # Initialize control panel
        cpl = ApplicationManager()
        cpl._init()
        self._setObject('Control_Panel', cpl)
        transaction.get().note("Created Zope Application")
    def install_cp_and_products(self):
        global APP_MANAGER
        APP_MANAGER = ApplicationManager()
        APP_MANAGER._init()

        app = self.getApp()
        app._p_activate()

        # Remove Control Panel.
        if 'Control_Panel' in app.__dict__.keys():
            del app.__dict__['Control_Panel']
            app._objects = tuple(i for i in app._objects if i['id'] != 'Control_Panel')
            self.commit('Removed persistent Control_Panel')
Exemple #6
0
    def install_cp_and_products(self):
        global APP_MANAGER
        APP_MANAGER = ApplicationManager()
        APP_MANAGER._init()

        app = self.getApp()
        app._p_activate()

        # Remove Control Panel.
        if 'Control_Panel' in app.__dict__.keys():
            del app.__dict__['Control_Panel']
            app._objects = tuple(i for i in app._objects
                                 if i['id'] != 'Control_Panel')
            self.commit('Removed persistent Control_Panel')
Exemple #7
0
    def install_cp_and_products(self):
        app = self.getApp()

        # Ensure that Control Panel exists.
        if not hasattr(app, 'Control_Panel'):
            cpl = ApplicationManager()
            cpl._init()
            app._setObject('Control_Panel', cpl)
            self.commit('Added Control_Panel')

        # b/c: Ensure that a ProductFolder exists.
        if not hasattr(aq_base(app.Control_Panel), 'Products'):
            app.Control_Panel.Products = App.Product.ProductFolder()
            self.commit('Added Control_Panel.Products')
Exemple #8
0
    def install_cp_and_products(self):
        app = self.getApp()

        # Ensure that Control Panel exists.
        if not hasattr(app, 'Control_Panel'):
            cpl=ApplicationManager()
            cpl._init()
            app._setObject('Control_Panel', cpl)
            self.commit('Added Control_Panel')

        # b/c: Ensure that a ProductFolder exists.
        if not hasattr(aq_base(app.Control_Panel), 'Products'):
            app.Control_Panel.Products=App.Product.ProductFolder()
            self.commit('Added Control_Panel.Products')
    def install_app_manager(self):
        global APP_MANAGER
        APP_MANAGER = ApplicationManager()

        # Remove persistent Control Panel.
        app = self.getApp()
        app._p_activate()

        if 'Control_Panel' in list(app.__dict__.keys()):
            del app.__dict__['Control_Panel']
            app._objects = tuple(i for i in app._objects
                                 if i['id'] != 'Control_Panel')
            self.commit('Removed persistent Control_Panel')
def initialize(app):
    # Initialize the application

    # The following items marked b/c are backward compatibility hacks
    # which make sure that expected system objects are added to the
    # bobobase. This is required because the bobobase in use may pre-
    # date the introduction of certain system objects such as those
    # which provide Lever support.

    # b/c: Ensure that Control Panel exists.
    if not hasattr(app, 'Control_Panel'):
        cpl=ApplicationManager()
        cpl._init()
        app._setObject('Control_Panel', cpl)
        get_transaction().note('Added Control_Panel')
        get_transaction().commit()

    # Initialize the cache:
    app.Control_Panel.initialize_cache()

    # b/c: Ensure that a ProductFolder exists.
    if not hasattr(aq_base(app.Control_Panel), 'Products'):
        app.Control_Panel.Products=App.Product.ProductFolder()
        get_transaction().note('Added Control_Panel.Products')
        get_transaction().commit()

    # Ensure that a temp folder exists
    if not hasattr(app, 'temp_folder'):
        from Products.TemporaryFolder.TemporaryFolder import \
             MountedTemporaryFolder
        tf = MountedTemporaryFolder('temp_folder','Temporary Folder')
        app._setObject('temp_folder', tf)
        get_transaction().note('Added temp_folder')
        get_transaction().commit()
        del tf

    # Ensure that there is a transient container in the temp folder
    tf = app.temp_folder
    if not hasattr(aq_base(tf), 'session_data'):
        env_has = os.environ.get
        from Products.Transience.Transience import TransientObjectContainer
        addnotify = env_has('ZSESSION_ADD_NOTIFY', None)
        delnotify = env_has('ZSESSION_DEL_NOTIFY', None)
        default_limit = 1000
        limit = env_has('ZSESSION_OBJECT_LIMIT', default_limit)
        try:
            limit=int(limit)
            if limit != default_limit:
                LOG('Zope Default Object Creation', INFO,
                    ('using ZSESSION_OBJECT_LIMIT-specified max objects '
                     'value of %s' % limit))
        except ValueError:
            LOG('Zope Default Object Creation', WARNING,
                ('Noninteger value %s specified for ZSESSION_OBJECT_LIMIT, '
                 'defaulting to %s' % (limit, default_limit)))
            limit = default_limit
        if addnotify and app.unrestrictedTraverse(addnotify, None) is None:
            LOG('Zope Default Object Creation', WARNING,
                ('failed to use nonexistent "%s" script as '
                 'ZSESSION_ADD_NOTIFY' % addnotify))
            addnotify=None
        elif addnotify:
            LOG('Zope Default Object Creation', INFO,
                'using %s as add notification script' % addnotify)
        if delnotify and app.unrestrictedTraverse(delnotify, None) is None:
            LOG('Zope Default Object Creation', WARNING,
                ('failed to use nonexistent "%s" script as '
                 'ZSESSION_DEL_NOTIFY' % delnotify))
            delnotify=None
        elif delnotify:
            LOG('Zope Default Object Creation', INFO,
                'using %s as delete notification script' % delnotify)

        toc = TransientObjectContainer('session_data',
              'Session Data Container', addNotification = addnotify,
              delNotification = delnotify, limit=limit)
        timeout_spec = env_has('ZSESSION_TIMEOUT_MINS', '')
        if timeout_spec:
            try:
                timeout_spec = int(timeout_spec)
            except ValueError:
                LOG('Zope Default Object Creation', WARNING,
                    ('"%s" is an illegal value for ZSESSION_TIMEOUT_MINS, '
                     'using default timeout instead.' % timeout_spec))
            else:
                LOG('Zope Default Object Creation', INFO,
                    ('using ZSESSION_TIMEOUT_MINS-specified session timeout '
                     'value of %s' % timeout_spec))
                toc = TransientObjectContainer('session_data',
                      'Session Data Container', timeout_mins = timeout_spec,
                      addNotification=addnotify, delNotification = delnotify,
                      limit=limit)
        tf._setObject('session_data', toc)
        tf_reserved = getattr(tf, '_reserved_names', ())
        if 'session_data' not in tf_reserved:
            tf._reserved_names = tf_reserved + ('session_data',)
        get_transaction().note('Added session_data to temp_folder')
        get_transaction().commit()
        del toc
        del addnotify
        del delnotify
        del timeout_spec
        del env_has

    del tf

    # Ensure that a browser ID manager exists
    if not hasattr(app, 'browser_id_manager'):
        from Products.Sessions.BrowserIdManager import BrowserIdManager
        bid = BrowserIdManager('browser_id_manager', 'Browser Id Manager')
        app._setObject('browser_id_manager', bid)
        get_transaction().note('Added browser_id_manager')
        get_transaction().commit()
        del bid

    # Ensure that a session data manager exists
    if not hasattr(app, 'session_data_manager'):
        from Products.Sessions.SessionDataManager import SessionDataManager
        sdm = SessionDataManager('session_data_manager',
            title='Session Data Manager',
            path='/temp_folder/session_data',
            requestName='SESSION')
        app._setObject('session_data_manager', sdm)
        get_transaction().note('Added session_data_manager')
        get_transaction().commit()
        del sdm

    # Ensure that there's an Examples folder with examples.
    # However, make sure that if the examples have been added already
    # and then deleted that we don't add them again.


    if not hasattr(app, 'Examples') and not \
       hasattr(app, '_Zope25_examples_have_been_added'):

        examples_path = os.path.join(Globals.ZOPE_HOME, \
             'import', 'Examples.zexp')

        if os.path.isfile(examples_path):
            app._importObjectFromFile(examples_path, verify=0)
            app._Zope25_examples_have_been_added=1
            get_transaction().note('Added Examples folder')
            get_transaction().commit()
        else:
            LOG('Zope Default Object Creation', INFO,
                '%s examples import file could not be found.' % examples_path)

    # b/c: Ensure that Owner role exists.
    if hasattr(app, '__ac_roles__') and not ('Owner' in app.__ac_roles__):
        app.__ac_roles__=app.__ac_roles__ + ('Owner',)
        get_transaction().note('Added Owner role')
        get_transaction().commit()

    # ensure the Authenticated role exists.
    if hasattr(app, '__ac_roles__'):
        if not 'Authenticated' in app.__ac_roles__:
            app.__ac_roles__=app.__ac_roles__ + ('Authenticated',)
            get_transaction().note('Added Authenticated role')
            get_transaction().commit()

    # Make sure we have Globals
    root=app._p_jar.root()
    if not root.has_key('ZGlobals'):
        import BTree
        app._p_jar.root()['ZGlobals']=BTree.BTree()
        get_transaction().note('Added Globals')
        get_transaction().commit()

    # Install the initial user.
    if hasattr(app, 'acl_users'):
        users = app.acl_users
        if hasattr(users, '_createInitialUser'):
            app.acl_users._createInitialUser()
            get_transaction().note('Created initial user')
            get_transaction().commit()

    # Install an error_log
    if not hasattr(app, 'error_log'):
        from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog
        error_log = SiteErrorLog()
        app._setObject('error_log', error_log)
        get_transaction().note('Added site error_log at /error_log')
        get_transaction().commit()

    install_products(app)
    install_standards(app)

    # Note that the code from here on only runs if we are not a ZEO
    # client, or if we are a ZEO client and we've specified by way
    # of env variable that we want to force products to load.
    if not doInstall():
        return

    # Check for dangling pointers (broken zclass dependencies) in the
    # global class registry. If found, rebuild the registry. Note that
    # if the check finds problems but fails to successfully rebuild the
    # registry we abort the transaction so that we don't leave it in an
    # indeterminate state.

    did_fixups=0
    bad_things=0
    try:
        if app.checkGlobalRegistry():
            LOG('Zope', INFO,
                'Beginning attempt to rebuild the global ZClass registry.')
            app.fixupZClassDependencies(rebuild=1)
            did_fixups=1
            LOG('Zope', INFO,
                'The global ZClass registry has successfully been rebuilt.')
            get_transaction().note('Rebuilt global product registry')
            get_transaction().commit()
    except:
        bad_things=1
        LOG('Zope', ERROR, 'The attempt to rebuild the registry failed.',
            error=sys.exc_info())
        get_transaction().abort()

    # Now we need to see if any (disk-based) products were installed
    # during intialization. If so (and the registry has no errors),
    # there may still be zclasses dependent on a base class in the
    # newly installed product that were previously broken and need to
    # be fixed up. If any really Bad Things happened (dangling pointers
    # were found in the registry but it couldn't be rebuilt), we don't
    # try to do anything to avoid making the problem worse.
    if (not did_fixups) and (not bad_things):

        # App.Product.initializeProduct will set this if a disk-based
        # product was added or updated and we are not a ZEO client.
        if getattr(Globals, '__disk_product_installed__', 0):
            try:
                LOG('Zope', INFO, 'New disk product detected, determining '\
                    'if we need to fix up any ZClasses.')
                if app.fixupZClassDependencies():
                    LOG('Zope', INFO, 'Repaired broken ZClass dependencies.')
                    get_transaction().commit()
            except:
                LOG('Zope', ERROR,
                    'Attempt to fixup ZClass dependencies after detecting ' \
                    'an updated disk-based product failed.',
                    error=sys.exc_info())
                get_transaction().abort()