~launchpad-pqm/launchpad/devel

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
3691.272.14 by Guilherme Salgado
Add a team-membership-janitor celebrity, which is responsible for flagging the expired memberships
18
from canonical.launchpad.interfaces import (
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
19
    DAYS_BEFORE_EXPIRATION_WARNING_IS_SENT, ILaunchpadCelebrities,
20
    ITeamMembershipSet)
8356.1.1 by Leonard Richardson
Partial move.
21
from lp.services.scripts.base import (
4264.2.1 by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it
22
    LaunchpadCronScript, LaunchpadScriptFailure)
23
24
25
class ExpireMemberships(LaunchpadCronScript):
4621.5.11 by Curtis Hovey
Merge from RF. Resolved sampledata conflict. Fixed imports, lines, and docstrings.
26
    """A script for expired team memberships."""
27
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
28
    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.
29
        """Flag expired team memberships and warn about impending expiration.
30
31
        Flag expired team memberships and send warnings for members whose
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
32
        memberships are going to expire in one week (or less) from now.
33
        """
34
        membershipset = getUtility(ITeamMembershipSet)
35
        self.txn.begin()
4621.5.28 by Curtis Hovey
Renamed Launchpan Janitor per review.
36
        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
37
        membershipset.handleMembershipsExpiringToday(reviewer)
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
38
        self.txn.commit()
39
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
40
        min_date_for_warning = datetime.now(pytz.timezone('UTC')) + timedelta(
41
            days=DAYS_BEFORE_EXPIRATION_WARNING_IS_SENT)
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
42
        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
43
        for membership in membershipset.getMembershipsToExpire(
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
44
                min_date_for_warning):
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
45
            membership.sendExpirationWarningEmail()
46
        self.txn.commit()
47
48
    def main(self):
4621.5.11 by Curtis Hovey
Merge from RF. Resolved sampledata conflict. Fixed imports, lines, and docstrings.
49
        """Flag expired team memberships."""
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
50
        if self.args:
51
            raise LaunchpadScriptFailure(
52
                "Unhandled arguments %s" % repr(self.args))
53
        self.logger.info("Flagging expired team memberships.")
54
        self.flag_expired_memberships_and_send_warnings()
55
        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
56
2770.1.47 by Guilherme Salgado
New cronscript to flag expired team memberships and some other cleanups.
57
58
if __name__ == '__main__':
4621.5.7 by Curtis Hovey
Replaced answer_tracker_janitor and team_membership_janitor with
59
    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
60
                               dbuser=config.expiredmembershipsflagger.dbuser)
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
61
    script.lock_and_run()
2770.1.47 by Guilherme Salgado
New cronscript to flag expired team memberships and some other cleanups.
62