Back to index

plone3  3.1.7
PloneInitialize.py
Go to the documentation of this file.
00001 from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod
00002 from Products.SiteAccess.SiteRoot import manage_addSiteRoot
00003 from Products.SiteAccess.AccessRule import manage_addAccessRule
00004 import transaction
00005 
00006 from AccessControl.SecurityManagement import newSecurityManager
00007 from AccessControl.SecurityManagement import noSecurityManager
00008 
00009 def create(app, admin_username='admin'):
00010     out = []
00011     oids = app.objectIds()
00012 
00013     # these are the two set elements...
00014     # (accessRule.py external method and SiteRoot)
00015     eid = 'accessRule.py'
00016     pid = 'Plone'
00017     emod = 'CMFPlone.accessRule'
00018     efn = 'accessRule'
00019     sid = 'SiteRoot'
00020 
00021     if pid in oids:
00022         out.append("A Plone site already exists")
00023         return out
00024 
00025     # 1 .get the admin user (dont bother making it, it's done before you
00026     #                        get a chance)
00027 
00028     acl_users = app.acl_users
00029 #    info = User.readUserAccessFile('inituser')
00030 #    if info:
00031 #        acl_users._doAddUser(info[0], info[1], ('manage',), [])
00032 
00033     user = acl_users.getUser(admin_username)
00034     if user:
00035         user = user.__of__(acl_users)
00036         newSecurityManager(None, user)
00037         out.append("Retrieved the admin user")
00038     else:
00039         out.append("Retrieving admin user failed")
00040 
00041     # 2. create the access rule external method
00042     if eid not in oids:
00043         # this is the actual access rule
00044         manage_addExternalMethod(app,
00045                                  eid,
00046                                  'Plone Access Rule',
00047                                  emod,
00048                                  efn)
00049         out.append("Added external method")
00050         # this sets the access rule
00051         manage_addAccessRule(app, eid)
00052         out.append("Set an access rule")
00053 ##         if user:
00054 ##             getattr(app, eid).changeOwnership(user)
00055 
00056     # 3. actually add in Plone
00057     if pid not in oids:
00058         factory = app.manage_addProduct['CMFPlone']
00059         factory.addPloneSite(pid, create_userfolder=1)
00060         out.append("Added Plone")
00061 ##         if user:
00062 ##             getattr(app, pid).changeOwnership(user, recursive=1)
00063 
00064     # 4. adding the site root in
00065     plone = getattr(app, pid)
00066     if sid not in plone.objectIds():
00067         manage_addSiteRoot(plone)
00068         out.append("Added Site Root")
00069 ##         if user:
00070 ##             getattr(plone, sid).changeOwnership(user)
00071 
00072     # 5. add in products
00073     qit = plone.portal_quickinstaller
00074 
00075     products_to_install = ["kupu",]
00076     ids = [ x['id'] for x in qit.listInstallableProducts(skipInstalled=1) ]
00077     for product in products_to_install:
00078         if product in ids:
00079             qit.installProduct(product)
00080 
00081     # 6. commit
00082     transaction.commit()
00083 
00084     noSecurityManager()
00085     out.append("Finished")
00086     return out