TracへHudsonへリンクを張るためのマクロを追加
こちらにあったものをそのまま使おうとしたが、自分が使っている環境
(Trac 0.11RC2, Hudson 1.226)ではうまく行かなかったので、下記のように修正後、適当な名前で、
Tracのプロジェクト内のpluginsディレクトリに突っ込んでみた。
# -*- coding: utf-8 -*-
from trac.wiki.macros import WikiMacroBase
class RefHudsonBuildMacro(WikiMacroBase):
"""
Job の ビルドへのリンクを表示します。
例:
{{{
Hudson(job1, 5) # job名がjob1, ビルド番号が5のページにリンク
}}}
"""
def get_macros(self):
"""Yield the name of the macro based on the class name."""
yield 'Hudson'
def expand_macro(self, formatter, name, content):
# args will be null if the macro is called without parenthesis.
if not content:
return ''
# parse arguments
# we expect the 1st argument to be a filename (filespec)
args = content.split(',')
if len(args) < 2:
raise Exception("Invalid arguments.")
hudson_url = self.env.config.get('hudson', 'main_page')
job_name = args[0].strip()
build_no = args[1].strip()
return "<a class=\"ext-link\" href=\"" + hudson_url + "/job/" + job_name + "/" + build_no +"\"><span class=\"icon\">Hudson:" + job_name + " #" + build_no + "</span></a>"
(Trac 0.11RC2, Hudson 1.226)ではうまく行かなかったので、下記のように修正後、適当な名前で、
Tracのプロジェクト内のpluginsディレクトリに突っ込んでみた。
# -*- coding: utf-8 -*-
from trac.wiki.macros import WikiMacroBase
class RefHudsonBuildMacro(WikiMacroBase):
"""
Job の ビルドへのリンクを表示します。
例:
{{{
Hudson(job1, 5) # job名がjob1, ビルド番号が5のページにリンク
}}}
"""
def get_macros(self):
"""Yield the name of the macro based on the class name."""
yield 'Hudson'
def expand_macro(self, formatter, name, content):
# args will be null if the macro is called without parenthesis.
if not content:
return ''
# parse arguments
# we expect the 1st argument to be a filename (filespec)
args = content.split(',')
if len(args) < 2:
raise Exception("Invalid arguments.")
hudson_url = self.env.config.get('hudson', 'main_page')
job_name = args[0].strip()
build_no = args[1].strip()
return "<a class=\"ext-link\" href=\"" + hudson_url + "/job/" + job_name + "/" + build_no +"\"><span class=\"icon\">Hudson:" + job_name + " #" + build_no + "</span></a>"