Plone4でカスタムコンテンツタイプ作ろうと思ったらハマった(その1)
最近、久しぶりにPloneを触っている。しばらく、触ってないので、新しい技術についていくのに時間が掛る。とりあえず、分かったことについてメモっておく。
インストール:開発用にはLinux/BSD/OSXが吉
以前からそうだったかも知れないが、Windowsインストーラを使うのは、OutOfTheBoxでそのまま使う用途に限った方がいい。Linux/BSD/OSX用のUnifiedInstallerで作った環境とWindowsインストーラで作った環境とでは、ディレクトリ構成がかなり違うし、開発者用ドキュメントは大分整備されてきたけど、Windows環境をベースにしているものは少ない。
とりあえず、次のドキュメントを見ながらやったら、UnifiedInstaller使ってUbuntuにインストールできた。(Plone4.3.1、rootユーザ、Stand-Alone Zope Installation)
無事に終わると、/usr/local/Ploneの直下に次のディレクトリが出きています。
- Plone-docs
- LICENCE.TXTとかCHANGES.TXTとか。
- Python-2.7
- buildout-cache
- 文字通り、buildoutのキャッシュです。Ploneの動作に必要なeggは、すべてここに展開されます。
- zinstance
さらに、次のユーザが追加されています。
インストール後の設定
ポート番号やadminパスワード等の各種設定は、zinstance直下のbuildout.cfgに記載します。
アドオン開発のやり方
Plone4では、基本的にアドオンはeggとして作成されます。(Produtsディレクトリに格納するだけという古い流儀もまだ使えるようではありますが、当然ながらオススメされてはいません)
基本的なパッケージの作り方は、このチュートリアル(Hello World Tutorial)のとおりです。
ただし、私の場合、zopeskelでアドオンパッケージを作成する(Create an add-on package)のに失敗しました。
plone_buildout@VirtualBox:/usr/local/Plone/zinstance/src$ ../bin/zopeskel archetype hoge.hoge archetype: A Plone project that uses Archetypes content types This creates a Plone project that uses Archetypes content types. It has local commands that will allow you to add content types and to add fields to your new content types. If at any point, you need additional help for a question, you can enter '?' and press RETURN. Expert Mode? (What question mode would you like? (easy/expert/all)?) ['easy']: Project Title (Title of the project) ['Example Name']: Version (Version number for project) ['1.0']: Description (One-line description of the project) ['']: Creating directory ./hoge.hoge Replace 0 bytes with 119 bytes (0/0 lines changed; 5 lines added) Replace 878 bytes with 1034 bytes (0/32 lines changed; 6 lines added) Replace 119 bytes with 2055 bytes (2/5 lines changed; 45 lines added) Replace 602 bytes with 828 bytes (5/19 lines changed; 7 lines added) Replace 70 bytes with 371 bytes (3/6 lines changed; 11 lines added) Replace 1034 bytes with 1793 bytes (12/38 lines changed; 32 lines added) ------------------------------------------------------------------------------ The project you just created has local commands. These can be used from within the product. usage: paster COMMAND Commands: addcontent Adds plone content types to your project For more information: paster help COMMAND ------------------------------------------------------------------------------ ************************************************************************** ** There is a local command to add individual Archetype content ** types and to add fields to those content types. See the ** instructions above on how to use this command. ************************************************************************** Traceback (most recent call last): File "../bin/zopeskel", line 258, in <module> sys.exit(zopeskel.zopeskel_script.run()) File "/usr/local/Plone/buildout-cache/eggs/ZopeSkel-2.21.2-py2.7.egg/zopeskel/zopeskel_script.py", line 397, in run command.run( [ '-q', '-t', template_name ] + optslist ) File "/usr/local/Plone/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/command.py", line 238, in run result = self.command() File "/usr/local/Plone/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/create_distro.py", line 170, in command egg_info_dir = pluginlib.egg_info_dir(output_dir, dist_name) File "/usr/local/Plone/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/pluginlib.py", line 135, in egg_info_dir % ', '.join(all)) IOError: No egg-info directory found (looked in ./hoge.hoge/./hoge.hoge.egg-info, ./hoge.hoge/hoge/hoge.hoge.egg-info, ./hoge.hoge/CONTRIBUTORS.txt/hoge.hoge.egg-info, ./hoge.hoge/docs/hoge.hoge.egg-info, ./hoge.hoge/setup.py/hoge.hoge.egg-info, ./hoge.hoge/MANIFEST.in/hoge.hoge.egg-info, ./hoge.hoge/CHANGES.txt/hoge.hoge.egg-info, ./hoge.hoge/setup.cfg/hoge.hoge.egg-info, ./hoge.hoge/README.txt/hoge.hoge.egg-info)
直接の原因は、egg-infoが作成されていないことです。
egg-infoは、途中(paste/script/create_distro.py:153-156行目)でアドオンのsetup.pyを別プロセスで走らせることによって作成しています。ところが、別プロセス側のsys.pathに、PasteScript等必要なものが入っていません。システムのPythonにPasteScript等をインストールしてあれば、この現象は起こりません。
zopeskelまたはpasterのバグだと思うのですが、Plone.orgのIssueTrackerが見れないので登録していません。
とりあえず、~/./.bashrcに次のような設定をして、逃げました。
export PATH=/usr/local/Plone/Python-2.7/bin:"$PATH" export PYTHONPATH=/usr/local/Plone/buildout-cache/eggs/ZopeSkel-2.21.2-py2.7.egg export PYTHONPATH="$PYTHONPATH":/usr/local/Plone/buildout-cache/eggs/Paste-1.7.5.1-py2.7.egg export PYTHONPATH="$PYTHONPATH":/usr/local/Plone/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg export PYTHONPATH="$PYTHONPATH":/usr/local/Plone/buildout-cache/eggs/PasteDeploy-1.3.4-py2.7.egg
アドオンパッケージが(zopeskel/pasterで)できたら、buildout.cfgを変更します。(どう変更するかは見れば分かります)
- eggs: 開発するアドオンを追加します。
- develop: 開発するアドオンのソースコードの格納先を追加します。(sys.pathに追加されます)
次にbuildoutを実行します。開発用の構成は、buildout.cfgから分離されたdevelop,cfgに記載されています。
$cd /usr/local/Plone/zinstance $sudo -u plone_buildout bin/buildout -c develop.cfg
最後に、Ploneをフォアグラウンドで起動します。
$sudo -u plone_daemon bin/install fg