trac customization

Posted at 2009/04/23 01:22  Posted by YT,Lim
trac을 설치하였으니, 이제 project에 따라 입맛에 맞게 최적화 시킬 차례다.

Project logo와 css style 적용

trac의 project directory를 살펴보면, 하위에 htdocs가 있다.  htdocs에 올린 file은 trac wiki에서 site/<filename>으로 접근할 수 있다.

Project logo image 띄우기

project의 htdocs (여기서는 /var/lib/trac/test/htdocs/)에 logo로 사용할 image를 복사한다. wiki page에 link될 부분이니, web browser에서 보일 수 있도록 jpg, gif, png 등의 image 중에서 하나를 선택한다.

project의 trac.ini를 열어 header_logo 부분을 수정한다. (여기서는 /var/lib/trac/test/conf/trac.ini)
[header_logo]
src = site/<logo_image_file_name>
alt = <logo_image_description_text>
width = <logo_image_width>
height = <logo_image_height>

2번째 줄의 src는 image를 link 시킬 경로와 image file 이름을 적어준다. htdocs에 올리면 site/로 link되므로, site/<file name> 형식으로 쓴다.
3번째 줄의 alt는 browser에서 image를 그릴 수 없거나 image위에 mouse cursor를 올렸을 때 나타날 tooltip text를 적어준다.
4번째와 5번째 줄은 image가 그려질 영역의 폭과 높이를 설정한다. image의 원래 size와 다를 경우, 주어진 크기에 맞게 늘어나거나 줄어들 것이다.

trac wiki에 style.css 적용 및 header와 footer 적용

역시 project의 htdocs에 적용하고 싶은 style.css를 복사한다. (여기서는 /var/lib/trac/test/htdocs/)

그리고, style.css를 wiki에서 불러 오기 위해서는 기본 template를 수정해야 한다. 이 template은 trac wiki page 전체에 적용되는 것으로 출력할 trac page에 header와 footer를 덧 붙여 줄 수 있다. 이 file은 project의 templates direcotry에 있다. (여기서는 /var/lib/trac/test/templates/site.html)
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/" py:strip="">
<!--! Custom match templates go here -->
<!--! Add site-specific style sheet -->
<head py:match="head" py:attrs="select('@*')">
${select ('*|comment()|text()')}
<link rel="stylesheet" type="text/css" href="${href.chrome('site/style.css')}" />
</head>
<body py:match="body" py:attrs="select('@*')">
<!--! Add site-specific header -->
<div id="siteheader">
<!--! Place your header content here -->
</div>

${select ('*|text()')}

<!--! Add site-specific footer -->
<div id="sitefooter">
<!--! Place your footer content here -->
</div>
</body>
</html>

7번째 줄을 보면 style.css를 불러오게 되어있다. 물론 htdocs에 style.css를 넣었으므로, link할 때는 site/style.css가 된다. 10~13번째 줄에는 header를 위한 영역이, 17~20번째에는 footer를 위한 영역을 만들어 두었다. header와 footer를 각각 12, 19번째 줄에 끼워 넣으면 되겠다.

그러나, 내 경우 기본 style이 괜찮게 생겼다고 생각하고, header와 footer를 만들어 넣는 것도 귀찮아서 그냥 쓰고 있다.

Project List로의 접근 차단

trac의 root를 webbroser로 열면 각 project의 list를 확인할 수 있고, 또 연결할 수 있다. 문제는 project 외에 다른 directory가 있을 경우 해당 directory는 error로 간주되며, page 모양도 그렇게 예쁘지 않다는 것이다.

어쨌든, 이 " Available Projects"라고 나오는 page 역시 template으로 제공되어 원할 경우 수정할 수 있다. 직접 수정할 수도 있고, 만약의 경우를 대비해 file을 복사해서 다른 경로에 놓고 지정된 file을 열 수도 있다.

내 경우 해당 template은 /usr/lib64/python2.5/site-packages/trac/templates/index.html로 존재하고 있었다. 해당 file을 직접 수정하여 기밀 project는 숨기고, page 모양도 예쁘게 바꿔볼까 생각했으나 template이 python으로 되어 있어 수정 작업이 만만치 않기에 해당 page를 아예 막아 버리기로 했다.

file 수정을 위해 해당 template은 그냥 두고, index.html file을 /var/lib/trac/.projectlist.html로 복사하였다. 이 복사한 file을 지정하기 위해 apache의 vhost <Location "/trac"> block을 수정해야 한다.

/etc/apache2/vhosts.d/00_default_ssl_vhosts.conf를 열고 다음 code를 참조하여 <Location "/trac"> block에 추가
PythonOption TracEnvIndexTemplate /var/lib/trac/.projectlist.html

그리고, /var/lib/trac/.projectlist.html file은 다음과 같은 내용으로 채운다.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude">
<head>
<title>You can not access this page</title>
</head>

<body>
<h1>You can not access this page</h1>
</body>
</html>

apache를 재시작한뒤 해당 page에 접근하면 "You can not access this page"라는 글을 보게 될 것이다.

svn commit과 trac 연동

이제, svn을 commit할 때 trac이 특정 동작을 취할 수 있도록 둘을 연동시키는 작업을 할 것이다.

trac에서는 ticket이라는 것을 사용하여 bug를 관리한다. (이 부분에 대해서는 따로 정리하겠지만) bug나, 혹은 꼭 bug가 아니더라도, 작업할 내용들을 적어서 ticket으로 만들어 둔다. 이것을 ticket을 연다(open)라고 말한다. ticket을 열면, 해당 ticket의 내용을 보고 source를 수정한뒤 ticket을 닫는다(close). 이 때 ticket을 닫는 작업을 svn commit할 때 자동으로 이루어 지도록 하는 것이 이번 chapter의 목표이다.

