~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to cronscripts/check-teamparticipation.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -S
2
2
#
3
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
3
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
4
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
5
 
6
6
# pylint: disable-msg=C0103,W0403
20
20
 
21
21
import _pythonpath
22
22
 
23
 
from lp.registry.scripts.teamparticipation import check_teamparticipation
 
23
from lp.registry.scripts.teamparticipation import (
 
24
    check_teamparticipation_circular,
 
25
    check_teamparticipation_consistency,
 
26
    check_teamparticipation_self,
 
27
    fetch_team_participation_info,
 
28
    )
24
29
from lp.services.scripts.base import LaunchpadScript
 
30
from lp.services.utils import (
 
31
    load_bz2_pickle,
 
32
    save_bz2_pickle,
 
33
    )
25
34
 
26
35
 
27
36
class CheckTeamParticipationScript(LaunchpadScript):
28
37
    description = "Check for invalid/missing TeamParticipation entries."
29
38
 
 
39
    def add_my_options(self):
 
40
        self.parser.add_option(
 
41
            "--load-participation-info",
 
42
            dest="load_info", metavar="FILE", help=(
 
43
                "File from which to load participation information "
 
44
                "instead of going to the database."))
 
45
        self.parser.add_option(
 
46
            "--save-participation-info",
 
47
            dest="save_info", metavar="FILE", help=(
 
48
                "File in which to save participation information, for "
 
49
                "later processing with --load-participation-info."))
 
50
 
30
51
    def main(self):
31
 
        check_teamparticipation(self.logger)
 
52
        """Perform various checks on the `TeamParticipation` table."""
 
53
        if self.options.load_info:
 
54
            participation_info = load_bz2_pickle(self.options.load_info)
 
55
        else:
 
56
            check_teamparticipation_self(self.logger)
 
57
            check_teamparticipation_circular(self.logger)
 
58
            participation_info = fetch_team_participation_info(self.logger)
 
59
        if self.options.save_info:
 
60
            save_bz2_pickle(participation_info, self.options.save_info)
 
61
        else:
 
62
            check_teamparticipation_consistency(
 
63
                self.logger, participation_info)
32
64
 
33
65
 
34
66
if __name__ == '__main__':