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 |
14612.2.7
by William Grant
scripts |
17 |
from lp.services.identity.interfaces.account import AccountStatus |
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/. |
18 |
from lp.services.scripts.base import ( |
14612.2.7
by William Grant
scripts |
19 |
LaunchpadScript, |
20 |
LaunchpadScriptFailure, |
|
21 |
)
|
|
4962.6.4
by Guilherme Salgado
Add a script to convert people into teams. |
22 |
|
23 |
||
24 |
class ConvertPersonToTeamScript(LaunchpadScript): |
|
25 |
||
26 |
usage = '%prog <person-to-convert> <team-owner>' |
|
27 |
||
28 |
def main(self): |
|
29 |
if len(self.args) != 2: |
|
30 |
raise LaunchpadScriptFailure( |
|
31 |
"You must specify the name of the person to be converted "
|
|
4962.6.8
by Guilherme Salgado
Some changes suggested by Michael |
32 |
"and the person/team who should be its teamowner.") |
4962.6.4
by Guilherme Salgado
Add a script to convert people into teams. |
33 |
|
34 |
person_set = getUtility(IPersonSet) |
|
35 |
person_name, owner_name = self.args |
|
36 |
person = person_set.getByName(person_name) |
|
4962.6.8
by Guilherme Salgado
Some changes suggested by Michael |
37 |
if person is None: |
38 |
raise LaunchpadScriptFailure( |
|
39 |
"There's no person named '%s'." % person_name) |
|
4962.6.4
by Guilherme Salgado
Add a script to convert people into teams. |
40 |
if person.account_status != AccountStatus.NOACCOUNT: |
41 |
raise LaunchpadScriptFailure( |
|
42 |
"Only people which have no account can be turned into teams.") |
|
4962.6.8
by Guilherme Salgado
Some changes suggested by Michael |
43 |
owner = person_set.getByName(owner_name) |
44 |
if owner is None: |
|
45 |
raise LaunchpadScriptFailure( |
|
46 |
"There's no person named '%s'." % owner_name) |
|
4962.6.4
by Guilherme Salgado
Add a script to convert people into teams. |
47 |
|
48 |
person.convertToTeam(owner) |
|
49 |
self.txn.commit() |
|
50 |
||
51 |
||
52 |
if __name__ == '__main__': |
|
53 |
script = ConvertPersonToTeamScript('convert-person-to-team') |
|
54 |
script.lock_and_run() |