三月 13, 2010

marr's weblog
marrtw
marr weblog is about »

tag cloud

» User SubGroup and Associated Roles

Plone 3.2 版本之前的會員管理介面 prefs_users_overview 執行搜尋時,只能針對 full name 欄位進行比對,不能比對 id 欄位,另外也有 subgroup 與 role 的顯示問題,症狀主要記錄於 #9317#8940。目前已在 changeset 33533 完成修訂,並整理出新的管理介面。

三月 8, 2010

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Fake Eggs ?

This is an abstract from Scrambled eggs by Martin Aspeli.

藉由 egg 機制,我們可以更順暢地進行模組軟體的包裝與散佈,但是,遇到 buildout 想要自動昇級某些模組時,為了滿足相依衝突時,egg 也可能帶來許多痛苦,我們會被一堆版本昇級要求資訊淹沒。

由於 Plone 3.0 到 3.1 搭配的 Zope 並沒有包裝成 egg 檔案,導致 setuptools 無從得知 Zope 3 模組的 egg metadata 資訊。舉例來說,如果你安裝一個相依於 zope.component 的模組,但是 setuptools 並不知道你已經有 zope.component 了,因此會試著下載最新版的 zope.component。由於新版 zope.component 的下載動作會引發其他相依關係,很容易造成永無止境的昇級要求。

