~ubuntu-reviewers/ubuntu-review-overview/trunk

14.1.2 by Daniel Holbach
add countdown script
1
#!/usr/bin/python
2
3
import Image
4
import sys
5
import os
6
7
import data
8
27 by Daniel Holbach
use global write_file function, don't write .css, write .js instead, merge images, css and lots of other great stuff from lp:~adnane002/+junk/ubuntu-reviews
9
def write_js(reviewed, total):
10
    percent = str(reviewed*100/total)+"%"
11
    js_text ="""/* Ubuntu Reviews Gadget */
29 by Daniel Holbach
hardcode paths
12
var gadget =\'<link rel="stylesheet" href="http://daniel.holba.ch/review/default.css" type="text/css" media="screen">\'+
27 by Daniel Holbach
use global write_file function, don't write .css, write .js instead, merge images, css and lots of other great stuff from lp:~adnane002/+junk/ubuntu-reviews
13
\'<div id="badge">\'+
14
\'<div id="ubuntu-reviewers-logo"></div>\'+
15
\'<div id="ubuntu-logo"></div>\'+
16
\'<div id="progress-bar"><div id="bar" style="width:%s">%s</div></div>\'+
17
\'<div id="percentage">%s</div>\'+
34 by Daniel Holbach
change link to operation cleansweep
18
\'<div id="ubuntu-review-team"><img src="http://daniel.holba.ch/review/images/3.png"><a href="https://wiki.ubuntu.com/OperationCleansweep" target="_blank">Help review patches in Ubuntu!</a></div>\'+
27 by Daniel Holbach
use global write_file function, don't write .css, write .js instead, merge images, css and lots of other great stuff from lp:~adnane002/+junk/ubuntu-reviews
19
\'</div>\';
20
document.write(gadget);
21
""" % (percent, percent, percent)
22
    js_file = os.path.join(data.data_dir(), "gadget.js")
23
    data.write_file(js_file, js_text)
25 by Daniel Holbach
add 'review/' directory, move all public data there. write .css file, add example.html
24
23 by Daniel Holbach
paint horizontal meter too
25
def draw(reviewed, total, horizontal=False):
26
    if horizontal:
27
        size = [200, 20]
25 by Daniel Holbach
add 'review/' directory, move all public data there. write .css file, add example.html
28
        x_range = [1, reviewed*size[0]/total]
23 by Daniel Holbach
paint horizontal meter too
29
        y_range = [1, size[1]]
30
        meterfile = "meter.horiz.png"
31
    else:
32
        meterfile = "meter.png"
33
        size = [20, 200]
34
        x_range = [1, size[0]]
25 by Daniel Holbach
add 'review/' directory, move all public data there. write .css file, add example.html
35
        y_range = [size[1]-reviewed*size[1]/total, size[1]]
23 by Daniel Holbach
paint horizontal meter too
36
    im = Image.new("RGB", (size[0], size[1]))
37
    for x in range(x_range[0], x_range[1]):
38
        for y in range(y_range[0], y_range[1]):
39
            im.putpixel((x,y), (255,0,0))
25 by Daniel Holbach
add 'review/' directory, move all public data there. write .css file, add example.html
40
    im.save(os.path.join(data.data_dir(), meterfile))
23 by Daniel Holbach
paint horizontal meter too
41
14.1.2 by Daniel Holbach
add countdown script
42
def main():
43
    launchpad = data.lp_login()
25 by Daniel Holbach
add 'review/' directory, move all public data there. write .css file, add example.html
44
    datadir = data.data_dir()
14.1.2 by Daniel Holbach
add countdown script
45
    ubuntu = launchpad.distributions['ubuntu']
30 by Nigel Babu
Change the stats for reviewed bugs
46
    ur = launchpad.people['ubuntu-reviewers']
31 by Nigel Babu
Correct total of patches too
47
    total_patches = data.get_count(ubuntu.searchTasks(has_patch=True, status=data.open_status,bug_subscriber=ur))
14.1.2 by Daniel Holbach
add countdown script
48
    already_reviewed_patches = data.get_count(ubuntu.searchTasks(has_patch=True, 
49
                                status=data.open_status, 
30 by Nigel Babu
Change the stats for reviewed bugs
50
                                bug_subscriber=ur,
14.1.2 by Daniel Holbach
add countdown script
51
                                tags=data.reviewed_tags,
52
                                tags_combinator='Any'))
21.1.3 by Daniel Holbach
also write out file with the length of the queue
53
    print "Total: %s" % total_patches
54
    print "Already reviewed: %s" % already_reviewed_patches
55
    print "In the queue: %s" % (total_patches-already_reviewed_patches)
23 by Daniel Holbach
paint horizontal meter too
56
    draw(already_reviewed_patches, total_patches, False) 
57
    draw(already_reviewed_patches, total_patches, True)
27 by Daniel Holbach
use global write_file function, don't write .css, write .js instead, merge images, css and lots of other great stuff from lp:~adnane002/+junk/ubuntu-reviews
58
    data.write_file(os.path.join(datadir, "in-the-queue.txt"), 
59
                    str(total_patches-already_reviewed_patches))
60
    data.write_file(os.path.join(datadir, "total.txt"), 
61
                    str(total_patches))
62
    write_js(already_reviewed_patches, total_patches)
14.1.2 by Daniel Holbach
add countdown script
63
64
if __name__ == "__main__":
27 by Daniel Holbach
use global write_file function, don't write .css, write .js instead, merge images, css and lots of other great stuff from lp:~adnane002/+junk/ubuntu-reviews
65
    sys.exit(main())
14.1.2 by Daniel Holbach
add countdown script
66
    try:
67
        sys.exit(main())
68
    except Exception, e:
69
        print "%s: %s" %(e.__class__.__name__, e)
70
        sys.exit(1)
71