plone.recipe.zope2instance的命名实例运行脚本入口点
collective.runhook的Python项目详细描述
在包中的某个模块中将脚本实现为 函数接受上下文和请求作为其参数:
defwhoami(context,request):fromAccessControl.SecurityManagementimportgetSecurityManageruser=getSecurityManager().getUser()return{'absolute_url':context.absolute_url(),'context':context.__repr__(),'user':user.__repr__(),'getId':user.getId(),'getUserName':user.getUserName(),'getRoles':user.getRoles(),'getRolesInContext':user.getRolesInContext(context)}
当脚本修改 数据库(上面的示例没有):
importtransactiontransaction.commit()
将函数注册为 collective.runhook*在包的setup.py中::
fromsetuptoolsimportsetupsetup(# ...entry_points=""" # -*- Entry points: -*- # ... [collective.runhook] whoami = my.package:whoami """)
添加collective.runhook作为包的依赖项,或将其包含在 构建的实例部分:
[buildout]parts=instance# ...[instance]recipe=plone.recipe.zope2instance# ...eggs= Plone# ...collective.runhook
运行构建并执行脚本:
$ bin/instance runhook whoami ... {'absolute_url': 'http://nohost/Plone', 'context': '<Application at >', 'getId': None, 'getRoles': ('manage', 'Authenticated'), 'getRolesInContext': ['manage', 'Authenticated'], 'getUserName': 'System Processes', 'user': "<UnrestrictedUser 'System Processes'>"}
collective.runhook遵循与 运行命令:
$ bin/instance -OPlone runhook whoami ... {'absolute_url': 'http://nohost/Plone', 'context': '<PloneSite at /Plone>', 'getId': None, 'getRoles': ('manage', 'Authenticated'), 'getRolesInContext': ['manage', 'Authenticated'], 'getUserName': 'System Processes', 'user': "<UnrestrictedUser 'System Processes'>"}作为一个额外的奖励,{ 1。} 使用ZOPE_USER环境变量指定的用户(但请注意 身份验证仅在-O-遍历之后完成:
$ ZOPE_USER=datakurre bin/instance -OPlone runhook whoami ... {'absolute_url': 'http://nohost/Plone', 'context': '<PloneSite at /Plone>', 'getId': 'datakurre', 'getRoles': ['Member', 'Reviewer', 'Site Administrator', 'Authenticated'], 'getRolesInContext': ['Member', 'Reviewer', 'Site Administrator', 'Authenticated'], 'getUserName': 'datakurre', 'user': "<PloneUser 'datakurre'>"}
我们确实支持带有virtualhostbase:
$ ZOPE_USER=datakurre bin/instance -O/VirtualHostBase/http://example.com:80/Plone/VirtualHostRoot/Plone runhook whoami ... {'absolute_url': 'http://example.com', 'context': '<PloneSite at /Plone>', 'getId': 'datakurre', 'getRoles': ['Member', 'Reviewer', 'Site Administrator', 'Authenticated'], 'getRolesInContext': ['Member', 'Reviewer', 'Site Administrator', 'Authenticated'], 'getUserName': 'datakurre', 'user': "<PloneUser 'datakurre'>"}
变更日志
0.9.5(2014-09-28)
- 修复以迭代使用相同名称的所有入口点以支持多个 具有相同挂钩名称的脚本 [数据库]
- 修复pprint脚本返回值不需要脚本自行打印 [数据库]
0.9.4(2014-09-26)
- 修复以打印挂钩的结果(非假时) [数据库]
0.9.3(2014-09-25)
- 添加对VirtualHostMonster URL的支持 [数据库]
0.9.2(2014-09-25)
- 修复从入口点读取错误属性的问题 [数据库]
0.9.1(2014-09-24)
- 更新自述文件 [数据库]
0.9.0(2014-09-24)
- 第一次释放。