10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python -S
|
8687.15.7
by Karl Fogel
Add the copyright header block to more files. |
2 |
#
|
3 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5 |
||
4935.3.7
by Curtis Hovey
Added bad name suppression to cronscripts. |
6 |
# pylint: disable-msg=C0103,W0403
|
2770.1.47
by Guilherme Salgado
New cronscript to flag expired team memberships and some other cleanups. |
7 |
|
4621.5.11
by Curtis Hovey
Merge from RF. Resolved sampledata conflict. Fixed imports, lines, and docstrings. |
8 |
"""Flag expired team memberships and warn about impending expiration."""
|
9 |
||
2770.1.47
by Guilherme Salgado
New cronscript to flag expired team memberships and some other cleanups. |
10 |
import _pythonpath |
11 |
||
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
12 |
import pytz |
3691.272.22
by Guilherme Salgado
Fix https://launchpad.net/launchpad/+bug/70518: Notify team members when their membership is going to expire |
13 |
from datetime import datetime, timedelta |
2770.1.47
by Guilherme Salgado
New cronscript to flag expired team memberships and some other cleanups. |
14 |
|
15 |
from zope.component import getUtility |
|
16 |
||
17 |
from canonical.config import config |
|
13130.1.21
by Curtis Hovey
Fixed cronscript imports. |
18 |
from lp.app.interfaces.launchpad import ILaunchpadCelebrities |
11882.2.2
by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces. |
19 |
from lp.registry.interfaces.teammembership import ( |
20 |
DAYS_BEFORE_EXPIRATION_WARNING_IS_SENT, |
|
21 |
ITeamMembershipSet, |
|
22 |
)
|
|
8356.1.1
by Leonard Richardson
Partial move. |
23 |
from lp.services.scripts.base import ( |
4264.2.1
by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it |
24 |
LaunchpadCronScript, LaunchpadScriptFailure) |
25 |
||
26 |
||
27 |
class ExpireMemberships(LaunchpadCronScript): |
|
4621.5.11
by Curtis Hovey
Merge from RF. Resolved sampledata conflict. Fixed imports, lines, and docstrings. |
28 |
"""A script for expired team memberships."""
|
29 |
||
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
30 |
def flag_expired_memberships_and_send_warnings(self): |
4621.5.11
by Curtis Hovey
Merge from RF. Resolved sampledata conflict. Fixed imports, lines, and docstrings. |
31 |
"""Flag expired team memberships and warn about impending expiration.
|
32 |
||
33 |
Flag expired team memberships and send warnings for members whose
|
|
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
34 |
memberships are going to expire in one week (or less) from now.
|
35 |
"""
|
|
36 |
membershipset = getUtility(ITeamMembershipSet) |
|
37 |
self.txn.begin() |
|
4621.5.28
by Curtis Hovey
Renamed Launchpan Janitor per review. |
38 |
reviewer = getUtility(ILaunchpadCelebrities).janitor |
4108.4.9
by Guilherme Salgado
Fix the flag-expired-memberships.py cronscript to auto renew memberships of teams which have a renewal policy set to AUTOMATIC |
39 |
membershipset.handleMembershipsExpiringToday(reviewer) |
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
40 |
self.txn.commit() |
41 |
||
4108.4.13
by Guilherme Salgado
Second half of the fix for https://launchpad.net/bugs/70519: Allow members of teams with an ONDEMAND renewal policy to renew their own memberships |
42 |
min_date_for_warning = datetime.now(pytz.timezone('UTC')) + timedelta( |
43 |
days=DAYS_BEFORE_EXPIRATION_WARNING_IS_SENT) |
|
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
44 |
self.txn.begin() |
4108.4.9
by Guilherme Salgado
Fix the flag-expired-memberships.py cronscript to auto renew memberships of teams which have a renewal policy set to AUTOMATIC |
45 |
for membership in membershipset.getMembershipsToExpire( |
11128.7.1
by Edwin Grubbs
Do not send membership expiration emails for teams with automatic membership renewal. |
46 |
min_date_for_warning, exclude_autorenewals=True): |
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
47 |
membership.sendExpirationWarningEmail() |
11128.7.1
by Edwin Grubbs
Do not send membership expiration emails for teams with automatic membership renewal. |
48 |
self.logger.debug("Sent warning email to %s in %s team." |
49 |
% (membership.person.name, membership.team.name)) |
|
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
50 |
self.txn.commit() |
51 |
||
52 |
def main(self): |
|
4621.5.11
by Curtis Hovey
Merge from RF. Resolved sampledata conflict. Fixed imports, lines, and docstrings. |
53 |
"""Flag expired team memberships."""
|
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
54 |
if self.args: |
55 |
raise LaunchpadScriptFailure( |
|
56 |
"Unhandled arguments %s" % repr(self.args)) |
|
57 |
self.logger.info("Flagging expired team memberships.") |
|
58 |
self.flag_expired_memberships_and_send_warnings() |
|
59 |
self.logger.info("Finished flagging expired team memberships.") |
|
3691.272.22
by Guilherme Salgado
Fix https://launchpad.net/launchpad/+bug/70518: Notify team members when their membership is going to expire |
60 |
|
2770.1.47
by Guilherme Salgado
New cronscript to flag expired team memberships and some other cleanups. |
61 |
|
62 |
if __name__ == '__main__': |
|
4621.5.7
by Curtis Hovey
Replaced answer_tracker_janitor and team_membership_janitor with |
63 |
script = ExpireMemberships('flag-expired-memberships', |
4108.4.13
by Guilherme Salgado
Second half of the fix for https://launchpad.net/bugs/70519: Allow members of teams with an ONDEMAND renewal policy to renew their own memberships |
64 |
dbuser=config.expiredmembershipsflagger.dbuser) |
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
65 |
script.lock_and_run() |