死或活链接检查器服务的ckan扩展
ckanext-deadoralive的Python项目详细描述
[![生成状态](https://travis-ci.org/ckan/ckanext-deadoralive.png)](https://travis-ci.org/ckan/ckanext-deadoralive)[![覆盖状态](https://img.shields.io/coveralls/ckan/ckanext-deadoralive.svg)](https://coveralls.io/r/ckan/ckanext-deadoralive?branch=master)
ckanext deadoralive
ckanext dead or alive是[dead或alive link checker service](https://github.com/ckan/deadoralive)的ckan扩展。 它提供了一个api,允许链接检查器检查ckan站点, 处理将链接检查器发布的结果保存到ckan的数据库和 向ckan站点添加各种断开的链接报告。
待办事项:报告截图。
要求
使用ckan 2.2和python2.7进行测试。不支持Python2.6!
安装和使用
激活您的ckan virtualenv,然后:
pip install ckanext-deadoralive
将deadoralive添加到ckan配置文件中的ckan.plugins设置。
为链接检查器创建要使用的用户帐户。
在运行链接检查器服务之前,您需要一个ckan用户帐户 供其使用。我建议创建一个新的用户帐户 只用于链接检查器而不是使用管理帐户,因此 检查器可以以尽可能少的权限运行。
您可以通过使用ckan的web注册新帐户来创建用户帐户 接口,或者使用[ckan的命令行接口](http://docs.ckan.org/en/latest/maintaining/paster.html#user-create-and-manage-users)。
为链接检查器创建用户帐户后,添加此配置 设置到ckan配置文件的[app:main]部分:
# The names of the users who’re allowed to access the deadoralive # plugin’s API to post link checker results. # The API key of one of these users must be passed to deadoralive.py # when you run it. ckanext.deadoralive.authorized_users = deadoralive
(在本例中,deadoralive是我们 已创建,但您可以随意调用此帐户。)
现在通过重新启动web服务器来重新启动ckan。你应该看到 断开的链接报告页将显示在您的网站上。开始他们会报告 没有断开的链接-因为你还没有检查站点是否有断开的链接。
现在转到[死亡或活着](https://github.com/ckan/deadoralive),然后 安装链接检查器(在安装ckan的同一台计算机上 或者在另一台机器上-没关系)。你的api密钥 将链接检查器配置为应该是用户的api密钥 在上面的步骤3中创建。对您的ckan站点运行链接检查器,然后 您将开始看到网站上出现断开的链接报告。
可选配置设置
在ckan配置文件的[app:main]部分中:
# The minimum number of hours to wait before re-checking a resource # (optional, default: 24). ckanext.deadoralive.recheck_resources_after = 24
# The minimum number of hours to wait for a check result for a resource # to come back before timing out and giving the resource out again to # another link checker task (optional, default: 2). ckanext.deadoralive.resend_pending_resources_after = 2
# The minimum number of times that checking a resource’s link must fail # consecutively before we mark that resource as broken in CKAN. ckanext.deadoralive.broken_resource_min_fails = 3
# The minimum number of hours that a resource’s link must be broken for # before we mark that resource as broken in CKAN. ckanext.deadoralive.broken_resource_min_hours = 36
发展
要安装用于开发的插件,请激活ckan virtualenv并执行以下操作:
git clone https://github.com/ckan/ckanext-deadoralive.git cd ckanext-deadoralive python setup.py develop pip install -r dev-requirements.txt
###创建测试数据集
要创建一些包含工作链接和断开链接的测试数据集,请执行以下操作:
python create_test_resources.py –url ‘http://your.ckan.site.com’ –apikey <your_api_key>
默认情况下,deadoralive插件不会将资源标记为已断开,除非它 在一段时间内至少连续三次断开链接检查 至少三天。另外,在检查了一个链接之后,插件不会重新检查它 至少24小时。
为了开发,您可能需要放松这些设置,以便可以标记 更快地测试资源。将这些设置添加到配置文件:
ckanext.deadoralive.recheck_resources_after = 0 ckanext.deadoralive.broken_resource_min_hours = 0 ckanext.deadoralive.resend_pending_resources_after = 0
这将允许您连续多次运行链接检查器,并重新检查所有 这些链接,不用等待24小时来重新检查一个链接。它还会将链接标记为 一经检查连续三次发现有破损, 不管检查的时间长短。
###运行测试
请注意,您应该在以下情况下签出ckan的release-v2.2分支 你运行这些测试。ckanext deadoralive分支当前 对travis上ckan的release-v2.2分支进行了测试。
从ckanext deadoralive目录运行:
nosetests –nologcapture –with-pylons=test.ini
要运行测试并生成覆盖率报告,首先确保 在您的virtualenv中安装了coverage(pip install coverage),然后运行:
nosetests –nologcapture –with-pylons=test.ini –with-coverage –cover-package=ckanext.deadoralive –cover-inclusive –cover-erase –cover-tests