]
トップ «前の日記(2013-01-09) 最新 次の日記(2013-01-11)» 編集

Yukiharu YABUKI の tDiary



このtDiaryを検索します。

2013-01-10 [長年日記]

_ [Debian] python-bottle package

2013.01.04 Pythonを始めるなら、1ファイルの軽量Webフレームワーク「Bottle」がおすすめ(http://mojix.org/2013/01/04/python-bottle) という文章を読みました。

上記の文章で、言及している bottle というフレームワークは、Debian ではどのようになっているのか、ちょっと書いておきます。

Debian のリポジトリへの収納状況

2013/01/10現在、Debianのstableは、squeeze で、次期リリース予定は wheezy というリリースコードネームを使っています。

2013/01/10現在の安定版である、squeeze に bottle は存在して、apt-getやaptutideなどでインストールすると使えるようです。バージョンの新旧による機能の差は、bottle本家(http://bottlepy.org/docs/dev/)からgithubなどへ飛んで、gitで差分を取らないと、changelogはなさそうな感じ。本家のchanglogがあったのを見落としていました。(http://bottlepy.org/docs/dev/changelog.html)どうしても新しいバージョンが知りたいなら、Debianの次期安定版のwheezyを試して使うことも考慮してくれると嬉しいです。

パッケージの構成

python-bottleパッケージは、本体と-docパッケージの2つになっています。それぞれのパッケージ内容は後述します。

パッケージのインストール

パッケージのインストールは、私の場合はsudo aptitude install python-bottle-doc python-bottleで行いました。wheezy 環境なら apt-get の方がいいかもしれません。

yabuki@yelona:~$ sudo aptitude install python-bottle-doc python-bottle
[sudo] password for yabuki: 
以下の新規パッケージがインストールされます:
  python-bottle python-bottle-doc 
更新: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
428 kB のアーカイブを取得する必要があります。展開後に 1,102 kB のディスク領域が新たに消費されます。
取得:1 http://cdn.debian.or.jp/debian/ squeeze/main python-bottle all 0.8.4-1 [25.1 kB]
取得:2 http://cdn.debian.or.jp/debian/ squeeze/main python-bottle-doc all 0.8.4-1 [403 kB]
428 kB を 1秒 秒でダウンロードしました (327 kB/s)
未選択パッケージ python-bottle を選択しています。
(データベースを読み込んでいます ... 現在 359384 個のファイルとディレクトリがインストールされています。)
(.../python-bottle_0.8.4-1_all.deb から) python-bottle を展開しています...
未選択パッケージ python-bottle-doc を選択しています。
(.../python-bottle-doc_0.8.4-1_all.deb から) python-bottle-doc を展開しています...
doc-base のトリガを処理しています ...
Processing 1 added doc-base file(s)...
Registering documents with scrollkeeper...
python-bottle (0.8.4-1) を設定しています ...
python-bottle-doc (0.8.4-1) を設定しています ...
python-support のトリガを処理しています ...
 
yabuki@yelona:~$ 
 
パッケージの内容

下記がそれぞれのパッケージの内容です。これらの構成を見るだけでも、どこを見ればいいのか? どう使うのか? 何となく見えてきます。

python-bottle パッケージ

/.
/usr
/usr/share
/usr/share/python-support
/usr/share/python-support/python-bottle.public
/usr/share/doc
/usr/share/doc/python-bottle
/usr/share/doc/python-bottle/changelog.Debian.gz
/usr/share/doc/python-bottle/copyright
/usr/share/pyshared
/usr/share/pyshared/bottle-0.8.4.egg-info
/usr/share/pyshared/bottle.py
  

python-bottle-doc パッケージ

/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/python-bottle-doc
/usr/share/doc/python-bottle-doc/changelog.Debian.gz
/usr/share/doc/python-bottle-doc/copyright
/usr/share/doc/python-bottle-doc/api
/usr/share/doc/python-bottle-doc/api/modindex
/usr/share/doc/python-bottle-doc/api/modindex/index.html
/usr/share/doc/python-bottle-doc/api/search
/usr/share/doc/python-bottle-doc/api/search/index.html
/usr/share/doc/python-bottle-doc/api/_static
/usr/share/doc/python-bottle-doc/api/_static/file.png
/usr/share/doc/python-bottle-doc/api/_static/plus.png
/usr/share/doc/python-bottle-doc/api/_static/myface_small.png
/usr/share/doc/python-bottle-doc/api/_static/favicon.ico
/usr/share/doc/python-bottle-doc/api/_static/pygments.css
/usr/share/doc/python-bottle-doc/api/_static/logo_nav.png
/usr/share/doc/python-bottle-doc/api/_static/basic.css
/usr/share/doc/python-bottle-doc/api/_static/searchtools.js
/usr/share/doc/python-bottle-doc/api/_static/bottle.css
/usr/share/doc/python-bottle-doc/api/_static/minus.png
/usr/share/doc/python-bottle-doc/api/_static/doctools.js
/usr/share/doc/python-bottle-doc/api/_static/myface.png
/usr/share/doc/python-bottle-doc/api/_static/logo_bg.png
/usr/share/doc/python-bottle-doc/api/_static/default.css
/usr/share/doc/python-bottle-doc/api/_sources
/usr/share/doc/python-bottle-doc/api/_sources/tutorial.txt
/usr/share/doc/python-bottle-doc/api/_sources/api.txt
/usr/share/doc/python-bottle-doc/api/_sources/contact.txt
/usr/share/doc/python-bottle-doc/api/_sources/faq.txt
/usr/share/doc/python-bottle-doc/api/_sources/changelog.txt
/usr/share/doc/python-bottle-doc/api/_sources/index.txt
/usr/share/doc/python-bottle-doc/api/_sources/stpl.txt
/usr/share/doc/python-bottle-doc/api/_sources/tutorial_app.txt
/usr/share/doc/python-bottle-doc/api/_sources/development.txt
/usr/share/doc/python-bottle-doc/api/_sources/recipes.txt
/usr/share/doc/python-bottle-doc/api/development
/usr/share/doc/python-bottle-doc/api/development/index.html
/usr/share/doc/python-bottle-doc/api/index.html
/usr/share/doc/python-bottle-doc/api/searchindex.js
/usr/share/doc/python-bottle-doc/api/faq
/usr/share/doc/python-bottle-doc/api/faq/index.html
/usr/share/doc/python-bottle-doc/api/tutorial_app
/usr/share/doc/python-bottle-doc/api/tutorial_app/index.html
/usr/share/doc/python-bottle-doc/api/stpl
/usr/share/doc/python-bottle-doc/api/stpl/index.html
/usr/share/doc/python-bottle-doc/api/changelog
/usr/share/doc/python-bottle-doc/api/changelog/index.html
/usr/share/doc/python-bottle-doc/api/objects.inv
/usr/share/doc/python-bottle-doc/api/.buildinfo
/usr/share/doc/python-bottle-doc/api/api
/usr/share/doc/python-bottle-doc/api/api/index.html
/usr/share/doc/python-bottle-doc/api/contact
/usr/share/doc/python-bottle-doc/api/contact/index.html
/usr/share/doc/python-bottle-doc/api/tutorial
/usr/share/doc/python-bottle-doc/api/tutorial/index.html
/usr/share/doc/python-bottle-doc/api/recipes
/usr/share/doc/python-bottle-doc/api/recipes/index.html
/usr/share/doc/python-bottle-doc/api/genindex
/usr/share/doc/python-bottle-doc/api/genindex/index.html
/usr/share/doc-base
/usr/share/doc-base/python-bottle
/usr/share/doc/python-bottle-doc/api/_static/jquery.js
  
Hello Worldを実行してみる

Debian Squeezeのpython-bottleの場合、バージョンのためか、blogで書いてあるhello worldプログラムを一部変更する必要があります。ってか、付属のドキュメント(英文)を読めば、このバージョンでの動かし方が書いてある。ググるのではなく、付属のドキュメント読みましょう。

- run(host='localhost', port=8080, debug=True)
+ run(host='localhost', port=8080)
  

ポートは、あなたの環境に応じて変更してください。例えば、私は8080を使っていたので、使用ポートを8082にして実験しました。Eclipseから実行して http://localhost:8082/hello アクセスすると

Bottle server starting up (using WSGIRefServer())...
Listening on http://localhost:8082/
Use Ctrl-C to quit.
 
localhost.localdomain - - [10/Jan/2013 19:39:08] "GET /hello HTTP/1.1" 200 12
localhost.localdomain - - [10/Jan/2013 19:39:08] "GET /favicon.ico HTTP/1.1" 404 682
  

と、起動メッセージのあとにログがコンソールに表示されます。webブラウザーの画面でも結果を確認してください。Wheezy のバージョンならたぶん、debug=Trueがいるのかなあ。試してないから憶測ですが。