annotate MoinMoin/script/account/disable.py @ 4468:fad2936d33a7 1.8.1

added dummy mig script for 1.8.1, bumped version number
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 24 Dec 2008 16:32:46 +0100
parents 749d7148b080
children a20de9383481
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 - disable 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 disable 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 disable [disable-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 [disable-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 you really want to disable the account.
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 While there is a disable script, no such enable script 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
3770
749d7148b080 script.account: create user checks for already known email adress or username,
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
28 1. To disable the user 'JohnSmith':
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
29 moin ... account disable --name JohnSmith
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
3770
749d7148b080 script.account: create user checks for already known email adress or username,
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
31 2. To disable the user 'JohnSmith', based on his UID '1198872910.78.56322':
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
32 moin ... account disable --uid 1198872910.78.56322
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 """
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
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
35 def __init__(self, argv, def_values):
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
36 MoinScript.__init__(self, argv, def_values)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
37 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
38 "--uid", metavar="UID", dest="uid",
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
39 help="Disable the user with user id UID."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
40 )
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
41 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42 "--name", metavar="NAME", dest="uname",
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
43 help="Disable the user with user name NAME."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44 )
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 def mainloop(self):
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47 # we don't expect non-option arguments
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
48 if len(self.args) != 0:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
49 self.parser.error("incorrect number of arguments")
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
50
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
51 flags_given = self.options.uid or self.options.uname
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
52 if not flags_given:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
53 self.parser.print_help()
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
54 import sys
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
55 sys.exit(1)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
56
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
57 self.init_request()
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
58 request = self.request
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
59
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 929
diff changeset
60 from MoinMoin import user
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
61 if self.options.uid:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
62 u = user.User(request, self.options.uid)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
63 elif self.options.uname:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64 u = user.User(request, None, self.options.uname)
3770
749d7148b080 script.account: create user checks for already known email adress or username,
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
65
749d7148b080 script.account: create user checks for already known email adress or username,
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
66 if not u.exists():
749d7148b080 script.account: create user checks for already known email adress or username,
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
67 print 'This user "%s" does not exists!' % u.name
749d7148b080 script.account: create user checks for already known email adress or username,
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
68 return
749d7148b080 script.account: create user checks for already known email adress or username,
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
69
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
70 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
71 if not u.disabled: # only disable once
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
72 u.disabled = 1
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
73 u.name = "%s-%s" % (u.name, u.id)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
74 if u.email:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
75 u.email = "%s-%s" % (u.email, u.id)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
76 u.subscribed_pages = "" # avoid using email
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
77 u.save()
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
78 print "- disabled."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
79 else:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
80 print "- is already disabled."