~jdong/prevu/jdong-dev

« back to all changes in this revision

Viewing changes to lprevu

  • Committer: John Dong
  • Date: 2007-01-03 19:35:47 UTC
  • Revision ID: john.dong@gmail.com-20070103193547-o0tzm0xhva46hx25
Made lprevu, an automatic launchpad prevu evaluator. Helps me prevent building then forgetting that I built a package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# Launchpad prevu wrapper
 
3
# USAGE: lprevu <bugno/bugurl> <package>
 
4
 
 
5
SOURCE_EMAIL="john.dong@gmail.com"  # Change me. Must be a LP registered e-mail account
 
6
 
 
7
 
 
8
##################################
 
9
import sys
 
10
import os
 
11
import cStringIO
 
12
 
 
13
 
 
14
def strcat(l):
 
15
    buf=cStringIO.StringIO()
 
16
    for line in l: buf.write(line)
 
17
    return buf.getvalue()
 
18
def findbuilt(l):
 
19
    pkglines=[]
 
20
    for line in l:
 
21
        if line.startswith('-> Built Package'):
 
22
            pkglines.append(line)
 
23
    return strcat(pkglines)
 
24
 
 
25
def parse_url(url):
 
26
    # Turns a Launchpad URL into a bug number
 
27
    for token in url.split('/'):
 
28
        try:
 
29
            if int(token) > 0: return token
 
30
        except ValueError: pass
 
31
    raise ValueError, "Couldn't detect launchpad bug number from: ".join(url)
 
32
 
 
33
def mail(dst,txt):
 
34
    global SOURCE_EMAIL
 
35
    p=os.popen('sendmail -t', 'w')
 
36
    p.write('To: %s\n' % dst)
 
37
    p.write('From: %s\n' % SOURCE_EMAIL)
 
38
    p.write('Subject:\n')
 
39
    p.write('\n')
 
40
    p.write(txt+"\n")
 
41
    st=p.close()
 
42
    if st:
 
43
        print "WARNING: sendmail unsuccessful!"
 
44
    else:
 
45
        print "Sent msg:",txt
 
46
 
 
47
def do_build(bugno,pkg):
 
48
    lines=[]
 
49
    mail("%s@bugs.launchpad.net" % bugno,
 
50
    """
 
51
This is an automated build message from my prevu client.\nBUILD STARTED.\n A build of package '%s' has been started. Upon the build finishing, another notification   will be sent out with the results.
 
52
""" % pkg)
 
53
    p=os.popen('TERM=linux prevu %s 2>&1' % pkg,'r')
 
54
    line=p.readline()
 
55
    while line:
 
56
        lines+=[line]
 
57
        print line,
 
58
        line=p.readline()
 
59
    retcode=p.close()
 
60
    if retcode:
 
61
        #Build failed.
 
62
        mail("%s@bugs.launchpad.net" % bugno,
 
63
    """
 
64
This is an automated build message from my prevu client.\nBUILD FAILED.\n Unfortunately, the build has failed. Here's the last 20 lines:
 
65
%s
 
66
...
 
67
%s
 
68
 
 
69
""" % (lines[0],strcat(lines[-25:-5])) )
 
70
    else:
 
71
        mail("%s@bugs.launchpad.net" % bugno,
 
72
    """
 
73
This is an automated build message from my prevu client.\nBUILD SUCCESS.\n The build has succeeded. A Backports developer will manually test the package to ensure it runs properly.
 
74
Built packages:
 
75
%s
 
76
""" % findbuilt(lines) )
 
77
 
 
78
 
 
79
bugno=parse_url(sys.argv[1])
 
80
pkg=sys.argv[2]
 
81
 
 
82
do_build(bugno,pkg)