1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#!/usr/bin/env python
import sys
from argparse import ArgumentParser
from launchpad import LaunchpadTrigger
from settings import LOCK_FILE, logger
from lockfile import FileLock
def getMergeCount(branch, merge_type):
"""Returns the total number of outstanding merge requests for the given
type."""
count = 0
launchpad_trigger = LaunchpadTrigger()
for b in branch:
mps = launchpad_trigger.get_merge_proposals(b, [merge_type])
logger.debug("[%s] merge proposals: %s" % (b, mps))
logger.debug("count: %d" % (len(mps)))
count += len(mps)
return count
def main():
parser = ArgumentParser(description="Return count of outstanding merge "
"proposals.")
parser.add_argument("-t", "--merge_type", default="Approved",
help="Count only this type of merge proposals.")
parser.add_argument("branch", nargs="+",
help="Branch to check merge count.")
args = vars(parser.parse_args())
return getMergeCount(**args)
if __name__ == "__main__":
# this is here because launchpadlib is not thread safe (yet)
# see also lp:459418 and lp:1025153
logger.debug("Going to acquire launchpad lock for %s" % (sys.argv[0]))
with FileLock(LOCK_FILE):
logger.debug('Lock acquired for %s' % (sys.argv[0]))
sys.exit(main())
|