실제 이루어지는 것은 commit이 발생할 때 log를 가로채서 해당 log에 ticket 정보가 있는지 확인하고 ticket 정보가 있다면 해당 ticket을 닫거나 해당 ticket에 log를 남기는 것이다.

post-commit hook template으로부터 post-commit hook script 생성

svn에서 hook은 commit 외에 다른 작업에도 쓰일 수 있는 것 같지만, 여기서는 commit 이후(post)에만 작동 시킬 것이다. hook은 각 repository 별로 따로 지정할 수 있으며, 각 repository의 하위 directory hooks에 hook을 위한 template들이 준비되어 있다.

/var/svn/repos/test/hooks # cp post-commit.tmpl post-commit
/var/svn/repos/test/hooks # chmod 751 post-commit

우선 post-commit hook template을 복사한 뒤, 실행 속성을 준다.

복사했으면, 해당 file의 아랫 부분을 다음과 같이 수정한다.
/var/svn/repos/test/hooks # vi post-commit
...
REPOS="$1"
REV="$2"

#commit-email.pl "$REPOS" "$REV" commit-watchers@example.org
#log-commit.py --repository "$REPOS" --revision "$REV"

SVNLOOK=/usr/bin/svnlook

LOG=`$SVNLOOK log -r "$REV" "$REPOS"`
AUTHOR=`$SVNLOOK author -r "$REV" "$REPOS"`
DIRS="`$SVNLOOK dirs-changed -r "$REV" "$REPOS"`"
$REPOS/hooks/trac-post-commit-hook -p /var/lib/trac/test -r "$REV" -u "$AUTHOR" -m "$LOG"

대략, repository 정보, revision 정보, log message, 사용자 정보를 가져다가 trac-post-commit-hook에 전달한다. 이 file은 아직 만들어 지지 않았으며, 다음 과정에서 만들 것이다.

trac-post-commit-hook 복사

위에서 호출되는 trac-post-commit-hook을 가져온다. 내 경우 /usr/share/doc/trac-0.11.2/contrib/trac-post-commit-hook 으로 존재하고 있었다.
/var/svn/repos/test/hooks # cp /usr/share/doc/trac-0.11.2/contrib/trac-post-commit-hook .
/var/svn/repos/test/hooks # chmod 751 trac-post-commit-hook

이 file은 별도로 수정할 내용은 없으며, 역시 실행 속성을 주어 post-commit에서 호출 할 수 있도록 한다.

svn commit할 때 ticket을 닫거나 comment로 추가

commit을 하면서 ticket에 대해 2가지 action을 취할 수 있는데, 하나는 닫기, 하나는 놔두고 참고 하기이다.
ticket 닫기 : "close" 대신에 "closed", "closes", "fix", "fixed", "fixes" 등을 사용할 수도 있다. log에 다음과 같은 형태로 적어주면 해당 ticket이 닫히게 된다.
close #5, #10
close #5 & #10
close #5 and #10
close ticket:5, ticket:10

ticket에 comment 추가 : "refs" 대신에 "references", "addresses", "re", "see"등을 사용할 수도 있다. log에 다음과 같은 형태로 적어주면 해당 ticket에 log가 적용되지만 닫히지는 않는다.
refs #5, #10
refs #5, #10
refs #5 & #10
refs #5 and #10
refs ticket:5, ticket:10

gmail smtp 설정

이제 mail을 보내기 위한 smtp를 설정한다. 설정해두면 ticket을 만들거나 ticket의 상태가 변할 때 mail로 관련된 사람들에게 통보할 수 있으며, 관리 plugin 중에 사용자 email 확인을 위한 인증 code를 발송할 수도 있다.

smtp service를 제공하는 mail을 써도 좋지만, 여기서는 gmail을 사용해서 만들어 본다. project의 trac.ini를 열어 notification 부분을 수정한다. (여기서는 /var/lib/trac/test/conf/trac.ini)
[notification]
admit_domains =
always_notify_owner =
always_notify_reporter =
always_notify_updater = true
ignore_domains =
mime_encoding = base64
smtp_always_bcc = id@gmail.com
smtp_always_cc =
smtp_default_domain = gmail.com
smtp_enabled = true
smtp_from = id@gmail.com
smtp_from_name =
smtp_password = password
smtp_port = 587
smtp_replyto = id@gmail.com
smtp_server = smtp.gmail.com
smtp_subject_prefix = __default__
smtp_user = id@gmail.com
ticket_subject_template = $prefix #$ticket.id: $summary
use_public_cc = false
use_short_addr = false
use_tls = true

gmail을 사용한다면, 위 code에서 id@gmail.com 부분과 password 정도만 설정하면 동작할 것이다. 단, 8번째 줄의 경우 smtp로 발송, 로그인하기 위한 mail이 아니라 trac에서 발송하는 모든 mail에 숨은 참조로 받게 될 mail 주소이다. 공란으로 두어도 상관 없다. 숨은 참조가 아니라 그냥 참조로 받고 싶다면 9번째 줄에 받을 mail 주소를 쓴다.
크리에이티브 커먼즈 라이센스
Creative Commons License
이 글의 관련글
2009/04/23 01:22 2009/04/23 01:22
Trackback Address :: http://blog.imcdream.net/trackback/296
Trackback RSS :: http://blog.imcdream.net/rss/trackback/296
Trackback ATOM :: http://blog.imcdream.net/atom/trackback/296
[로그인][오픈아이디란?]
Name
Password
Homepage