~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.22 by Karl Fogel
Add the copyright header block to the remaining .py files.
2
#
14538.1.6 by Curtis Hovey
Fixed script imports.
3
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.22 by Karl Fogel
Add the copyright header block to the remaining .py files.
4
# GNU Affero General Public License version 3 (see the file LICENSE).
4962.6.4 by Guilherme Salgado
Add a script to convert people into teams.
5
6
"""Script to convert a person into a team.
7
8
Only people whose account_status is NOACCOUNT can be turned into teams.
9
"""
10
11
12
import _pythonpath
13
14
from zope.component import getUtility
15
14538.1.6 by Curtis Hovey
Fixed script imports.
16
from lp.registry.interfaces.person import IPersonSet
8356.1.9 by Leonard Richardson
Renamed the base script module in scripts/, which module_rename.py didn't touch because it wasn't under lib/.
17
from lp.services.scripts.base import (
4962.6.4 by Guilherme Salgado
Add a script to convert people into teams.
18
    LaunchpadScript, LaunchpadScriptFailure)
14538.1.6 by Curtis Hovey
Fixed script imports.
19
from lp.services.identity.interfaces.account import AccountStatus
4962.6.4 by Guilherme Salgado
Add a script to convert people into teams.
20
21
22
class ConvertPersonToTeamScript(LaunchpadScript):
23
24
    usage = '%prog <person-to-convert> <team-owner>'
25
26
    def main(self):
27
        if len(self.args) != 2:
28
            raise LaunchpadScriptFailure(
29
                "You must specify the name of the person to be converted "
4962.6.8 by Guilherme Salgado
Some changes suggested by Michael
30
                "and the person/team who should be its teamowner.")
4962.6.4 by Guilherme Salgado
Add a script to convert people into teams.
31
32
        person_set = getUtility(IPersonSet)
33
        person_name, owner_name = self.args
34
        person = person_set.getByName(person_name)
4962.6.8 by Guilherme Salgado
Some changes suggested by Michael
35
        if person is None:
36
            raise LaunchpadScriptFailure(
37
                "There's no person named '%s'." % person_name)
4962.6.4 by Guilherme Salgado
Add a script to convert people into teams.
38
        if person.account_status != AccountStatus.NOACCOUNT:
39
            raise LaunchpadScriptFailure(
40
                "Only people which have no account can be turned into teams.")
4962.6.8 by Guilherme Salgado
Some changes suggested by Michael
41
        owner = person_set.getByName(owner_name)
42
        if owner is None:
43
            raise LaunchpadScriptFailure(
44
                "There's no person named '%s'." % owner_name)
4962.6.4 by Guilherme Salgado
Add a script to convert people into teams.
45
46
        person.convertToTeam(owner)
47
        self.txn.commit()
48
49
50
if __name__ == '__main__':
51
    script = ConvertPersonToTeamScript('convert-person-to-team')
52
    script.lock_and_run()