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)

  • 第一次释放。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java类StatusCode扩展了枚举<StatusCode>   尝试将JavaFX与Hibernate集成时出现java错误   java对列表进行排序需要很多时间   数组在JSONArray(JSONSimple/JAVA)中创建JSONObject   java试图从控制台识别非重复值,并将非重复值打印到输出   java在DoFn(apache crunch)中传递映射(或并发hashmap)   java操作栏自定义组件(自定义开关)未与actionLayout一起显示   java我在一个布局中创建了两个回收器视图,我有nullPointerException   java我应该在目标目录中放置什么?   数据存储应用程序引擎和objectify中的java持久化关系   java为基于回合的2人棋盘游戏创建网络连接   java从不可变集合创建可变集合   javajsoup与regex的匹配