Ubuntu-Netbook-Remix
Attachment 'case-count.py'
Download 1 #!/usr/bin/env python
2 """
3 Site-scraping script
4 """
5
6 nameList = []
7
8 import urllib
9 import re
10 import sys
11
12 def help():
13 print "Usage: python case-count.py [-s|<qa account>]"
14
15 def parse_subscriptions(name, test_subs):
16 output = ""
17 if test_subs.has_key(name):
18 output += "\nTest Case Subscriptions for %s:\n\n" % (name)
19 for test_case in test_subs[name]:
20 output += " %s\n" % (test_case)
21 else:
22 output += " None\n"
23
24 return output
25
26 #RED = "#E47A7A"
27 #ORANGE = "#FFDB80"
28 #GREEN = "#CCFFCC"
29
30 wiki = urllib.urlopen("https://wiki.canonical.com/DistroTeam/HardyIsoTesting?action=raw")
31 content = wiki.read()
32 wiki.close()
33
34 reg_exp = "\|\|.*(\[.*?\]).*\|\|.*<(\S*)>.*\|\|(.*)\|\|(.*)\|\|(.*)\|\|"
35 metric = re.findall(reg_exp, content)
36
37 for row in metric:
38 nameList.append(row[2].strip())
39
40 sock = urllib.urlopen("http://iso.qa.ubuntu.com/qatracker/subscriptions")
41 htmlSource = sock.read()
42 sock.close()
43
44 reg_exp = "<a href=\"/qatracker/build.*?>(.*?)</a>(.*?)</table>"
45 subscriptions = re.findall(reg_exp, htmlSource)
46
47 test_subscriptions = {}
48
49 for section in subscriptions:
50 reg_exp = "<tr><td.*?>(.*?)</td><td.*?>(.*?)</td></tr>"
51 flavors = re.findall(reg_exp, section[1])
52 for flavor in flavors:
53 subscribers = flavor[1].replace("<b>", "")
54 subscribers = subscribers.replace("</b>", "")
55 subscribers = subscribers.split(", ")
56 for name in subscribers:
57 if not test_subscriptions.has_key(name):
58 test_subscriptions[name] = []
59 test_subscriptions[name].append(section[0] + ": " + flavor[0])
60
61 index = 0
62 subs_output = ""
63 wiki_output = ""
64
65 if len(sys.argv) > 1 and sys.argv[1] != "-s":
66 subs_output += parse_subscriptions(sys.argv[1], test_subscriptions)
67 print subs_output
68 sys.exit(1)
69
70 for name in nameList:
71 subs_output += parse_subscriptions(name, test_subscriptions)
72 caseCount = htmlSource.count(name)
73 color = metric[index][1]
74
75 if metric[index][3].strip():
76 archs = metric[index][3].strip()
77 else:
78 archs = "i386"
79
80 wiki_output += "|| %s ||<%s> %d || %s || %s || %s ||\n" % (metric[index][0], color, caseCount, name, archs,metric[index][4].strip())
81 index += 1
82
83 if len(sys.argv) == 1:
84 print wiki_output
85 elif sys.argv[1] == "-s":
86 print subs_output
87 else:
88 print help()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.