TekTekのGoogle App Engine対応は完了したのだが、まだ登録の順番が回ってこない!!
なので、ちょっとメモなど
* Google App Engineではdjangoのauth、sessionは使えないようだ。sessionが使えないのは、djangoのsessionがdjangoのmodelに依存しているからだそうな。この制限は厳しいが誰かが簡単な解決を探してくれるんじゃないかな。
* TekTekでは、sessionをやめて、できる限りCookieに保存するようにした。
2008-04-10
Google App Engineが待ち遠しすぎる。。。
2008-04-09
Google App Engine と格闘中
昨晩、数時間ほどGoogle App Engineで自作のdjangoアプリを移植していた際に気づいたこと。
* printデバッグをしていると、HTTPヘッダの前にprintの結果が出力され、HTTPヘッダもろともブラウザに表示されてしまう。
* urlopenは使えず、Googleが用意したURL Fetch APIを用いる。
* 手元のマシンのpythonのsite-packagesはそのままではどうも見てくれないようだ。
* django の ContextProcessorは通常内部的にrequest.userを使っているようで、以下のようにしてTEMPLATE_CONTEXT_PROCESORSからauthを外す必要がある。
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media"
)
早く本登録来い!!
Google App Engine SDKインストール編
TekTekで使えたらいいなと思って、Google App EngineのSDKをインストールしてみた。
(まだ登録は順番待ちなのです。(T_T)
ひとまずHello worldまで実験完了したので書いておきます。
1. SDKのダウンロード
http://code.google.com/appengine/downloads.html
2. インストール
ダウンロードしたパッケージをひたすらクリックしてインストールして行きます。
その間表示されるメッセージには、以下のようなことが書いてあります。
開発用サーバーは、/usr/local/bin/dev_appserver.py にインストールされます。
その他の部品は /usr/local/google_appengine へインストールされます。
開発サーバーの起動
/usr/local/bin/dev_appserver.py [options] <application root>
"application root"は、文字通りアプリケーションのルートディレクトリで、
正式なフォーマットのapp.yamlかapp.ymlファイルを置いていなければならない。
追加で、以下のコマンドを実行し、各アプリをPythonにインストール。
% sudo ln -s /usr/local/google_appengine/google /usr/local/Python25/lib/python2.5/site-packages/google
※上記"/usr/local/Python25/lib/python2.5/site-packages/"の部分は、
あなたがお使いのPythonのインストールパスに合わせてください。
% cd /usr/local/google_appengine/lib/webob
% sudo python setup.py install
% cd /usr/local/google_appengine/lib/yaml
% sudo python setup.py
※djangoをインストールしていない方は、さらに
% cd /usr/local/google_appengine/lib/django
% sudo python setup.py
3. 確認
% python
>>> from google.appengine.ext import webapp
※このimportで何もエラーがでなければ、OKのようだ。
>>> ^D
4. Hello worldを書く。
% mkdir helloworld
% cd helloworld
※ここでこのディレクトリに以下の2ファイルを作成。
% cat helloworld.py
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
% cat app.yaml
application: helloworld
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: helloworld.py
5. hello worldアプリを起動
先ほどのhelloworldディレクトリ内にいる場合は、その上の階層へ
% cd ..
そして、以下を実行
ayu@~/work% /usr/local/google_appengine/dev_appserver.py helloworld
Allow dev_appserver to check for updates on startup? (Y/n): n
※上でdev_appserver.pyのアップデートをするかを聞かれるが、あせってnを選びました。。。
WARNING 2008-04-09 01:31:55,128 datastore_file_stub.py] Could not read datastore data from /tmp/dev_appserver.datastore
WARNING 2008-04-09 01:31:55,128 datastore_file_stub.py] Could not read datastore data from /tmp/dev_appserver.datastore.history
INFO 2008-04-09 01:31:55,131 dev_appserver_main.py] Running application helloworld on port 8080: http://localhost:8080
ここまでできたら、以下のURLをブラウザで開く。
http://127.0.0.1:8080/
これでhello world!が画面に表示されるはず!!!
2008-04-08
MySQL5のFederatedはまだまだ使えないという話
Every query to a federated table results in a full scan of MyISAM table.
Federatedエンジンでselect count(*) from ...をすると、いちいちテーブルの全レコードをリモートに送り込むというバグがあるそうで、期待のFederatedであったがまだまだ使い物にはならない。
5.1以上で直すことになると見えるが、現時点ではChange logにその修正の旨は発見できず。
投稿者
hiroshiykw
時刻:
1:40 PM
PythonでLatent semantic analysis
Latent Semantic Analysis in Python
興味深い。
【要点】
* TFIDFをベクトルの成分とする。
* scipy のsvdルーチンを使う。(次元が100万とかになっても大丈夫なんだろうか?Lanczos法のような手法を内部で使っているか?)
Blogの記事のような、極端に短い内容の記事も大量にあるような文書集合だと、こういった手法でぼかした検索ができるといいのかもしれません。
でもこういうのは実運用の場合はC++で書くべきと思うよ。
2008-04-07
optparseのhelp文で改行を生かす方法
pythonのoptparseモジュールは便利だが、help文に改行を使ってもうまく表示されない。
解決の参考になるのはここの議論だろう。
以下にそのソースを抜粋。
import optparse
import textwrap
class IndentedHelpFormatterWithNL(optparse.IndentedHelpFormatter):
def format_description(self, description):
if not description: return ""
desc_width = self.width - self.current_indent
indent = " "*self.current_indent
bits = description.split('\n')
formatted_bits = [
textwrap.fill(bit,
desc_width,
initial_indent=indent,
subsequent_indent=indent)
for bit in bits]
result = "\n".join(formatted_bits) + "\n"
return result
def format_option(self, option):
"""
The help for each option consists of two parts:
* the opt strings and metavars
eg. ("-x", or "-fFILENAME, --file=FILENAME")
* the user-supplied help string
eg. ("turn on expert mode", "read data from FILENAME")
If possible, we write both of these on the same line:
-x turn on expert mode
But if the opt string list is too long, we put the help
string on a second line, indented to the same column it would
start in if it fit on the first line.
-fFILENAME, --file=FILENAME
read data from FILENAME
"""
result = []
opts = self.option_strings[option]
opt_width = self.help_position - self.current_indent - 2
if len(opts) > opt_width:
opts = "%*s%s\n" % (self.current_indent, "", opts)
indent_first = self.help_position
else: # start help on same line as opts
opts = "%*s%-*s " % (self.current_indent, "", opt_width, opts)
indent_first = 0
result.append(opts)
if option.help:
help_text = self.expand_default(option)
help_lines = []
for para in help_text.split("\n"):
help_lines.extend(textwrap.wrap(para, self.help_width))
result.append("%*s%s\n" % (
indent_first, "", help_lines[0]))
result.extend(["%*s%s\n" % (self.help_position, "", line)
for line in help_lines[1:]])
elif opts[-1] != "\n":
result.append("\n")
return "".join(result)
if __name__ == "__main__":
parser = optparse.OptionParser(
formatter=IndentedHelpFormatterWithNL(),
usage=u"""....""")
....
投稿者
hiroshiykw
時刻:
11:23 AM
2008-04-05
「ケータイマルチキャリア高機能テスター」を使ってみるよ。
ケータイマルチキャリア高機能テスター P1エミュレーター
を使ってみる事にした。
ほとんどの最近のケータイのエミュレーターになるそうで、携帯用サイトの作成に役立ちそうです。
これでTekTekのi-mode版、SB版も作ってみることにしよう。
投稿者
hiroshiykw
時刻:
6:14 PM