ARMで動くかどうか試してみる

Google App EngineをHDL-GT上のOLP Sarge/Python2.4環境でテスト。
とりあえず動作する模様。
ベースはlocalhostでしか動作しないので、中を書き換えてリモートからも参照できた。

      • -

Pythonだということなので、ARM上でも動くのかな?
ローカル環境がそのまま単体動作で使えると面白いかも。
BigTableないからダメか?


環境はOLP Sarge版。
たまたま起動していたからというのが理由。
作業は一般ユーザーでいいのかな?


SDKのダウンロード
http://code.google.com/appengine/downloads.html
http://googleappengine.googlecode.com/files/google_appengine.zip
なぜにzipなのだ?
展開する。

admin@OLP_GT:~$ wget http://googleappengine.googlecode.com/files/google_appengine.zip
admin@OLP_GT:~$ unzip google_appengine.zip

ライセンスの確認。

admin@OLP_GT:~$ cd google_appengine
admin@OLP_GT:~/google_appengine$ more LICENSE

ライセンスはApache License, Version 2.0だそうな。
Django,WebOb,PyYamlのライセンスも書かれている。
READMEに目を通す。

admin@OLP_GT:~/google_appengine$ more README

なんでインストール手順がMacが先頭なんだろう。Macで開発されたのかな?
あれ、Linux版にはPythonは入ってないそうだ。
Sargeには2.5はないからめんどくさいな。
今はいっているのはPython 2.3.5。
このまま進んでみる。


インストールという作業は特にはない。
展開したままで、dev_appserver.pyをオプション付けて実行するだけみたい。
コマンドとオプションはこれ。

dev_appserver.py [options] <application root>

  --help, -h                 View this helpful message.
  --debug, -d                Use debug logging. (Default false)
  --clear_datastore, -c      Clear the Datastore on startup. (Default false)
  --address=ADDRESS, -a ADDRESS
                             Address to which this server should bind. (Default
                             localhost).
  --port=PORT, -p PORT       Port for the server to run on. (Default 8080)
  --datastore_path=PATH      Path to use for storing Datastore file stub data.
                             (Default /tmp/dev_appserver.datastore)
  --history_path=PATH        Path to use for storing Datastore history.
                             (Default /tmp/dev_appserver.datastore.history)
  --require_indexes          Disallows queries that require composite indexes
                             not defined in index.yaml.
  --smtp_host=HOSTNAME       SMTP host to send test mail to.  Leaving this
                             unset will disable SMTP mail sending.
                             (Default '')
  --smtp_port=PORT           SMTP port to send test mail to.
                             (Default 25)
  --smtp_user=USER           SMTP user to connect as.  Stub will only attempt
                             to login if this field is non-empty.
                             (Default '').
  --smtp_password=PASSWORD   Password for SMTP server.
                             (Default '')
  --enable_sendmail          Enable sendmail when SMTP not configured.
                             (Default false)
  --auth_domain              Authorization domain that this app runs in.
                             (Default gmail.com)
  --debug_imports            Enables debug logging for module imports, showing
                             search paths used for finding modules and any
                             errors encountered during the import process.

yamlでアプリ情報を記述しておくと、appcfg.pyコマンドで鯖に送れるようだ。
あとは、以下を読めということで。
http://code.google.com/appengine/docs/gettingstarted


チュートリアルのhelloworldをやってみる。

admin@OLP_GT:~/google_appengine$ cd ~
admin@OLP_GT:~$ mkdir helloworld
admin@OLP_GT:~$ cd helloworld/
admin@OLP_GT:~/helloworld$ vi helloworld.py
	print 'Content-Type: text/plain'
	print ''
	print 'Hello, ARM world!'
admin@OLP_GT:~/helloworld$ vi app.yaml
	application: helloworld
	version: 1
	runtime: python
	api_version: 1
	
	handlers:
	- url: /.*
	  script: helloworld.py

起動してみる。

admin@OLP_GT:~/helloworld$ ../google_appengine/dev_appserver.py ./
Error: Python 2.3 is not supported. Please use version 2.5 or greater.

うへ、怒られた...


Googleさんちのコーディングルールは、2タブですか。
どうも、違和感あるな。
イマイチ見通しが悪いような気が。


Pythonのバージョンは、appcfg.pyでチェックされているようだ。
中を見ると、2.4であれば、まだワーニングで動作するようになっている。
無理やり進むのに、ここを潰してみた。

OLP_GT:/home/admin/google_appengine# vi appcfg.py

appcfg,pyはwrite権限がみな削られているのでroot権限で強制上書きする必要がある。


再挑戦。

admin@OLP_GT:~/helloworld$ ../google_appengine/dev_appserver.py ./
Error: Python 2.3 is not supported. Please use version 2.5 or greater.

あれ、ここだけじゃなかったのか。
dev_appserver.pyにも同じようなコードがあった...
同様に潰す。

OLP_GT:/home/admin/google_appengine# vi dev_appserver.py


三度目の正直。

