File: PloneInitialize.py

package info (click to toggle)
zope-cmfplone 2.0.4-3sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,992 kB
  • ctags: 2,558
  • sloc: python: 12,755; makefile: 102; sh: 67
file content (94 lines) | stat: -rw-r--r-- 3,071 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod
from Products.CMFPlone.Portal import manage_addSite
from Products.SiteAccess.SiteRoot import manage_addSiteRoot
from Products.SiteAccess.AccessRule import manage_addAccessRule

from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager

def create(app, admin_username='admin'):
    out = []
    oids = app.objectIds()

    # these are the two set elements...
    # (accessRule.py external method and SiteRoot)
    eid = 'accessRule.py'
    pid = 'Plone'
    emod = 'CMFPlone.accessRule'
    efn = 'accessRule'
    sid = 'SiteRoot'

    if pid in oids:
        out.append("A Plone site already exists")
        return out

    # 1 .get the admin user (dont bother making it, it's done before you
    #                        get a chance)

    acl_users = app.acl_users
#    info = User.readUserAccessFile('inituser')
#    if info:
#        acl_users._doAddUser(info[0], info[1], ('manage',), [])

    user = acl_users.getUser(admin_username)
    if user:
        user = user.__of__(acl_users)
        newSecurityManager(None, user)
        out.append("Retrieved the admin user")
    else:
        out.append("Retrieving admin user failed")

    # 2. create the access rule external method
    if eid not in oids:
        # this is the actual access rule
        manage_addExternalMethod(app,
                                 eid,
                                 'Plone Access Rule',
                                 emod,
                                 efn)
        out.append("Added external method")
        # this sets the access rule
        manage_addAccessRule(app, eid)
        out.append("Set an access rule")
##         if user:
##             getattr(app, eid).changeOwnership(user)

    # 3. actually add in Plone
    if pid not in oids:
        manage_addSite(app,
                   pid,
                   title='Portal',
                   description='',
                   create_userfolder=1,
                   email_from_address='postmaster@localhost',
                   email_from_name='Portal Administrator',
                   validate_email=0,
                   custom_policy='Default Plone',
                   RESPONSE=None)
        out.append("Added Plone")
##         if user:
##             getattr(app, pid).changeOwnership(user, recursive=1)

    # 4. adding the site root in
    plone = getattr(app, pid)
    if sid not in plone.objectIds():
        manage_addSiteRoot(plone)
        out.append("Added Site Root")
##         if user:
##             getattr(plone, sid).changeOwnership(user)

    # 5. add in products
    qit = plone.portal_quickinstaller

    products_to_install = ["Epoz",]
    ids = [ x['id'] for x in qit.listInstallableProducts(skipInstalled=1) ]
    for product in products_to_install:
        if product in ids:
            qit.installProduct(product)

    # 6. commit
    get_transaction().commit()

    noSecurityManager()
    out.append("Finished")
    return out