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 循环中调用的值。

如果我运行交互式 shell 并导入这个文件,它就可以工作。如果我尝试使用 < 将其拉入,它会在没有任何输出的情况下运行并退出,但它不会像我在 shell 中以交互方式运行它时那样创建用户。输出如下所示:

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