admin@OLP_GT:~/helloworld$ ../google_appengine/dev_appserver.py ./
Traceback (most recent call last):
  File "../google_appengine/dev_appserver.py", line 50, in ?
    execfile(script_path, globals())
  File "/home/admin/google_appengine/google/appengine/tools/dev_appserver_main.py", line 67, in ?
    from google.appengine.tools import appcfg
  File "/home/admin/google_appengine/google/appengine/tools/appcfg.py", line 162
    for x in response_body.split("\n") if x)
      ^
SyntaxError: invalid syntax

確認。

admin@OLP_GT:~/google_appengine$ python
Python 2.3.5 (#2, Oct 16 2006, 22:16:27)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.appengine.tools import appcfg
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "google/appengine/tools/appcfg.py", line 162
    for x in response_body.split("\n") if x)
      ^
SyntaxError: invalid syntax

構文エラーじゃPythonを上げないとしょうがいないね...


2.4ならセーフのようなので、それを入れることに。

OLP_GT:~# apt-get install python2.4
Need to get 3476kB of archives.
After unpacking 11.5MB of additional disk space will be used.
Get:1 http://ftp.debian.org sarge/main python2.4 2.4.1-2sarge1 [3476kB]
Fetched 3476kB in 12s (275kB/s)

デフォルトで、2.4のほうを指すように変更。

OLP_GT:~# ls -al /usr/bin/python
lrwxrwxrwx  1 root root 9 Feb 13 21:03 /usr/bin/python -> python2.3
OLP_GT:~# rm /usr/bin/python
OLP_GT:~# ln -s /usr/bin/python2.4 /usr/bin/python
OLP_GT:~# ls -al /usr/bin/python
lrwxrwxrwx  1 root root 18 Apr  9 10:19 /usr/bin/python -> /usr/bin/python2.4
OLP_GT:~# python
Python 2.4.1 (#2, Oct 19 2006, 03:26:48)

準備できた。


4度目の正直?

admin@OLP_GT:~$ google_appengine/dev_appserver.py helloworld/
Allow dev_appserver to check for updates on startup? (Y/n):
dev_appserver will check for updates on startup.  To change this setting, edit /home/admin/.appcfg_nag
INFO     2008-04-09 10:21:19,441 appcfg.py] Checking for updates to the SDK.
INFO     2008-04-09 10:21:20,289 appcfg.py] The SDK is up to date.
WARNING  2008-04-09 10:21:20,292 datastore_file_stub.py] Could not read datastore data from /tmp/dev_appserver.datastore
WARNING  2008-04-09 10:21:20,295 datastore_file_stub.py] Could not read datastore data from /tmp/dev_appserver.datastore.history
INFO     2008-04-09 10:21:20,375 dev_appserver_main.py] Running application helloworld on port 8080: http://localhost:8080

SDKのアップデートチェックがされて、アップデートされちゃったみたい。
バージョンチェックを潰してあったのは、上書きでもとに戻された?
調べてみたけど、一番上の階層のものは変更されていなかった。
更新はgoogle以下かな。


サービスはlocalhostのみでしか上がらないようだ。
これでは外部からのアクセスができない。
ARMローカルにはブラウザがないから、これでは開発がめんどくさい。
portは、起動時の引数で決めることができる。
インターフェイス縛りはこのへんかな?

google_appengine/google/appengine/tools/dev_appserver_main.py:  ARG_ADDRESS: 'localhost',

変更して起動してみる。

admin@OLP_GT:~$ ./google_appengine/dev_appserver.py ./helloworld/
INFO     2008-04-09 10:44:10,586 appcfg.py] Checking for updates to the SDK.
INFO     2008-04-09 10:44:11,525 appcfg.py] The SDK is up to date.
WARNING  2008-04-09 10:44:11,528 datastore_file_stub.py] Could not read datastore data from /tmp/dev_appserver.datastore
WARNING  2008-04-09 10:44:11,531 datastore_file_stub.py] Could not read datastore data from /tmp/dev_appserver.datastore.history
INFO     2008-04-09 10:44:11,695 dev_appserver_main.py] Running application helloworld on port 8080: http://192.168.123.28:8080

うまく外向けに起動した。


別端末のブラウザからアクセスしてみる。

Hello, ARM world!

外部からのアクセスに成功。


コンソールログはこんな感じ。

INFO     2008-04-09 01:45:11,997 dev_appserver.py] "GET / HTTP/1.1" 200 -
INFO     2008-04-09 01:45:12,018 dev_appserver_index.py] Updating /home/admin/helloworld/index.yaml
INFO     2008-04-09 01:45:12,446 dev_appserver.py] "GET /favicon.ico HTTP/1.1" 200 -


あ、間抜けだ。
アドレス指定もオプションにあるじゃん...orz

--address=ADDRESS


プロジェクトのテンプレートはnew_project_templateディレクトリにあって、中にはapp.yaml,index.yaml,main.pyがある。シンプル。
これなら、Python使いの人ならば苦もなく遊べるね。