~launchpad-pqm/launchpad/devel

7109.3.2 by Jonathan Lange
Docstrings and coding standard compliance.
1
#!/usr/bin/python2.4
8687.15.22 by Karl Fogel
Add the copyright header block to the remaining .py 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
7109.3.10 by Jonathan Lange
Disable lint.
6
# pylint: disable-msg=W0403
7109.3.2 by Jonathan Lange
Docstrings and coding standard compliance.
7
8
"""List the stacked branches in Launchpad.
9
10
Usage: ./get-stacked-on-branches.py
11
12
Prints the stacked branches in Launchpad to standard output in the following
13
format:
14
  <id> <branch_type> <unique_name> <stacked_on_unique_name>
15
16
<id> is the database ID of the Branch as a decimal integer.
17
<branch_type> is the name of the BranchType, e.g. 'HOSTED'.
18
<unique_name> is the unique_name property of the Branch.
19
<stacked_on_unique_name> is the unique_name property of the Branch.stacked_on
20
    branch.
21
22
This script is intended to be used in conjunction with "update-stacked-on.py".
23
"""
24
25
__metaclass__ = type
26
7109.3.1 by Jonathan Lange
Initial version of stacking update scripts.
27
import _pythonpath
28
29
from storm.locals import Not
30
from zope.component import getUtility
31
32
from canonical.launchpad.scripts import execute_zcml_for_scripts
33
from canonical.launchpad.webapp.interfaces import (
34
    IStoreSelector, MAIN_STORE, SLAVE_FLAVOR)
35
36
37
def get_stacked_branches():
7109.3.2 by Jonathan Lange
Docstrings and coding standard compliance.
38
    """Iterate over all branches that, according to the db, are stacked."""
8486.12.1 by Celso Providelo
Fixing the 'fixable' scripts and adding a checker with the really-broken ones blacklisted.
39
    # Avoiding circular import.
40
    from lp.code.model.branch import Branch
7109.3.1 by Jonathan Lange
Initial version of stacking update scripts.
41
    store = getUtility(IStoreSelector).get(MAIN_STORE, SLAVE_FLAVOR)
42
    return store.find(Branch, Not(Branch.stacked_on == None))
43
44
45
def main():
7109.3.2 by Jonathan Lange
Docstrings and coding standard compliance.
46
    """Print all stacked branches from the database.
47
48
    See the module docstring for more information.
49
    """
7109.3.1 by Jonathan Lange
Initial version of stacking update scripts.
50
    execute_zcml_for_scripts()
51
    for db_branch in get_stacked_branches():
52
        print '%s %s %s %s' % (
53
            db_branch.id, db_branch.branch_type.name, db_branch.unique_name,
54
            db_branch.stacked_on.unique_name)
55
56
57
if __name__ == '__main__':
58
    main()