项目

通用

个人资料

操作

使用Python的REST API

以下是使用Python的REST API可用的库列表

  1. Python-Redmine
  2. PyRedmineWS
  3. PyActiveResource
  4. PyRed

Python-Redmine:

Python-Redmine是一个支持Redmine的REST API 100%功能的库。它提供了一个简单但功能强大的Pythonic API,灵感来源于著名的Django ORM,并且经过彻底测试。示例

>>> from redminelib import Redmine

>>> redmine = Redmine('http://demo.redmine.org', username='foo', password='bar')
>>> project = redmine.project.get('vacation')

>>> project.id
30404

>>> project.identifier
'vacation'

>>> project.created_on
datetime.datetime(2013, 12, 31, 13, 27, 47)

>>> project.issues
<redminelib.resultsets.ResourceSet object with Issue resources>

>>> project.issues[0]
<redminelib.resources.Issue #34441 "Vacation">

>>> dir(project.issues[0])
['assigned_to', 'author', 'created_on', 'description', 'done_ratio',
'due_date', 'estimated_hours', 'id', 'priority', 'project', 'relations',
'start_date', 'status', 'subject', 'time_entries', 'tracker', 'updated_on']

>>> project.issues[0].subject
'Vacation'

>>> project.issues[0].time_entries
<redminelib.resultsets.ResourceSet object with TimeEntry resources>

PyRedmineWS 示例:

假设Eric生病了,已经好几天没来了。你需要爬取名为Parrot的项目,并将分配给Eric的所有问题的到期日推迟两周。

dateutil库包含一个名为relativedelta的方便方法,用于计算相对日期。

# Import the Redmine class
from redmine import Redmine
from dateutil.relativedelta import relativedelta

server = Redmine('http://my-server.com', username='Me', password='seakrit')
project = server.projects['parrot']

# Find Eric in the user data
for u in server.users:
    if u.firstname == 'Eric' and u.lastname == 'Idle':
       user = u
       break
else:
    raise Exception("Didn't find Eric Idle in the user dateabase")

# Extend issues in project assigned to user by two weeks
for issue in project.issues(assigned_to_id=user.id):
    if issue.due_date is not None:
       issue.due_date += relativedelta(weeks=+2)
       issue.save('Giving Eric more time to complete - he was out ill')

PyActiveResource 示例:

# Importing pyactiveresource
from pyactiveresource.activeresource import ActiveResource

class Issue(ActiveResource):
    _site = 'http://redmine.foo.org'
    _user = 'username'
    _password = 'password'

# Get issues
issues = Issue.find()

# Get a specific issue, from its id
issue = Issue.find(1345)

# Issue attributes

# Updating an attribute

PyRed 示例:待定

Max Tepkeev更新 超过7年前 · 18次修订