Personal tools
You are here: Home なごぶろ Turbogearsのプロジェクトを起動する
About this blog
なごすいぶろぐ。「すべてはなごすいのために」。
Categories
COREBlog2 (31)
Zope (61)
Linux (26)
Misc (47)
Nagosui (11)
ReadingCOREBlog (7)
Plone (81)
Python (20)
Turbogears (18)
COREBlog1 (30)
moblog (5)
Django (12)
 
Document Actions

Turbogearsのプロジェクトを起動する

アプリが起動した

今日も元気に(ホントは眠いけど…)Turbogears!と思ってフォルダを開いてみたら、いつの間にか「locales」というフォルダが増えていました。おそらく前回tg-admin i18nを実行したためだと思います(すぐCtr+Cしたけど…)。

localesフォルダが増えてた

まぁそれはどうでもよいとして、前回まででとりあえずプロジェクトのひな形ができあがったわけで、この次は何をしたらいいのでしょうか。よくわからないのでネット上を徘徊してみると、start-PROJECT.pyスクリプトを実行すれば(特に何もいじらずとも)アプリケーションが起動するみたいです。ということで

python start-junksnack.py

としてみました。するとlocalhost:8080で画面が確認できました。しかもご丁寧にもこの後の開発手順が書いてある(・∀・)

1.  Edit your project's model.py to create SQLObjects representing the data you're working with
2. Edit your dev.cfg file to point to the database you'll be using
3. Run "tg-admin sql create" to create the tables in the database
4. Edit controllers.py to add the functionality to your webapp
5. Change the master.kid template to have the headers and footers for your application.
6. Change welcome.kid (this template) or create a new one to display your data
7. Repeat steps 4-6 until done.
8. Profit!

さっそく次へ進みたいと思います。というのはウソで、ちょっと足を止めてstart-junksnack.pyを見てみます。だっていきなり手順1がちょっと難しそうなんだもん。

start-junksnack.pyの冒頭部はいろんなモジュールのインポートです。

#!C:\Python24\python.exe
import pkg_resources
pkg_resources.require("TurboGears")

import turbogears
import cherrypy
cherrypy.lowercase_api = True

from os.path import *
import sys

よくわからなかったのがpkg_resourcesとcherrypy.lowercase_apiですが、pkg_resourcesというのはegg関係の人らしく、Turbogearsがインストールしてないとダメだよということのようです。まぁ、見た感じそのままですね…。

またcherrypy.lowercase_apiは、CherryPyのサイトに何か書いてありました。CherryPyのAPIはCamelCaseで書かれていたのですが、それをlowercase_with_underscoresで書くようになった、と。しかも何かちょっとだけ起動が速くなるようですね(・∀・)

There's a new "cherrypy.lowercase_api" flag, so that users can say "I'm using the new lowercase API" and get a (small) speed boost from it.

start-junksnack.pyの残りの部分は以下の通り:

# first look on the command line for a desired config file,
# if it's not on the command line, then
# look for setup.py in this directory. If it's not there, this script is
# probably installed
if len(sys.argv) > 1:
    turbogears.update_config(configfile=sys.argv[1],
        modulename="junksnack.config")
elif exists(join(dirname(__file__), "setup.py")):
    turbogears.update_config(configfile="dev.cfg",
        modulename="junksnack.config")
else:
    turbogears.update_config(configfile="prod.cfg",
        modulename="junksnack.config")

from junksnack.controllers import Root

turbogears.start_server(Root())

なるほど、ほんとは設定ファイルを指定できるわけですか。

最初にsys.argvを見て、設定ファイルが引数として指定されていればそれを使うということですね。で、設定ファイルが指定されていないときは、setup.pyがあればdev.cfgを、そうでなければprod.cfgを使うわけですか。名前からすると、dev.cfgは開発用の設定ファイル、prod.cfgは本番用の設定ファイルという認識でよいのですかな…?

そのあとのcontrollersとかstart_serverとかはsite-packagesの中のTurbogears-VERSION.eggフォルダの中のファイルの中にあったけれど、難しそうだったので深追いするのは止めました(*´Д`)頭がこんがらがった~。あー、ホントに頭悪いなー。困った困った。

あー、朝だ。1.5hほど寝ておこう。おやすみなさぃ。

Category(s)
Turbogears Turbogears
The URL to Trackback this entry is:
http://nagosui.org:8080/Nagosui/COREBlog2/start-project/tbping

TurboGears関連記事

Posted by Twisted Mind in TurboGears at Aug 06, 2006 05:38 PM
Turbogearsのプロジェクトを作る — nagosui.org http://nagosui.org/Nagosui/COREBlog2/create-project Turbogearsのプロジェクトを起動する — nagosui.org http://nagosui.org/Nagosui/COREBlog2/start-project 素晴らしく丁寧に説明されております。 素晴らしい。 間違ってトラックバックを送っておこう。
Add comment

You can add a comment by filling out the form below. Plain text formatting.

(Required)
(Required)
(Required)
(Required)
Enter the word