~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
#
14213.4.33 by Gavin Panella
Update copyright.
3
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
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
4868.1.1 by Guilherme Salgado
Make TeamMembership.setStatus call flush_db_updates() and add a script to fix the db corruption caused by the lack of flush_db_updates() on setStatus when it's called from the flag-expired-memberships script
7
7052.1.1 by Guilherme Salgado
Fix check-teamparticipation.py to use a logger rather than printing stuff to stdout
8
"""Check for invalid/missing TeamParticipation entries.
4868.1.6 by Guilherme Salgado
Turn the script that was supposed to fix invalid team participation entries into something that just reports the invalid ones, to be run from staging
9
7052.1.1 by Guilherme Salgado
Fix check-teamparticipation.py to use a logger rather than printing stuff to stdout
10
Invalid TP entries are the ones for which there are no active TeamMemberships
11
leading to.
4868.1.6 by Guilherme Salgado
Turn the script that was supposed to fix invalid team participation entries into something that just reports the invalid ones, to be run from staging
12
13
This script is usually run on staging to find discrepancies between the
7052.1.1 by Guilherme Salgado
Fix check-teamparticipation.py to use a logger rather than printing stuff to stdout
14
TeamMembership and TeamParticipation tables which are a good indication of
4868.1.6 by Guilherme Salgado
Turn the script that was supposed to fix invalid team participation entries into something that just reports the invalid ones, to be run from staging
15
bugs in the code which maintains the TeamParticipation table.
16
17
Ideally there should be database constraints to prevent this sort of
18
situation, but that's not a simple thing and this should do for now.
19
"""
20
9641.1.4 by Gary Poster
more updates for _pythonpath. Still need to update all subprocess calls to python to use -S; still need to update z3c.recipe.filetemplate to provide sys.modules from -S run.
21
import _pythonpath
14213.4.2 by Gavin Panella
Move check_teamparticipation() into sys.path.
22
14213.4.26 by Gavin Panella
Enable loading and saving of team participation info. Work in progress.
23
from lp.registry.scripts.teamparticipation import (
24
    check_teamparticipation_circular,
25
    check_teamparticipation_consistency,
26
    fetch_team_participation_info,
14464.1.7 by Gavin Panella
Fix team participations by default.
27
    fix_teamparticipation_consistency,
14213.4.26 by Gavin Panella
Enable loading and saving of team participation info. Work in progress.
28
    )
14213.4.2 by Gavin Panella
Move check_teamparticipation() into sys.path.
29
from lp.services.scripts.base import LaunchpadScript
14213.4.29 by Gavin Panella
Move load() and save() from check-teamparticipation.py to lp.services.utils.
30
from lp.services.utils import (
31
    load_bz2_pickle,
32
    save_bz2_pickle,
33
    )
14213.4.26 by Gavin Panella
Enable loading and saving of team participation info. Work in progress.
34
35
13970.7.4 by William Grant
check-teamparticipation is now a LaunchpadScript.
36
class CheckTeamParticipationScript(LaunchpadScript):
37
    description = "Check for invalid/missing TeamParticipation entries."
38
14213.4.26 by Gavin Panella
Enable loading and saving of team participation info. Work in progress.
39
    def add_my_options(self):
40
        self.parser.add_option(
41
            "--load-participation-info",
14213.4.34 by Gavin Panella
Don't check consistency when a save has been requested.
42
            dest="load_info", metavar="FILE", help=(
14213.4.26 by Gavin Panella
Enable loading and saving of team participation info. Work in progress.
43
                "File from which to load participation information "
44
                "instead of going to the database."))
45
        self.parser.add_option(
46
            "--save-participation-info",
14213.4.34 by Gavin Panella
Don't check consistency when a save has been requested.
47
            dest="save_info", metavar="FILE", help=(
14213.4.26 by Gavin Panella
Enable loading and saving of team participation info. Work in progress.
48
                "File in which to save participation information, for "
49
                "later processing with --load-participation-info."))
50
13970.7.4 by William Grant
check-teamparticipation is now a LaunchpadScript.
51
    def main(self):
14213.4.26 by Gavin Panella
Enable loading and saving of team participation info. Work in progress.
52
        """Perform various checks on the `TeamParticipation` table."""
14213.4.34 by Gavin Panella
Don't check consistency when a save has been requested.
53
        if self.options.load_info:
54
            participation_info = load_bz2_pickle(self.options.load_info)
14213.4.26 by Gavin Panella
Enable loading and saving of team participation info. Work in progress.
55
        else:
14213.4.38 by Gavin Panella
When --load-participation-info is used, don't run the self and circular checks.
56
            check_teamparticipation_circular(self.logger)
14213.4.26 by Gavin Panella
Enable loading and saving of team participation info. Work in progress.
57
            participation_info = fetch_team_participation_info(self.logger)
14213.4.34 by Gavin Panella
Don't check consistency when a save has been requested.
58
        if self.options.save_info:
59
            save_bz2_pickle(participation_info, self.options.save_info)
60
        else:
14464.1.7 by Gavin Panella
Fix team participations by default.
61
            errors = check_teamparticipation_consistency(
14213.4.34 by Gavin Panella
Don't check consistency when a save has been requested.
62
                self.logger, participation_info)
14464.1.7 by Gavin Panella
Fix team participations by default.
63
            fix_teamparticipation_consistency(self.logger, errors)
13970.7.4 by William Grant
check-teamparticipation is now a LaunchpadScript.
64
14213.4.2 by Gavin Panella
Move check_teamparticipation() into sys.path.
65
13970.7.4 by William Grant
check-teamparticipation is now a LaunchpadScript.
66
if __name__ == '__main__':
67
    CheckTeamParticipationScript("check-teamparticipation").run()