Commit aa66479a authored by Benjamin Fischer's avatar Benjamin Fischer
Browse files

[bin] script for bulk adding users

parent f8b96db7
#!/usr/bin/env python
import sys
import os
base = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
if os.path.isdir(base):
sys.path.insert(0, base)
from argparse import ArgumentParser
import logging
logging.basicConfig(level=logging.INFO)
parser = ArgumentParser()
parser.add_argument('-c', '--configdir', help='Directory containing configuration files.')
parser.add_argument('-d', '--datadir', help='Directory containing server.')
args = parser.parse_args()
import vispa
import vispa.models
from sqlalchemy.orm import scoped_session, sessionmaker
vispa.setup_config(args.configdir)
session = scoped_session(sessionmaker(autoflush=True, autocommit=False))
session.configure(bind=vispa.models.open_database(args.datadir))
from vispa.models.user import User
while True:
try:
inp = raw_input()
except EOFError, KeyboardInterrupt:
break
if not inp:
break
name, password = unicode(inp).strip().split(":", 1)
try:
User.set_password(session, User.register(session, name, "%s@nowhere" % name).hash, password)
except vispa.AjaxException as ex:
res = ex.message
else:
res = "ok!"
print "%15s: %s" % (name, res)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment