一月 21, 2009

hoamon's sandbox
hoamon
hoamon's sandbox is about »

tag cloud

» Trac + Mercurial on Apache 的亂碼問題

這個問題搞了我很久。

用 trac 內帶的 tracd 來跑, changelog 部份的中文就是正常的,但跑在 apache 上時,它就亂了,而且只亂 changelog 部份,程式碼的 diff 結果及 raw 格式都沒事。

看了很久的 mercurial-plugin-0.11 程式碼,看來看去覺得這應該是 mercurial 的錯,不過為什麼我在 shell 中用沒事,或是用 tracd 跑也沒問題,但它跑在 apache 上就錯了呢???

hg 在讀 changelog 的部份,它是用 mercurial.changelog.changelog 函式來處理,但裡面有一個 read() 被 mercurial-plugin 拿來用了,而這個 read 函式在解讀字串時,要叫用 util.tolocal() 來處理編碼,只要沒設定 os.environ['HGENCODING'] 的話,它就會預設為 ascii ,這就是造成 changelog 亂碼問題的地方。

以前,我只須在 /etc/python2.5/sitecustomize.py 設定 sys.setdefaultencoding('utf8') 就行了,現在還得加上 os.environ['HGENCODING'] = 'utf-8' 。

我還是不太懂 os 及 sys 的差別是什麼?

一月 22, 2008

hoamon's sandbox
hoamon
hoamon's sandbox is about »

tag cloud

» Trac0.11b1 + Mercurial + Postgresql

基於對 Python 的喜愛,所以想要把 subversion 換成 Mercurial ,但目前還只是測試階段,真正上線使用的還是 subversion 。另外一直都想要找個機會把 Mysql 換掉,到不是說 Mysql 不好用,而是我對於 PostgreSQL 本來就有一分感情,那是在 Mysql3,4 還不支援 UTF-8 時,我用 Perl 寫了一個 unicode 字的查詢系統。

而今天所要介紹的,不過是我在工餘之際把玩的小小玩意,既然成功了,那就作個紀錄。

在 Ubuntu 安裝軟體是一點都不難的(只要有 .deb 檔),所以要裝 Trac + PostgreSQL + Mercurial ,請執行下面指令:

# sudo apt-get install postgresql-client-8.2 postgresql-8.2 python-psycopg2 \
> python-setuptools python-genshi \
> python-psycopg2 python-pygments python-docutils mercurial

接下來,安裝 Trac 0.11b1 主程式
# sudo easy_install http://ftp.edgewall.com/pub/trac/Trac-0.11b1.tar.gz

最後安裝 Trac 控制 Mercurial 的外掛
# svn co http://svn.edgewall.com/repos/trac/sandbox/mercurial-plugin-0.11
# cd mercurial-plugin-0.11/
# sudo python setup.py install

再來是設定,首先我們建立一個 dbuser ,這方面, PostgreSQL 有點奇怪,或許是我 Mysql 用久了,
# sudo -u postgres createuser trac -P
Enter password for new role:
再輸入一次:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE
# sudo createdb -O trac trac
並將 pg_hba.conf 中的
local all all ident sameuser
改成
local all all password

這樣你的 trac 程式就可以透過帳號: trac 密碼: trac host: localhost 的方式與 PostgreSQL 連接了。

接下來,初始化 trac 設定目錄及 hg 儲存庫:
# trac-admin /path/to/myproject initenv
# hg init /path/to/myproject/hg

另外在 trac.ini 中加入
[components]
tracext.hg.* = enabled

[hg]
show_rev = yes
node_format = short

用 tracd --port 8000 /path/to/myproject 測試一下有沒有問題,沒有問題就讓 mod_python 來跑吧!

下面則是 mod_python 的設定檔


NameVirtualHost *:443

ServerAdmin admin@xxx.com
ServerName trac.xxx.com
DocumentRoot /www/trac

SetHandler mod_python
PythonHandler trac.web.modpython_frontend
#PythonPath "sys.path+['/usr/local/Trac/lib/python2.5/site-packages/']"
PythonOption TracEnv /www/trac
PythonOption TracUriRoot /
PythonDebug Off
SetEnv PYTHON_EGG_CACHE /www/trac/tmp
SetEnv LANG UTF-8
SetEnv HTTPS 1
AuthType Basic
AuthName "Trac Server"
AuthUserFile /www/htpasswd_users
Require valid-user