為了解決上述問題,plone.recipe.zope2install 這個 recipe 預設會安裝一些 fake egg,它的效果,就像是建立一堆指到 parts/zope2/lib/python/* 的 egg。如此一來,setuptools 就能知道系統裡存在 zope.component、zope.interface 等標準模組,不需要再去下載新版檔案。

常見的情況是,我們只知道需要安裝某個檔案,但不清楚所需的明確版本,因此 fake egg 會指定為 0.0 版本,除非你為特定的 recipe 額外指定它的版本號碼。也就是說,如果有個模組的相依關係是 zope.component >= 3.1,setuptools 仍然會以為系統既有的 zope.component 版本過舊,將嘗試下載新的版本。

那麼,模組的相依資訊被記錄於何處? 它的來源大致有兩類,一是在模組檔案的 setup.py 內容裡,二是從 buildout.cfg 檔案的 eggs 設定值尋找。相依資訊的常見形式,又可分成兩類,第一類的例子是「我需要和 zope.component 一起工作」,只指定模組名稱,而不指定模組版本,第二類的例子是「我需要和 zope.component >= 3.4 版本一起工作」,同時指定模組名稱與版本條件。

有時,在 setup.py 裡指定最小版本號碼是必要的,因為某些版本以上的模組,才提供我們需要的功能。當然,在 setup.py 裡明確指定「我需要和 zope.component == 3.4 版本工作」是合法的設定方式,但通常會造成日後的災難,而指定最大版本號碼的方式,例如「我需要和 zope.component >=3.4, <=3.4.999 版本工作」,通常也是很糟的形式。一般而言,除非有必要,永遠不要在 setup.py 裡指定「==」的版本要求,頂多使用「<=」的版本形式。因為,這類不適當的設定值一旦出錯,除錯工作極度困難。

另一方面,目前 setuptools 的運作方式,是找尋最新版本來下載,如果它先下載了某個模組的新版本,就會順著它的相依關係來下載其他模組,即使某個舊版本提供更合適的相依條件,setuptools 並無從得知,這會導致下列問題:

* setuptools 下載過新版本的模組,和稍後模組的最大版本條件相衝突。幸好,這個問題並不難解決。

* 原本 buildout 運作正常,但是有人在 PyPI 上傳新版模組,造成相依關係更新,接著你又執行 buildout 更新動作,下載了新版模組,引發更多新版模組的下載。運氣好的話,系統會通知版本衝突的訊息,運氣不好的話,表面上 build 動作完成,但執行系統時卻失敗。

三月 6, 2010
» onlinedict by google app engine

PB173371
Central Station.NYC.US

I posted an article about using Google App Engine in last June, and the experiment target is the onlinedict. Everything goes well and since onlinedict is originally written in python, the porting task is without any efforts.

However, there's one limitation of using Google App Engine: You can get your codes back from the server. You have to keep your codes somewhere. That's quite strange as a policy. I know it may be easier to control the whole system on google side, but as a user, it's troublesome ofr me because I am too lazy to my stuff in another source control website.

As a consequence, I lost my codes after re-installing OS on my nb for several times. Although my original work still runs well, it looks bad on all mobile devices. The words are too small to read. However, I don't have original codes anymore! no way to improve it at all!

Finally, I decided to rewrite it again,since this website should help me most on mobile devices. If the outlook on devices are bad, then it is somehow useless to me. Well, the first thing to do is study again how to apply the google app engine framework into my dictionaries. With the help of the tutorial, I quickly achieved what I have done last time: a working fr-en, ch-en dictionary, and, plus eijiro dictionary!

The most difficult part (not really difficult at all, I just don't know how to do) is to adopt some css style to make it look great on mobile devices. Well, I found a good refernce site: http://building-iphone-apps.labs.oreilly.com/. And, it's free!

Okay, after several hours of work, I am happy with my new dictionary now. The font size is good, the input control is at the right position, with some hints in the box. Three online dictionaries are available. It's time to go to sleep again~~

三月 3, 2010

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Quote Portlet

想在 Plone 網站加上 quote portlet 嗎? 利用 collective.portlet.quote 輕鬆就能完成,它還有 Quote Folder 專門來放 Quote Type。不過,並不喜歡預設的方框樣版,想要改個樣子,於是動手修改兩個檔案。

修改 randomquote.pt 內容如下:

    <dd class="portletItem odd">
<q tal:content="structure view/get_quote">
Body text
</q>
</dd>
<dd class="QuoteSource">
<span class="portletBottomLeft"></span>
<p tal:condition="not:view/has_link">

<tal:block replace="view/get_source"/>
</p>
<tal:block condition="view/has_link">
<a tal:attributes="href view/get_link">

<tal:block replace="view/get_source"/>
</a>
</tal:block>
<span class="portletBottomRight"></span>
</dd>

新增 ploneCustom.css 內容如下:
.QuoteSource
{
border-color: #8CACBB;
border-width: 1px;
border-style: none solid none;
margin: 0;
text-align: right;
padding: 0.25em 1em;
}
有圖有真相。

二月 23, 2010
» Development on android

PB124730
Annecy.France

看了點文件,想說就來寫寫東西吧,從最簡單的開始。

之前在國外時,為了學法文,幫onlinedic寫了個Vocabulary Review的小程式在Windows Mobile上。讓自己可以用當時帶出去的dopod818加減看一下查過的單字。現在,當時的code已經都不見了,所以想說在android上也寫一個好了。反正onlinedic的export機制都還是okay的。

在寫程式時,也可以順便練習到android上的一些基本觀念,比方說:如何透過intent來叫起另一個activity;如果在叫起別的activity時,帶想要的參數給它;透過xml的UI建置方式,畫面橫轉正轉的處理;UI元件的動作指派;目錄結構的讀取,文字檔的讀取;簡單的webview應用;activity暫存狀態的記錄;功能權限的開啟;androidManifest.xml的基本設定;eclipse開發環境的熟悉等。

真的寫下去了,明明是個很簡單的程式,但也弄了一天多才寫好,花了許多時間在小細節上。如果不把除錯、追臭蟲方式弄熟,接下來的日子應該會很痛苦吧。

= = =
如果有空的話,乾脆一不做二不休,把onlinedict也搬到android,這樣子就不用每次都要裝一堆字典了。在網路上找到open source,可以讀取stardict字典檔的程式,有空再研究吧。先記下link:
http://code.google.com/p/toolkits/wiki/YAStarDict

另外,沒想到有人替eblib包了個python wrapper!!
當初在onlinedict裡亂寫的鄨腳command line程式,應該可以用這個wrapper把它換掉吧,省下暫存文字檔輸入輸出的廢工。
也是…改天有空再試吧。
Link: http://code.google.com/p/pyeb/

二月 17, 2010
» plurkmonitor

photo
Marbourg.Allemagne

又在亂寫東西了。
目前的噗浪,可能是為了有效地節省傳輸的頻寬,提高使用者操作時的response,
雖然它會定期的檢查是不是有新的回應,
但是使用者還是要再按一下才可以切到最新回應的模式。
時間軸的方式在大部分情況下很方便,
但是在看回應時,就顯得不是那麼重要了,
因為,這時使用者在意的是別人的回覆,
而不是這條噗是在什麼時候發出的,或是跟其他噗的前後關係。
所以,如果在看最新回應時,所有的噗可以更集中的話,
應該會更一目瞭然才是。

於是乎,自己寫了一個小小的script,
讓我可以在不開browser或是不開plurk website的情況下,
可以知道目前是不是有新的回應,而這些回應又是屬於哪些使用者的噗。
畢竟,有些時候,並不是所有最新回應自己都有興趣,
但又懶得一一去關成靜音。

= = = =

為了怕自己會一直改來改去,所以去google code開了個project
方便之後的source code control。
網址在:https://code.google.com/p/plurkmonitor/

系統需求:python + wxpython

二月 6, 2010
» Virtualenv 簡單入門

功用

使用 Virtualenv 可以讓你預先建立一個虛擬環境,在虛擬環境中開發 Python 程式,可以保持 Python path 乾淨,並減少因為機器上需要同時支援不同版本函式庫,造成各函式庫彼此之間相依性的困擾。

而且使用虛擬環境後,到時要將環境轉移到別台機器上,也減少很多設定上的問題。

安裝

$ easy_install virtualenv

設定環境

$ virtualenv --no-site-packages [dev_place]

即建立一個名為 [dev_place] 的資料夾(中括號裡的名稱自行填寫取代)。

切換到虛擬環境

進入 [dev_place] 目錄,輸入命令:

$ source bin/activate

若看到路徑提示前多了個([dev_place])符號,即表示已經進入了虛擬環境。

這時我們可以使用預設提供的 easy_install 工具安裝要使用的函式庫、或是安裝各種 Python 程式。

安裝的函式庫會被放到 [dev_place]/lib/Python[版本]/site-packages/ 目錄中,跟一般的 Python 函式庫配置方式相似。

離開虛擬環境

要離開虛擬環境,只需輸入命令:

$ deactivate

即可回到預設的命令行狀態。

其他操作

如果你的電腦上有裝多個 Python 版本,在下 virtualenv 命令時加上「--python=python[版本] 」當作參數,也可以建立出不同版本的 Python 虛擬環境,讓你可以更容易地在多個 Python 版本間做測試。

其他使用方法可以輸入「virtualenv --help」參考印出的說明。

二月 2, 2010
» [tips] python2與python 3的list comprehensions之差異

剛好看到這篇
http://yz.mit.edu/wp/2010/01/14/bitten-by-python-scoping/
想起之前也有遇到類似的問題~

其實主要就是python2的list comprehensions有個副作用,
就是會重設scope內的變數, 比如以下這個程式

def t1(): 
x=5
[0 for x in [1,2,3]]
print x

t1()

3

這邊的x會被重設為3, 有點像是殘餘的loop變數的感覺~
有些人會玩弄這個副作用來達到一些不想讓人看懂的lambda技巧就是了:P

但相對來說後來引進的generator語法就沒有這個問題, 所以這個問題其實也可以使用list(x for x in [1,2,3])這個方法來解決.
def ts2():
x=5
list(x for x in [1,2,3])
print x

ts2()

5

另外也可以置換變數比如改成使用a來取代x(當然a是會被assigned).

當然還有另外一個方法則是使用python 3, 就完全沒有這個問題了 :D

一月 18, 2010

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Dexterity vs Archetypes

This blog is an abstract from How is Dexterity related to Archetypes by Martin Aspeli.

DexterityArchetypes 的替代方案,這兩種方案都是 Plone 建構 content type 的框架技術。由於 Archetypes 存在已久,是成熟的方案,而 Dexterity 是後起之秀,結合新版 Zope 技術,有些新技術能夠有效處理以往難以解決的問題。

下列是幾項主要的差異:

* Dexterity 結合新版 CMF、Zope 3 的技術與功能,程式碼更精簡,測試工作更能自動且完整。
* Dexterity 具備更高的模組化程度,更容易整合 SQL 資料庫。
* Archetypes 自有的 Schema 機制,並無法完全相容於 zope.interface 或 zope.schema 的介面。
* Archetypes 使用 accessor 與 mutator 來處理設定值,Dexterity 則使用 attribute notation 方式來處理,因此 Archetypes 的寫法類似 context.getFirstName() 而 Dexterity 是 context.first_name 這樣的寫法。
* Archetypes 自有的 field 和 widget 配合 content object 的脈絡來運作,並不容易被應用在獨立表單,Dexterity 則使用 z3c.form 函式庫,這是表單運作的標準工具。
* Archetypes 並不支援新增表單,Dexterity 則透過 z3c.form 來支援,這代表它不需要用到 portal_factory,執行效率能夠改善。

一月 14, 2010

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Archetypes id-to-title Normalizer

Archetypes 的 content type 在新建時,需要決定 Id 並讓它成為 URL 的一部份,決定 Id 的函式可以先從 Products/Archetypes/BaseObject.py 的 generateNewId() 和 _renameAfterCreation() 查起,它們會配合 plone.i18n.normalizer.interfaces 的 IURLNormalizer 和 IUserPreferredURLNormalizer,並分別來自 INormalizer 和 IUserPreferredNormalizer。

實作例子有 ZopeChinaPakC2FileNameNormalizer,也有個 External Method 的例子

一月 4, 2010
» Invent Your Own Computer Games with Python

電子書

一月 3, 2010
» 連兩天加班

P6182020
Nagoya.Japan

今天加班時,同事分我們吃由台中"糖村"買來的牛軋糖。
好好吃啊!
看起來跟這根欄杆的形狀很像。
雖然我拿了一堆,還是被我吃光了。
不知道可不可以郵購呢?

****

好累。
希望農曆過年時,已經解脫。

之前寫的random display flickr photo,由於flikrapi改版,所以不行用了。
再加上epc重灌,一時還來不及灌wxpython;
所以臨時改了一版可以直接用command line產生html再叫system開啟的script。
雖然還很陽春,但總比都沒有來得好。

十二月 29, 2009
» 第十章 更多的例子

昆蟲世界 基本的幾何形狀 用七巧板排列 滑鼠控制移動 張貼新的事件 可移動板塊的七巧板 除了文字之外,我們還可以在Pygame視窗中載入圖片或是直接利用draw模組來繪圖,我們先來看看如何載入圖片,以下的程式同時顯示背景圖片及滑鼠游標的圖片。 #《電腦做什麼事》的範例程式碼 #http://pydoing.blogspot.com/ import pygame from pygame.locals import * from sys import exit screen_size = (800, 600) title = "Hello, Real world!" background_image = "background.png" cursor_image = "cursor.png" def mouse_pos(img): x, y =

十二月 23, 2009

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Plone 4 Preview

Plone 4 於十二月進入 alpha 2 階段,這個版本搭配 Python 2.6 和 Zope 2.12 執行,因此要留意 Python 執行版本的細節。

$ python -V
Python 2.6.1

$ svn co http://svn.plone.org/svn/plone/buildouts/plone-coredev/branches/4.0 Plone-4-svn
A Plone-4-svn/tests.cfg
A Plone-4-svn/sources.cfg
A Plone-4-svn/pil.cfg
A Plone-4-svn/bootstrap.py
A Plone-4-svn/buildout.cfg
A Plone-4-svn/versions.cfg
... ...
A Plone-4-svn/experimental/i18n.cfg
U Plone-4-svn
Checked out revision 32308.

$ cd Plone-4-svn
$ python bootstrap.py
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.8.tar.gz
... ...
Generated script '/home/marr/Download/Plone-4-svn/bin/buildout'.

$ bin/buildout
Getting distribution for 'mr.developer==1.7'.
Got mr.developer 1.7.

$ bin/buildout -c pil.cfg
mr.developer: Updating 'Plone' with subversion.
mr.developer: Updating 'Products.ATContentTypes' with subversion.
mr.developer: Updating 'Products.PasswordResetTool' with subversion.
mr.developer: Updating 'plone.app.upgrade' with subversion.
mr.developer: Updating 'plone.app.users' with subversion.
mr.developer: Updating 'plonetheme.sunburst' with subversion.
Develop: '/home/marr/Download/Plone-4-svn/src/plonetheme.sunburst'
Develop: '/home/marr/Download/Plone-4-svn/src/plone.app.upgrade'
Develop: '/home/marr/Download/Plone-4-svn/src/Products.PasswordResetTool'
Develop: '/home/marr/Download/Plone-4-svn/src/Products.ATContentTypes'
Develop: '/home/marr/Download/Plone-4-svn/src/plone.app.users'
Develop: '/home/marr/Download/Plone-4-svn/src/Plone'
Uninstalling alltests.
Uninstalling test.
Uninstalling instance.
Uninstalling zopepy.
Uninstalling _mr.developer.
Installing _mr.developer.
Generated script '/home/marr/Download/Plone-4-svn/bin/develop'.
Installing zopepy.
Getting distribution for 'PIL==1.1.6'.

Plone 4 有了新的 Plone Site 新增按鈕,透過 http://localhost:8080/@@plone-addsite 之類的網址來呼叫建立功能,預設的網站畫面也不同於 Plone 3.x 版本。





十二月 17, 2009

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Content Type Migration

由於 Plone 2.5 和 Plone 3.x 的 package 管理方式不同,想要把 2.5 時代的 custom archetype-based content type 改成 3.x 新版格式,可參考 changing product name/structure 的討論,特別留意可能要處理 archetype migration 的動作,也就是改用新版 content type 的情形。
想看 Plone 核心系統如何處理這樣的問題,可以到 Products/CMFPlone/migrations 找看看程式碼,如果是用 archetype 額外寫的小型應用程式,很可能要參考 ATContentTypes 附的 migration 機制。在 Products/Archetypes/Extensions 和 Products/ATContentTypes/migration 可能有細部線索。
如果想再跟上 Plone 4.x 的發展方向,就要考量適合的時機,從 archetype 轉到 dexterity 的開發方式。

» Custom Plone Home Page

記錄幾個客製 Plone 首頁畫面的技巧。

以 blog style 的首頁為例,新增一個 collection 把 blog 搜尋出來,再於首頁指定顯示這個 collection 即可。想要同時顯示多個 collection 的話,方法之一是尋求擴充模組的支援,像 ContentWellPortlets 就是一個例子。試用 PortletPage 後,覺得是較合用的選項,它可以把 portlet 新增在上下左右共四個區位。

如果想要修改首頁的顯示方式,可以參考 Create a different look and feel for different sections of your web site 這篇文件,利用 sectional CSS 方式來完成。下面的例子,就是把首頁的 heading 和 byline 都取消顯示。

在 portal_skins/custom 裡新增一個 DTML Method 將 Id 設為 sections.css 後,使用下列範例程式碼:

/* <dtml-with base_properties> (do not remove this :) */
/* <dtml-call "REQUEST.set('portal_url', portal_url())"> (not this either :) */

