예제 #1
0
    def _getImportContext(self, context_id, should_purge=None, archive=None):
        """ Crack ID and generate appropriate import context.
        """
        encoding = self.getEncoding()

        if context_id is not None:
            if context_id.startswith('profile-'):
                context_id = context_id[len('profile-'):]
                info = _profile_registry.getProfileInfo(context_id)

                if info.get('product'):
                    path = os.path.join(_getProductPath(info['product']),
                                        info['path'])
                else:
                    path = info['path']
                if should_purge is None:
                    should_purge = (info.get('type') != EXTENSION)
                return DirectoryImportContext(self, path, should_purge,
                                              encoding)

            elif context_id.startswith('snapshot-'):
                context_id = context_id[len('snapshot-'):]
                if should_purge is None:
                    should_purge = True
                return SnapshotImportContext(self, context_id, should_purge,
                                             encoding)

        if archive is not None:
            return TarballImportContext(tool=self,
                                       archive_bits=archive,
                                       encoding='UTF8',
                                       should_purge=should_purge,
                                      )

        raise KeyError('Unknown context "%s"' % context_id)
예제 #2
0
파일: utils.py 프로젝트: kkdhanesh/NBADEMO
def installTypeIfNeeded(type_name):
    """Make sure the dexterity-fti is already installed.
    If not we create a empty dexterity fti and load the
    information from the fti in the profile.
    """
    if type_name not in DEFAULT_TYPES:
        raise KeyError("%s is not one of the default types" % type_name)
    portal = getSite()
    tt = getToolByName(portal, 'portal_types')
    fti = tt.getTypeInfo(type_name)
    if IDexterityFTI.providedBy(fti):
        # The dx-type is already installed, so keep it.  But this
        # might be an old dexterity type of Collection, in which case
        # it is better to replace it.
        if type_name != 'Collection':
            return
        if fti.klass == 'plone.app.contenttypes.content.Collection':
            # If the klass is fine, we are happy.
            return
    if fti:
        tt.manage_delObjects(type_name)
    tt.manage_addTypeInformation('Dexterity FTI', id=type_name)
    dx_fti = tt.getTypeInfo(type_name)
    ps = getToolByName(portal, 'portal_setup')
    profile_info = ps.getProfileInfo('profile-plone.app.contenttypes:default')
    profile_path = os.path.join(profile_info['path'])
    environ = DirectoryImportContext(ps, profile_path)
    parent_path = 'types/'
    importObjects(dx_fti, parent_path, environ)
예제 #3
0
    def test_setuphandler(self):
        default_profile_path = os.path.join(
            os.path.dirname(ftw.bridge.client.__file__), 'profiles', 'default')

        with z2.zopeApp() as app:
            acl_users = app.acl_users
            self.assertFalse(setuphandlers.PLUGIN_ID in acl_users.objectIds())

            setup = DirectoryImportContext(app.acl_users, default_profile_path)
            setuphandlers.setup_bridge_pas_plugin(setup)

            self.assertTrue(setuphandlers.PLUGIN_ID in acl_users.objectIds())

            # Does not fail on another call
            setuphandlers.setup_bridge_pas_plugin(setup)
예제 #4
0
 def test_pm_ToolAttributesAreOnlySetOnFirstImportData(self):
     '''The tool attributes are set the first time it is imported, if some
        import_data are imported after, it does not change the tool attributes.'''
     # testing import_data has been imported, change a parameter in the tool
     # and import_data again to check
     self.changeUser('admin')
     self.assertFalse(self.tool.restrictUsers)
     self.tool.setRestrictUsers(True)
     # make sure restrictUsers is set in the 'testing' profile import_data
     profile_names = self._currentSetupProfileNames()
     profile_name = [p_name for p_name in profile_names if p_name.endswith(':testing')][0]
     profile_infos = [profile for profile in self.portal.portal_setup.listProfileInfo()
                      if profile['id'] == profile_name][0]
     path = profile_infos['path']
     import_context = DirectoryImportContext(self.portal.portal_setup, path)
     import imp
     import_data = imp.load_source('', import_context._profile_path + '/import_data.py')
     self.assertFalse(import_data.data.restrictUsers)
     self.portal.portal_setup.runAllImportStepsFromProfile(u'profile-' + profile_name)
     # restrictUsers is still True
     self.assertTrue(self.tool.restrictUsers)
예제 #5
0
def installTypeIfNeeded(type_name):
    """Make sure the dexterity-fti is already installed.
    If not we create a empty dexterity fti and load the
    information from the fti in the profile.
    """
    if type_name not in DEFAULT_TYPES:
        raise KeyError("%s is not one of the default types" % type_name)
    portal = getSite()
    tt = getToolByName(portal, 'portal_types')
    fti = tt.getTypeInfo(type_name)
    if IDexterityFTI.providedBy(fti):
        # the dx-type is already installed
        return
    if fti:
        tt.manage_delObjects(type_name)
    tt.manage_addTypeInformation('Dexterity FTI', id=type_name)
    dx_fti = tt.getTypeInfo(type_name)
    ps = getToolByName(portal, 'portal_setup')
    profile_info = ps.getProfileInfo('profile-plone.app.contenttypes:default')
    profile_path = os.path.join(profile_info['path'])
    environ = DirectoryImportContext(ps, profile_path)
    parent_path = 'types/'
    importObjects(dx_fti, parent_path, environ)