tornadoの最近のブログ記事

from pymongo import Connection
from time import sleep

reconnect_times = 10
reconnect_counter = 0

def con(**kwargs):

    global reconnect_counter
    global reconnect_times

    if 'host' not in kwargs:
        kwargs['host'] = settings.application['dbhost']
    dbname = settings.application['dbname']

    try:
        _con = Connection(**kwargs)
        return eval('_con.'+dbname)

    except Exception, e:

        sleep(0.1)

        print('Fail to excute %s [%s]' % ( __name__, e))
        if reconnect_counter == reconnect_times:
            reconnect_counter = reconnect_counter + 1
            con(**kwargs)

==
mongodb 1.5.* は若干バギーで、コネクトエラーがたまにでる。(でるらしいので、pymongoのコネクトラッパーらしきものもあるが)自前で、対応
べーすハンドラーに
class BaseHandler(tornado.web.RequestHandler):
    def get_user_locale(self):
        return tornado.locale.get(*[self.get_cookie('lang', None)])

get_user_locale を上記のように指定すると、
cookie lang に locale の指定があれば、locale テーブルを差し替えられる。

== po file 作成サンプルシェル ==

BASE=.
DOMAINNAME='main'
FILELIST=$BASE/templates
POFILEDIR=$BASE/po
XGETTEXT=`which xgettext`

find $FILELIST -type f > .tmp
touch $POFILEDIR/$DOMAINNAME.pot
$XGETTEXT -j -n -o $POFILEDIR/$DOMAINNAME.pot --keyword=_:1,2 --language=Python -f .tmp
rm .tmp

#for x in "af_ZA" "ar_AR" "bg_BG" "bn_IN" "bs_BA" "ca_ES" "cs_CZ" "cy_GB" "da_DK" "de_DE" "el_GR" "en_GB" "en_US" "es_ES" "es_LA" "et_EE" "eu_ES" "fa_IR" "fi_FI" "fr_CA" "fr_FR" "ga_IE" "gl_ES" "he_IL" "hi_IN" "hr_HR" "hu_HU" "id_ID" "is_IS" "it_IT" "ja_JP" "ko_KR" "lt_LT" "lv_LV" "mk_MK" "ml_IN" "ms_MY" "nb_NO" "nl_NL" "nn_NO" "pa_IN" "pl_PL" "pt_BR" "pt_PT" "ro_RO" "ru_RU" "sk_SK" "sl_SI" "sq_AL" "sr_RS" "sv_SE" "sw_KE" "ta_IN" "te_IN" "th_TH" "tl_PH" "tr_TR" "uk_UA" "vi_VN" "zh_CN" "zh_HK" "zh_TW";
for x in "ja_JP";
do

LOCALE=$x
POPATH=$POFILEDIR/$LOCALE.po

test ! -f $POPATH && touch $POPATH

nkf -wLu $POPATH > $POFILEDIR/$LOCALE.old.po
msgmerge -v $POFILEDIR/$LOCALE.old.po $POFILEDIR/$DOMAINNAME.pot -o $POPATH
done


このアーカイブについて

このページには、過去に書かれたブログ記事のうちtornadoカテゴリに属しているものが含まれています。

前のカテゴリはSSLです。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。