0

歩哨コマンドでこれを試しています:

sentry --config=sentry.conf.py shell < add_user.py

add_user.py は次のようになります。

from django.contrib.auth.models import User

try:
    import authfile
except Exception as e:
    print "authfile not present, %s" % e

def conv_dict(the_dict):
    sen_username = the_dict['sen_username']
    sen_email = the_dict['sen_email']
    sen_password = the_dict['sen_password']
    print sen_username
    return sen_username, sen_email, sen_password

for t, imp_dict in authfile.__dict__.iteritems():
    if isinstance(imp_dict, dict) and not t.startswith('_'):
        sen_username, sen_email, sen_password = conv_dict(imp_dict)
        try:
            new_user = User.objects.create_user( sen_username, sen_email, sen_password)
            new_user.is_superuser = True
            print "created new user: %s" % imp_dict['sen_username']
        except Exception as e:
            print "could not create new user: %s" % e
            pass

authfile は、for ループで呼び出された値を入力する一連の辞書です。

対話型シェルを実行してこのファイルをインポートすると、機能します。< でプルしようとすると、出力なしで実行されて終了しますが、シェルで対話的に実行した場合のようにユーザーを作成しません。出力は次のようになります。

sentry --config=../sentry.conf.py shell < add_super.py
Python 2.7.3 (default, Aug  9 2012, 17:23:57)
Type "copyright", "credits" or "license" for more information.

IPython 1.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:
In [2]:
In [2]:
In [3]:
In [3]:    ...:    ...:    ...:    ...:    ...:    ...:
In [4]:    ...:    ...:    ...:    ...:    ...:    ...:    ...:    ...:    ...:    ...:
Do you really want to exit ([y]/n)?
4

0 に答える 0