.section-front-page
.documentFirstHeading {
display: none;
}
.documentByLine {
display: none;
}

/* </dtml-with> */

到 portal_css 裡新增一個 stylesheet 填寫 ID 為 sections.css 其他都使用預設值。必要的話,可以設定 Plone 在 debug mode 執行,並勾選 portal_css 的 Debug/development mode 讓修改結果馬上生效。

還有許多修改技巧,可以在 Plone 3 Theming 這本書裡看到。

另外,使用 Plone 3.3.1 的朋友,可能會發現 collection 設定 criteria 時的錯誤,請參考 Impossible to add a criteria in a collection in 3.3.1 的修訂方法,先處理掉這個問題。

十二月 14, 2009

marr's weblog
marrtw
marr weblog is about »

tag cloud

» FancyZoomView

collective.fancyzoomviewjQuery 為基礎,提供 Plone 放大顯示圖片的功能。

以 News Item 為例,它會去修改 page template 內容,先加上一段:

<metal:javascript fill-slot="javascript_head_slot">
<script type="text/javascript"
tal:attributes="src
string:${context/++resource++collective.fancyzoomview.javascript/fancyzoom.js};">
</script>
<script type="text/javascript" charset="utf-8">
jq(document).ready(function() {
jq('div.newsImageContainer a').fancyZoom({closeOnClick: true})
});
</script>
</metal:javascript>

