annotate MoinMoin/script/account/create.py @ 3108:2572688e031a

improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 23:40:48 +0100
parents bb2e053067fb
children 749d7148b080 085328cb4f4d
rev   line source
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
2 """
3108
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
3 MoinMoin - create a user account
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
4
3108
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
5 @copyright: 2006 MoinMoin:ThomasWaldmann
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
6 @license: GNU GPL, see COPYING for details.
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
7 """
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
8
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 501
diff changeset
9 from MoinMoin.script import MoinScript
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
10
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
11 class PluginScript(MoinScript):
3108
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
12 """\
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
13 Purpose:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
14 ========
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
15 This tool allows you to create user accounts via a command line interface.
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
16
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
17 Detailed Instructions:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
18 ======================
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
19 General syntax: moin [options] account create [create-options]
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
20
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
21 [options] usually should be:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
22 --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
23
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
24 [create-options] see below:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
25 0. Verify that the account does not exist.
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
26 Currently this script does not check if the user exists.
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
27
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
28 1. Verify that you have specified the right options.
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
29 This script does no verification of email addresses or the like.
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
30
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
31 2. To create a normal user 'JohnSmith' with an alias of 'JSmith' and an
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
32 email of 'john@smith.com'
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
33 moin ... account create --name JohnSmith --alias JSmith --email john@smith.com
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
34 """
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
35
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
36 def __init__(self, argv, def_values):
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
37 MoinScript.__init__(self, argv, def_values)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
38 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
39 "--name", metavar="NAME", dest="uname",
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
40 help="Set the wiki user name to NAME."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
41 )
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
43 "--alias", metavar="ALIAS", dest="ualiasname",
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44 help="Set the wiki user alias name to ALIAS (e.g. the real name if NAME is cryptic)."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
45 )
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
46 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47 "--email", metavar="EMAIL", dest="email",
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
48 help="Set the user's email address to EMAIL."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
49 )
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
50 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
51 "--password", metavar="PASSWORD", dest="password",
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
52 help="Set the user's password to PASSWORD (either cleartext or {SHA1}...)."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
53 )
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
54
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
55 def mainloop(self):
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
56 # we don't expect non-option arguments
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
57 if len(self.args) != 0:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
58 self.parser.error("incorrect number of arguments")
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
59
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
60 flags_given = self.options.uname and self.options.email
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
61 if not flags_given:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
62 self.parser.print_help()
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
63 import sys
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64 sys.exit(1)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
65
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
66 self.init_request()
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
67 request = self.request
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
68
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 670
diff changeset
69 from MoinMoin import user
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
70 u = user.User(request, None, self.options.uname, password=self.options.password)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
71 u.email = self.options.email
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
72 u.aliasname = self.options.ualiasname or ''
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
73 print " %-20s %-25s %-35s" % (u.id, u.name, u.email),
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
74 u.save()
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
75 print "- created."