ErrorLog /var/log/apache2/trac_error.log
LogLevel warn
CustomLog /var/log/apache2/trac_access.log combined
ServerSignature Off
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem

十二月 10, 2007

hoamon's sandbox
hoamon
hoamon's sandbox is about »

tag cloud

» 讓 Trac 支援 Email on Change

當 Trac 系統上有人增加/修改了一篇 wiki 、 ticket ,它能直接以 email 的方式讓其他人知道。

方法是:只要在 trac.ini 中編輯以下選項即可。

smtp_enabled = true
smtp_server = localhost
smtp_from = dontreply@mailserver
smtp_replyto = dontreply@mailserver
smtp_always_cc = XXX@gmail.com, YYY@gmail.com
always_notify_owner = true # 任何改變也會寄給「被指派的人」
always_notify_reporter = true # 任何改變也會寄給「創ticket的人」
always_notify_updater = true # 寄給改變這個 ticket 狀態的人

smtp_server 是寄信伺服器,如果你是在 hinet 的網路之下,可使用 msa.hinet.net ,它不會擋你。smtp_from, smtp_replyto 不重要,因為你不期待有人針對通知信回信。而 smtp_always_cc 則是每封通知信一定要寄的對象。

修改後,再重啟 apache 即可。

另外當你使用 ticket 時,要讓多人知道這個 ticket ,請使用 Cc: 欄位,其值為收信地址,若多值請用逗號隔開。

七月 14, 2007

hoamon's sandbox
hoamon
hoamon's sandbox is about »

tag cloud

» 使用 Trac 的錯誤示範: Section 2

非常高興,在本文中,我們又邀請兩位知名「演員」為我們示範 Trac 的錯誤使用方法,就有請第一男主角:小強、第二男主角:阿蒙,出場!

小峰一開始在 wiki 的研討會準備事項中寫著:

  1. 要有紅茶
  2. 要買喝紅茶的吸管
  3. 記得買停車券
  4. 18日會有大頭來視察
小強後來把研討會準備事項內容改成:
  1. 要有檸檬紅茶
  2. 19日會有大頭來視察
  3. 20日記得買停車券
但小強的修改是有問題的。

小強在原本的 1、3、4 點作部份加強,這部份沒問題。然而他把原本的第 2 點完全刪除了。這是不對的,除非他明知這一點是要刪除的,但事實上不是,因為吸管是有必要存在的。

因為小強是後修改的人,所以他有責任及權利把別人之前的成果整合到自已的內容當中。這樣才會你刪我加,我刪你加,搞到最後,內容到底要什麼都亂了。

六月 23, 2007

hoamon's sandbox
hoamon
hoamon's sandbox is about »

tag cloud

» 使用 Trac 的錯誤示範: Section 1

非常高興,在本文中,我們邀請兩位知名「演員」為我們示範 Trac 的錯誤使用方法,就有請第一男主角:小強、第二男主角:阿蒙,出場!

小強:學長你丟給我的 ticket ,我不太懂是什麼意思耶~
阿蒙:應該是我前天還是昨天 assign 給你的那一個吧!是不是跟寄信有關。
小強:是的,好像是叫我找 python 寄 html 的模組,我不太懂「寄 html 」的意義是什麼。
阿蒙:你記不記得你有收到一封信,內容中的連結是原始網址,像是: http://xxx.yyy.zzz/id/modeule/?pk=32ufjdaddadf 之類的東西。
小強:有大致看過,好像是這樣的。
阿蒙:那是因為我寄出信的格式是 plain 純文字檔,所以無法把網址變成真正的超連結。所以我希望你幫我找到給 python 用的模組,而讓能它寄出 html 格式的信件。
小強:那我知道了。

看倌們!看出問題了嗎?

問題1:小強在 trac 上看到一個不了解涵義的 ticket ,他想要問阿蒙,他選擇的方式不是當下打電話或是在此 ticket 上作 comment 再指派回阿蒙身上,而是選擇記在腦海中,要在某一天遇到阿蒙時「記得」問他。如果還得把「專案開發」時衍生的「溝通工作」記在腦海中,那麼 Trac 就沒有存在的意義,而且用人腦記住也絕比不上用電腦記住來的正確。

問題2:明知道小強應該會不懂你的要求,為什麼不一開始就在 ticket 上寫清楚,還要浪費一次溝通呢!

A Feedjack powered Planet
A Django site.