1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/usr/bin/env python
from flask import current_app
from flask.ext.script import Command, Manager, Server, Shell, Option
from accounts import app
from accounts.utils.console import TablePrinter
class ListServices(Command):
"""List the configured services."""
name = 'list-services'
def run(self):
table = TablePrinter(['Name', 'URL'])
table.output([(service.name, service.url)
for service in current_app.all_services])
class ListUsers(Command):
"""List registered users."""
name = 'list-users'
option_list = (
Option('--locked', '-l', action='store_true', dest='locked',
help='Include locked users.'),
Option('--only-locked', '-L', action='store_true', dest='only_locked',
help='Show ONLY locked users.'),
)
def _get_users(self, locked, only_locked):
for user in current_app.user_backend.find():
user_locked = user.mail.startswith('noreply-disabledaccount-')
if user_locked and not (locked or only_locked):
continue
elif not user_locked and only_locked:
continue
yield user
def run(self, locked, only_locked):
table = TablePrinter(['Name', 'E-Mail'])
table.output([(user.uid, user.mail)
for user in self._get_users(locked, only_locked)])
def main():
manager = Manager(app)
manager.add_command(
'runserver', Server(host='::', use_debugger=False))
manager.add_command(
'debug', Server(host='::', use_debugger=True))
manager.add_command(
'shell', Shell())
manager.add_command(ListServices)
manager.add_command(ListUsers)
manager.run()
if __name__ == '__main__':
main()
|