Usage of Trac API from an external Python script

490 views
Skip to first unread message

noamtm

unread,
Dec 13, 2011, 3:11:33 AM12/13/11
to Trac Users
I want to write a Python script that accesses Trac through its API.
Specifically, I want to send users a daily email with ticket changes
(similar to what they would get by visiting /timeline?
daysback=1&ticket=on&milestone=on).

I want to run this script in the same server that hosts Trac itself.
Ideally, I want to use Trac's existing code to generate html or at
least TSV, but it seems that the functions that do it require an
"running" http Request object, which I don't have when running the
script outside of Trac.

Is there a way to get html/CSV/TSV query results from an external
script, or do I have to write the SQL myself?

Thanks,
Noam.

Zwinki

unread,
Dec 13, 2011, 9:21:16 AM12/13/11
to trac-...@googlegroups.com
On Tuesday, 13 Dec 2011, 09:11:33 noamtm wrote:
> I want to write a Python script that accesses Trac through its API.
> Specifically, I want to send users a daily email with ticket changes
> (similar to what they would get by visiting /timeline?
> daysback=1&ticket=on&milestone=on).

The XmlRpc Plugin is the appropriate way for this. The
getRecentChanges() method (the XMLRPC interface is described via Web
frontent of Trac) gives numbers oft new tickets - mind that UTC time is
taken as argument. Don't forget to allow XMLRPC for the user which runs
the Python script ...

... and one more remark:

When you only add an attachment, at least in Trac 0.11.7 the
modification time does not change, so getRecentChanges() does not list
this ticket (if an comment is added or some field changes, anything is
fine). I don't know whether this is the case for Trac 0.12, too; in the
next time I will look and possibly try to fix this problem.

Greetings,

Reinhard

Olemis Lang

unread,
Dec 13, 2011, 12:07:08 PM12/13/11
to trac-...@googlegroups.com
On Tue, Dec 13, 2011 at 9:21 AM, Zwinki <zwi...@gmx.de> wrote:
> On Tuesday, 13 Dec 2011, 09:11:33 noamtm wrote:
>> I want to write a Python script that accesses Trac through its API.
>> Specifically, I want to send users a daily email with ticket changes
>> (similar to what they would get by visiting /timeline?
>> daysback=1&ticket=on&milestone=on).
>
> The XmlRpc Plugin is the appropriate way for this. The
> getRecentChanges() method (the XMLRPC interface is described via Web
> frontent of Trac) gives numbers oft new tickets - mind that UTC time is
> taken as argument. Don't forget to allow XMLRPC for the user which runs
> the Python script ...
>

In TracGViz plugin there is an implementation of an RPC handler
(component name : TimelineRPC) for Trac timeline (which , in theory,
is quite much more than just tickets + wiki events considering it's
underlying pluggable nature allowing to extend it and add further
timeline contributors e.g. Hudson build results ;) .

Besides there's a GViz data source (component name :
GVizTimelineEvents) which may be used to download timeline data in CSV
& TSV format (... and others as well ...).

PS: All this will be migrated onto TracXmlRpc plugin eventually = once
I have the time & gasoline to develop Trac plugins once again +
immediately after plugin maintainer will approve patches I'll submit .
;)

PS: PS: Documentation for the plugin should be online as soon as I
solve some issues happening in my hosting environment . I'll post an
announcement to trac-users list once it will be ready .
;)

> ... and one more remark:
>
> When you only add an attachment, at least in Trac 0.11.7 the
> modification time does not change, so getRecentChanges() does not list
> this ticket (if an comment is added or some field changes, anything is
> fine). I don't know whether this is the case for Trac 0.12, too; in the
> next time I will look and possibly try to fix this problem.
>

Yes ... there's a way to get this and all other ticket modifications
reported in the timeline . Configuration option is ... mmmm ... where
r u babe ? come to daddy ! ... here it is :

{{{
ticket_show_details
 true  false

Enable the display of all ticket changes in the timeline, not only
open / close operations (since 0.9).
}}}

so you should have something like this in trac.ini

{{{
[timeline]
ticket_show_details = true
}}}

... and events will be there ... ;)

PS: In order for them to show up in Trac web site you need to check
`Ticket updates` timeline filter . They are not rendered by default ,
even if option set to true ;)

--

Regards,

Olemis

Facebook => http://www.facebook.com/olemis
Twitter => http://www.twitter.com/olemislc (@olemislc)
Blog ES => http://simelo-es.blogspot.com
Blog EN => http://simelo-en.blogspot.com
Quora => http://www.quora.com/olemis
Youtube => http://youtube.com/user/greatsoftw

Featured article : Personalizando imagenes mostradas al compartir
páginas en sitios sociales
http://feedproxy.google.com/~r/simelo-news/~3/nSdht_RqLKk/personalizando-imagenes-mostradas-al.html
Tweet: iPhone o iPad ? RT @iroko Cada vez que quiero escribir "chen",
iOS los sustituye por "chencha". Alerto #fb
Follow @olemislc Reply Retweet   11:03 Dec-13
  Get this email app!
Get a signature like this. CLICK HERE.

Reply all
Reply to author
Forward
0 new messages