Mercurial > public > src > moin > extensions
changeset 566:ca006bf7dae8
script.account.create_many: script to create many users given from a comma separated list of a file e.g. Username, user@email.de
author | Reimar Bauer <rb.proj AT googlemail DOT com> |
---|---|
date | Mon, 19 Sep 2011 17:36:48 +0200 |
parents | 03bb9b27aca8 |
children | 854b5b2a059c |
files | data/plugin/script/account/create_many.py |
diffstat | 1 files changed, 87 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/plugin/script/account/create_many.py Mon Sep 19 17:36:48 2011 +0200 @@ -0,0 +1,87 @@ +# -*- coding: iso-8859-1 -*- +""" +MoinMoin - create a user account + +@copyright: 2006 MoinMoin:ThomasWaldmann, + 2011 MoinMoin:ReimarBauer +@license: GNU GPL, see COPYING for details. +""" +import sys +try: + from pwgen import pwgen +except ImportError: + print '!!!' + print 'You need to "pip install pwgen"' + print '(http://pypi.python.org/pypi/pwgen)' + print '!!!' + sys.exit() +from MoinMoin.script import MoinScript +from MoinMoin import user + +class PluginScript(MoinScript): + """\ +Purpose: +======== +This tool allows you to create many accounts via a command line interface. + +Detailed Instructions: +====================== +General syntax: moin [options] account create [create-options] + +[options] usually should be: + --config-dir=/path/to/my/cfg/ --wiki-url=http://wiki.example.org/ + +[create-options] see below: + 1. Verify that you have specified the right options. + This script does no verification of email addresses or the like. + + 2. To create users you need an input file: with lines of Wiki UserName, EMAIL + moin ... account create --filename input_file.csv +""" + + def __init__(self, argv, def_values): + MoinScript.__init__(self, argv, def_values) + self.parser.add_option( + "--filename", metavar="filename", dest="filename", + help="comma separated file of WikiUsername, email." + ) + + def mainloop(self): + # we don't expect non-option arguments + if len(self.args) != 0: + self.parser.error("incorrect number of arguments") + + flags_given = self.options.filename + if not flags_given: + self.parser.print_help() + sys.exit(1) + + self.init_request() + request = self.request + + text = file(self.options.filename, 'r').read() + lines = text.split('\n') + for line in lines: + try: + uname, email = line.split(',') + uname = uname.strip() + email = email.strip() + if '@' in email: + password = pwgen(10, no_symbols=True) + if user.User(request, name=uname).exists(): + print 'This username "%s" exists already!' % uname + return + # Email should be unique - see also MoinMoin.action.newaccount + if email and request.cfg.user_email_unique: + if user.get_by_email_address(request, email): + print 'This emailaddress "%s" belongs to someone else!' % email + return + u = user.User(request, None, uname, password=password) + u.email = email + u.aliasname = '' + print " %-20s %-25s %-35s" % (u.id, u.name, u.email), u.save() + print "- created." + + except ValueError: + print line +