把 tal:attributes="href string:$here_url/image/image_view_fullscreen" 改成 tal:attributes="href string:#news_item_image;"

再加上

<div id="" tal:attributes="id string:news_item_image">
<img tal:replace="structure python: here.tag(scale='large', css_class='newsImage')" src="" alt="" />
</div>

十二月 11, 2009
» 要賣 9 本 Perl 的書(再補一本,共 10 本)


請上露天拍賣網址(結標時間:2010-01-0213:56)

書籍近照:

底價定 300 元,只要是郵資費夠,我就賣掉。

為什麼要賣掉呢? 因為我想我不會再研究 Perl 了吧! 過去,我剛入門 Linux 的時候,那時系統管理員最好用的工具語言是 Perl ,所以為了把 Linux 管好,我花了不少心力學它, Perl 幫助我找到人生中的第一份工作。但是後來,約五年前,我開始常寫網頁系統時,卻無法拿它來用,那時還沒流行 Web Framework ,所以我當然不知道有 Catalyst 的存在,於是我學了 PHP ,用它來寫網頁。

那時的我是 PHP/Perl 兩頭玩,直到兩、三年前, Ruby on RailsDjangoTurboGears 的出現,我才開始認真地想把「系統管理」、「網頁設計」及「學術研究」的工作用同一種語言來解決,最後選的是 Python + Django ,因為 Python 當時的數學函式庫比 Ruby 豐富,所以我們老大就說用 Python 好了,雖然那時我是比較想用 Ruby on Rails 的,當時 Rails 的氣焰比較高。

不過,現在看來,選擇 Python 應是比較符合我的個性,因為我個人是比較龜毛,喜歡 SOP (標準作業程序),所以過去用 Perl 時,有太多種表現的手法後,在我個人寫的程式上,風格十分隨便,反正看不懂了,就再寫一個,而這點, Ruby 的特性就有點類似 Perl 了。

也是用了 Python 後,我才發現過去喜愛 Perl 的程度,不如我以為的那樣高。這讓我想到重慶森林裡的廚師莎拉與漢堡薯條的故事:「沒有嘗試過,你如何知道真正喜歡的是什麼」。所以,我想把這些 Perl 相關的書籍留給其他適合的讀者。願意作它們的新主人嗎?

十二月 9, 2009

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Adding Portal Actions

Plone 的 content type 預設會顯示 Send this 和 Print this 的 document action 項目,如果想要新增一個 Google this 項目,該怎樣做呢?



在 ZMI 裡 portal_actions/document_actions 新增 CMF Action 項目,先要填寫識別碼。



以 google 為例,再點選進入填寫更多細節,範例如下:

Title: Google this
I18n Domain: plone
URL (Expression): string:javascript:(function(){open('http://www.google.com.tw/search?q=' +encodeURIComponent(document.title)+'&ie;=utf-8&oe;=utf-8&aq;=t&rls;=com.ubuntu:en-US:unofficial&client;=firefox-a','google','toolbar=no,width= 700,height=250')})()
Permissions: View
Visible?: true



按 Save Changes 鈕後就會直接生效。

有些細節值得留意。即使沒做翻譯的動作,像是 I18n Domain 最好要填,預設是 plone。在 URL (Expresion) 欄位裡常用的變數有:

$portal_url - 例 string:${portal_url}/news
$object_url - 例 string:${object_url}/addtoFavorites
$globals_view - 例 string:${globals_view/navigationRootUrl}

十一月 26, 2009

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Plone Maintenance Branch

Development process 的討論串裡,談到 Plone 3.x 有許多 package maintenance branch 可從 coredev buildout 的 source.cfg 內容來查詢,如果 package 維護 maintenance branch 的話,就可以在 branch 裡改好再 merge 回 trunk 裡。

A Feedjack powered Planet
A Django site.