import repository from arizona
[raven.git] / testscripts / scott / pacmanactive / activecomon.groups.pacman
1 #!/usr/bin/python
2
3 import urllib2
4 import string
5 import sys
6
7 def comon(query):
8         
9         #   Formats the URL   #
10         ii = 0
11         commaNeeded = 0
12
13
14         if(query.find("'") == -1):
15                 #Finds select= and adds a ' after the =
16                 while (commaNeeded != 1 and ii < len(query)-6): 
17                         if (query[ii:ii+7] == 'select='):
18                                 query = query[0:ii+7]+"'"+query[ii+7:] 
19                                 commaNeeded = 1
20                         ii += 1
21
22                 #If there is an option after select= 
23                 while(commaNeeded and ii < len(query)-1):
24                         if (query[ii] == '&' and query[ii+1] != '&' and query[ii-1] != '&'): #If we need to add a comma, look for a single &
25                                 query = query[0:ii+1]+"'"+query[ii+1:0]
26                                 commaNeeded = 0
27                         ii += 1
28
29                 #Adds ' to the end if there are no other options after select=
30                 while(commaNeeded):
31                         query = query+"'"
32                         commaNeeded = 0
33
34                 # Replaces spaces with '%20' #
35                 query = query.replace(" ", "%20")
36
37         
38         ii = 0
39         output = ""
40         url1 = 'http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=nameonly&'
41         url2 = query
42         url = url1 + url2
43         f = urllib2.urlopen(url)
44         s = f.read()
45         f.close()
46         
47         while ((s[0:11] == "query error") and (s[ii:ii+3] != "<p>")):
48                 output += s[ii]
49                 ii += 1
50         if(ii != 0):
51                 print output
52                 sys.exit(1)
53
54         return s
55
56 args = sys.argv
57
58 lowslices = comon("select='liveslices<10'").split("\n")
59 highslices = comon("select='liveslices>=10'").split("\n")
60
61 if args[2] in lowslices:
62     print "lowslices"
63
64 if args[2] in highslices:
65     print "highslices"
66
67 if (not (args[2] in lowslices)) and (not (args[2] in highslices)):
68     print "unknownslices"
69