def createUtils(root_folder, connection=None, dummy_db=None): # search in global component registry sitem = root_folder.getSiteManager() # search for ICatalog utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(ICatalog) ] instUtilityICatalog = utils[0].component if not "host_oid_index" in instUtilityICatalog.keys(): host_oid_index = FieldIndex(interface=ISearchableText, field_name='getSearchableHostOid', field_callable=True) instUtilityICatalog['host_oid_index'] = host_oid_index # search for IAdmUtilSupervisor utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor) ] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: ICatalog - create oid index for entry type 'host'") if not "host_hostname_index" in instUtilityICatalog.keys(): host_hostname_index = FieldIndex( interface=ISearchableText, field_name='getSearchableHostHostname', field_callable=True) instUtilityICatalog['host_hostname_index'] = host_hostname_index # search for IAdmUtilSupervisor utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor) ] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: ICatalog - create hostname index for entry type 'host'") if not "host_room_oid_index" in instUtilityICatalog.keys(): host_room_oid_index = TextIndex(interface=ISearchableText, field_name='getSearchableHostRoomOid', field_callable=True) instUtilityICatalog['host_room_oid_index'] = host_room_oid_index # search for IAdmUtilSupervisor utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor) ] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: ICatalog - create room index for entry type 'host'") # creates and stores the local system in ZODB # createLocalSystem(root_folder) ensureComponentFolderOnBootstrap( IHostFolder, u"Hosts", u'org.ict_ok.components.host.host.HostFolder', root_folder, sitem) transaction.get().commit() if connection is not None: connection.close()
def setupCatalog(test): intids = IntIds() component.provideUtility(intids, IIntIds) component.provideAdapter(SimpleKeyReference) cat = Catalog() cat['org_name'] = FieldIndex('name', IOrganization) cat['proj_name'] = FieldIndex('name', IProject) cat['proj_descr'] = FieldIndex('description', IProject) cat['student_name'] = FieldIndex('name', IStudent) cat['mentor_name'] = FieldIndex('name', IMentor) cat['all_students'] = AllIndex(IStudent) cat['all_mentors'] = AllIndex(IMentor) cat['all_projects'] = AllIndex(IProject) cat['all_orgs'] = AllIndex(IOrganization) m1 = Mentor() m1.name = u"John Doe" id = intids.register(m1) cat.index_doc(id, m1) p1 = Project() p1.name = u"Save the world" p1.description = u"test" id = intids.register(p1) cat.index_doc(id, p1) s1 = Student() s1.name = u"Charith" id = intids.register(s1) cat.index_doc(id, s1) s2 = Student() s2.name = u"Jane" id = intids.register(s2) cat.index_doc(id, s2) s3 = Student() s3.name = u"Ann" id = intids.register(s3) cat.index_doc(id, s3) o1 = Organization() o1.name = u"Zope.org" id = intids.register(o1) cat.index_doc(id, o1) # cat2 = zc.relation.catalog.Catalog(dumpRelation, loadRelation) # cat2.addValueIndex(IProjectRelation['project'], dumpObj, loadObj, btree=BTrees.family32.OO) # cat2.addValueIndex(IProjectRelation['mentor'], dumpObj, loadObj, btree=BTrees.family32.OO) # cat2.addDefaultQueryFactory(zc.relation.queryfactory.TransposingTransitive('project','mentor')) # # rel = ProjectRelation(m1, p1) # cat2.index(rel) # component.provideUtility(cat2, zc.relation.interfaces.ICatalog, name='rel-catalog') component.provideUtility(cat, ICatalog, name='foo-catalog')
def bootStrapSubscriberDatabase(event): """initialisation of esx_vim utility on first database startup """ if appsetup.getConfigContext().hasFeature('devmode'): logger.info(u"starting bootStrapSubscriberDatabase (org.ict_ok...)") EsxVimConnectionThread.database = event.database dummy_db, connection, dummy_root, root_folder = \ getInformationFromEvent(event) madeAdmUtilEsxVim = ensureUtility(root_folder, IAdmUtilEsxVim, 'AdmUtilEsxVim', AdmUtilEsxVim, '', copy_to_zlog=False, asObject=True) if isinstance(madeAdmUtilEsxVim, AdmUtilEsxVim): logger.info(u"bootstrap: Ensure named AdmUtilEsxVim") dcore = IWriteZopeDublinCore(madeAdmUtilEsxVim) dcore.title = u"ESX VIM" dcore.created = datetime.utcnow() madeAdmUtilEsxVim.ikName = dcore.title madeAdmUtilEsxVim.__post_init__() #madeAdmUtilEsxVim.connect2VimServer() sitem = root_folder.getSiteManager() utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor)] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: made IAdmUtilEsxVim-Utility") #else: #sitem = root_folder.getSiteManager() #utils = [ util for util in sitem.registeredUtilities() #if util.provided.isOrExtends(IAdmUtilEsxVim)] #instAdmUtilEsxVim = utils[0].component #instAdmUtilEsxVim.connect2VimServer() sitem = root_folder.getSiteManager() # search for ICatalog utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(ICatalog)] instUtilityICatalog = utils[0].component if not "host_esx_uuid_index" in instUtilityICatalog.keys(): host_esx_uuid_index = FieldIndex(interface=ISearchableText, field_name='getSearchableEsxUuid', field_callable=True) instUtilityICatalog['host_esx_uuid_index'] = host_esx_uuid_index # search for IAdmUtilSupervisor utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor)] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: ICatalog - create esx uuid index for entry type 'host'") recursiveEsxVimSubscriber(root_folder) transaction.get().commit() connection.close()
def setupCatalog(test, optCount=10, unoptCount=10, halfCount=10): intids = IntIds() component.provideUtility(intids, IIntIds) component.provideAdapter(SimpleKeyReference) cat = Catalog() cat['opt_name'] = FieldIndex('name', IOptimizedClass) cat['opt_value'] = FieldIndex('value', IOptimizedClass) cat['half_name'] = FieldIndex('name', IHalfOptimizedClass) cat['half_valueOpt'] = FieldIndex('value', IHalfOptimizedClass) cat['all_opt'] = AllIndex(IOptimizedClass) cat['all_unopt'] = AllIndex(IUnOptimizedClass) cat['all_half'] = AllIndex(IHalfOptimizedClass) for i in range(optCount): o = OptimizedClass() o.value = i o.name = unicode(i) id = intids.register(o) cat.index_doc(id, o) for i in range(unoptCount): o = UnOptimizedClass() o.value = i o.name = unicode(i) id = intids.register(o) cat.index_doc(id, o) for i in range(halfCount): o = HalfOptimizedClass() o.valueOpt = i o.valueNoOpt = i o.name = unicode(i) id = intids.register(o) cat.index_doc(id, o) component.provideUtility(cat, ICatalog, name='foo-catalog')
def createUtils(root_folder, connection=None, dummy_db=None): madeAdmUtilEsxVim = ensureUtility(root_folder, IAdmUtilEsxVim, 'AdmUtilEsxVim', AdmUtilEsxVim, name='AdmUtilEsxVim', copy_to_zlog=False, asObject=True) if isinstance(madeAdmUtilEsxVim, AdmUtilEsxVim): logger.info(u"bootstrap: Ensure named AdmUtilEsxVim") dcore = IWriteZopeDublinCore(madeAdmUtilEsxVim) dcore.title = u"ESX VIM" dcore.created = datetime.utcnow() madeAdmUtilEsxVim.ikName = dcore.title madeAdmUtilEsxVim.__post_init__() #madeAdmUtilEsxVim.connect2VimServer() sitem = root_folder.getSiteManager() utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor) ] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: made IAdmUtilEsxVim-Utility") sitem = root_folder.getSiteManager() # search for ICatalog utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(ICatalog) ] instUtilityICatalog = utils[0].component if not "host_esx_uuid_index" in instUtilityICatalog.keys(): host_esx_uuid_index = FieldIndex(interface=ISearchableText, field_name='getSearchableEsxUuid', field_callable=True) instUtilityICatalog['host_esx_uuid_index'] = host_esx_uuid_index # search for IAdmUtilSupervisor utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor) ] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: ICatalog - create esx uuid index for entry type 'host'") recursiveEsxVimSubscriber(root_folder) transaction.get().commit() if connection is not None: connection.close()
def setup_catalog(catalog): catalog['name'] = FieldIndex('name', IMammoth)
def bootStrapSubscriber(event): """initialisation of IntId utility on first database startup """ if appsetup.getConfigContext().hasFeature('devmode'): logger.info(u"starting bootStrapSubscriberDatabase (org.ict_ok...)") dummy_db, connection, dummy_root, root_folder = \ getInformationFromEvent(event) # search in global component registry sitem = root_folder.getSiteManager() # search for ICatalog utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(ICatalog) ] instUtilityICatalog = utils[0].component if not "host_oid_index" in instUtilityICatalog.keys(): host_oid_index = FieldIndex(interface=ISearchableText, field_name='getSearchableHostOid', field_callable=True) instUtilityICatalog['host_oid_index'] = host_oid_index # search for IAdmUtilSupervisor utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor) ] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: ICatalog - create oid index for entry type 'host'") if not "host_hostname_index" in instUtilityICatalog.keys(): host_hostname_index = FieldIndex( interface=ISearchableText, field_name='getSearchableHostHostname', field_callable=True) instUtilityICatalog['host_hostname_index'] = host_hostname_index # search for IAdmUtilSupervisor utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor) ] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: ICatalog - create hostname index for entry type 'host'") if not "host_room_oid_index" in instUtilityICatalog.keys(): host_room_oid_index = TextIndex(interface=ISearchableText, field_name='getSearchableHostRoomOid', field_callable=True) instUtilityICatalog['host_room_oid_index'] = host_room_oid_index # search for IAdmUtilSupervisor utils = [ util for util in sitem.registeredUtilities() if util.provided.isOrExtends(IAdmUtilSupervisor) ] instAdmUtilSupervisor = utils[0].component instAdmUtilSupervisor.appendEventHistory(\ u" bootstrap: ICatalog - create room index for entry type 'host'") # creates and stores the local system in ZODB # createLocalSystem(root_folder) transaction.get().commit() connection.close()