-
Notifications
You must be signed in to change notification settings - Fork 9
/
manage.py
executable file
·54 lines (43 loc) · 1.52 KB
/
manage.py
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
#!/usr/bin/env python2
from __future__ import print_function
import sys
from dudel import manager, db, app
from dudel.models import Poll
@manager.command
def cron(verbose=False):
"""
This view should execute some regular tasks to be called by a cronjob, e.g.
by simply calling "./manage.py cron"
"""
def stdout(*args, **kwargs):
if not verbose: return
if 'end' not in kwargs: kwargs['end'] = '\n'
print(*args, **kwargs)
def stderr(*args, **kwargs):
if 'end' not in kwargs: kwargs['end'] = '\n'
kwargs['file'] = sys.stderr
print(*args, **kwargs)
if "ldap" in app.config['LOGIN_PROVIDERS']:
# Update LDAP only if it is enabled
from dudel.plugins.ldapauth import ldap_connector
try:
stdout("Updating LDAP users... ", end="")
ldap_connector.update_users()
stdout("[DONE]")
except Exception, e:
stdout("[FAILED]")
stderr("Error updating LDAP users: %s" % str(e))
try:
stdout("Updating LDAP groups... ", end="")
ldap_connector.update_groups()
stdout("[DONE]")
except Exception, e:
stdout("[FAILED]")
stderr("Error updating LDAP groups: %s" % str(e))
for poll in Poll.query.filter_by(deleted=False).all():
if poll.should_auto_delete:
poll.deleted = True
stdout("Auto-deleted poll: %s" % poll.title)
db.session.commit()
if __name__ == '__main__':
manager.run()