~launchpad-pqm/launchpad/devel

11134.1.1 by Steve Kowalik
Add a new script that checks the status of the local versus remote branches and tells the state of any linked MPs.
1
#!/usr/bin/python
2
3
import commands
4
import os
5
import sys
6
14612.2.6 by William Grant
utilities
7
from bzrlib import (
8
    branch,
9
    errors,
10
    )
11
from launchpadlib.launchpad import Launchpad
12
13
11677.3.3 by Robert Collins
More edge removal.
14
launchpad = Launchpad.login_with('rocketfuel-mp-status', 'production')
11134.1.1 by Steve Kowalik
Add a new script that checks the status of the local versus remote branches and tells the state of any linked MPs.
15
trunk = commands.getoutput(
16
    '. ~/.rocketfuel-env.sh && echo $LP_TRUNK_NAME')
17
projpath = commands.getoutput(
18
    '. ~/.rocketfuel-env.sh && echo $LP_PROJECT_PATH')
11551.1.2 by Steve Kowalik
* Allow users to specify multiple branches to check, thanks Edwin
19
if len(sys.argv) > 1:
20
    branches = sys.argv[1:]
11551.1.3 by Steve Kowalik
Don't chdir if we specify which branches
21
else:
22
    os.chdir(projpath)
23
    branches = os.listdir('.')
11134.1.2 by Steve Kowalik
Remove a large number of egregious underscores
24
lp_branches = launchpad.branches
11134.1.1 by Steve Kowalik
Add a new script that checks the status of the local versus remote branches and tells the state of any linked MPs.
25
26
for lb in branches:
27
    if lb == trunk:
28
        continue
29
    try:
13744.1.1 by Steve Kowalik
Improve freshness messages and fix one bit of lint.
30
        _branch = branch.Branch.open(lb)
11134.1.1 by Steve Kowalik
Add a new script that checks the status of the local versus remote branches and tells the state of any linked MPs.
31
    except errors.NotBranchError:
32
        continue
33
    print ' * %s' % lb
11134.1.2 by Steve Kowalik
Remove a large number of egregious underscores
34
    rem_branch_url = _branch.get_public_branch()
11134.1.1 by Steve Kowalik
Add a new script that checks the status of the local versus remote branches and tells the state of any linked MPs.
35
    try:
11134.1.2 by Steve Kowalik
Remove a large number of egregious underscores
36
        rem_branch = branch.Branch.open(rem_branch_url)
11134.1.1 by Steve Kowalik
Add a new script that checks the status of the local versus remote branches and tells the state of any linked MPs.
37
    except errors.NotBranchError:
38
        print '   - Remote branch does not exist'
39
        continue
13744.1.1 by Steve Kowalik
Improve freshness messages and fix one bit of lint.
40
    if _branch.revno() == rem_branch.revno():
41
        print '   - Remote branch is up to date'
42
    elif _branch.revno() > rem_branch.revno():
11134.1.1 by Steve Kowalik
Add a new script that checks the status of the local versus remote branches and tells the state of any linked MPs.
43
        print '   - Remote branch is missing revisions'
13744.1.1 by Steve Kowalik
Improve freshness messages and fix one bit of lint.
44
    elif _branch.revno() < rem_branch.revno():
45
        print '   - Local branch is missing revisions'
11134.1.2 by Steve Kowalik
Remove a large number of egregious underscores
46
    remote = lp_branches.getByUrl(url = rem_branch_url)
47
    mps = remote.landing_targets
48
    for mp in mps:
11134.1.1 by Steve Kowalik
Add a new script that checks the status of the local versus remote branches and tells the state of any linked MPs.
49
        print '   - MP: %s' % mp.queue_status
50