annotate smartopen/handlers.py @ 14:a62fbff067f8

start bringing this whole thing up to speed
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 01 May 2013 06:56:12 -0700
parents f11ce7b1a349
children 1281d999618c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
1 import address
10
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
2 import string
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
3 import urllib
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
4 import urllib2
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
5 from subprocess import call
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
6
11
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
7 class Location(object):
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
8 """
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
9 generic class for locations
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
10 """
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
11
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
12 def __init__(self, baseurl=""):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
13 self.baseurl = baseurl
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
14 # should/could strip here?
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
15
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
16 def url(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
17 return self.baseurl + self.process(query)
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
18
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
19 def process(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
20 return query
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
21
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
22 def test(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
23 return True
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
24
11
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
25 def exists(self, URL):
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
26 """does a URL exist?"""
12
bb995bdf82e2 annoyingly work around user agents again; i hate robot protection sometimes
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
27 # need a phony user agent so wikipedia won't know we're a bot
bb995bdf82e2 annoyingly work around user agents again; i hate robot protection sometimes
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
28 headers = {}
bb995bdf82e2 annoyingly work around user agents again; i hate robot protection sometimes
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
29 headers['User-Agent'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4'
bb995bdf82e2 annoyingly work around user agents again; i hate robot protection sometimes
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
30
bb995bdf82e2 annoyingly work around user agents again; i hate robot protection sometimes
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
31 request = urllib2.Request(URL, None, headers)
11
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
32 try:
12
bb995bdf82e2 annoyingly work around user agents again; i hate robot protection sometimes
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
33 f = urllib2.urlopen(request).read()
11
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
34 return True
12
bb995bdf82e2 annoyingly work around user agents again; i hate robot protection sometimes
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
35 except urllib2.HTTPError, e:
bb995bdf82e2 annoyingly work around user agents again; i hate robot protection sometimes
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
36 return False
bb995bdf82e2 annoyingly work around user agents again; i hate robot protection sometimes
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
37 except urllib2.URLError, e:
11
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
38 return False
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
39
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
40 class URL(Location):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
41 """a straight URL"""
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
42
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
43 def process(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
44 if '://' in query:
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
45 return query
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
46 return 'http://' + query
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
47
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
48 def test(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
49 """try to open the url"""
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
50 if ' ' in query or '\n' in query:
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
51 return False
11
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
52 return self.exists(self.process(query))
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
53
1
10fc4904c10f now can pass data
k0s <k0scist@gmail.com>
parents: 0
diff changeset
54 class GoogleMaps(Location):
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
55 """try to google-maps the address"""
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
56
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
57 def __init__(self):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
58 gmapsurl='http://maps.google.com/maps?f=q&hl=en&q='
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
59 Location.__init__(self, gmapsurl)
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
60
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
61 def process(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
62 theaddress = address.normalizeaddress(query)
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
63 if not theaddress:
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
64 return theaddress
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
65 return urllib.quote_plus(theaddress)
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
66
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
67 def test(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
68 return bool(self.process(query))
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
69
1
10fc4904c10f now can pass data
k0s <k0scist@gmail.com>
parents: 0
diff changeset
70 class Trac(Location):
2
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
71 def __init__(self, baseurl):
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
72 baseurl = baseurl.strip('/') + '/'
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
73 Location.__init__(self, baseurl)
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
74
2
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
75 def process(self, query):
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
76 if query[0] == 'r':
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
77 if query[1:].isdigit():
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
78 return 'changeset/' + str(query[1:])
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
79 if query[0] == '#':
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
80 if query[1:].isdigit():
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
81 return 'ticket/' + str(query[1:])
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
82
2
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
83 def test(self, query):
f084e152dd47 add Trac handler
k0s <k0scist@gmail.com>
parents: 1
diff changeset
84 return bool(self.process(query))
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
85
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
86
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
87 class Wikipedia(Location):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
88 """try to open the query in wikipedia"""
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
89 def __init__(self):
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
90 wikiurl = 'http://en.wikipedia.org/wiki/'
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
91 Location.__init__(self, wikiurl)
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
92
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
93 def process(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
94 return urllib.quote_plus('_'.join(query.split()))
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
95
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
96 def test(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
97 'test to see if the article exists'
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
98
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
99 # need a phony user agent so wikipedia won't know we're a bot
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
100 headers = {}
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
101 headers['User-Agent'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4'
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
102
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
103 request = urllib2.Request(self.url(query), None, headers)
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
104 try:
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
105 f = urllib2.urlopen(request).read()
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
106 except urllib2.HTTPError, e:
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
107 return False
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
108
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
109 if 'Wikipedia does not have an article with this exact name' in f:
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
110 return False
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
111 return True
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
112
11
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
113 class Wiktionary(Location):
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
114 def __init__(self):
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
115 baseurl = 'http://en.wiktionary.org/wiki/'
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
116 Location.__init__(self, baseurl)
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
117 def test(self, query):
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
118 for c in (' ', '\n', '/'):
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
119 if c in query:
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
120 return False
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
121 if self.exists(self.url(query)):
ba9058605c5a add a wiktionary handler
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
122 return True
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
123
7
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
124 class Bugzilla(Location):
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
125 def __init__(self):
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
126 baseurl = 'https://bugzilla.mozilla.org/show_bug.cgi?id='
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
127 Location.__init__(self, baseurl)
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
128
7
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
129 def test(self, query):
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
130 try:
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
131 int(query)
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
132 return True
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
133 except:
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
134 return False
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
135
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
136 class Google(Location):
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
137 def __init__(self):
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
138 googleurl = 'http://www.google.com/search?hl=en&q='
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
139 Location.__init__(self, googleurl)
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
140
0
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
141 def process(self, query):
d6fa501af82f initial commit of smartopen
k0s <k0scist@gmail.com>
parents:
diff changeset
142 return urllib.quote_plus(query)
7
d5343f681ef9 add bugzilla handler
Jeff Hammel <k0scist@gmail.com>
parents: 2
diff changeset
143
8
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
144 class FedEx(Location):
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
145 def __init__(self):
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
146 baseurl = 'http://www.fedex.com/Tracking?cntry_code=us&language=english&tracknumber_list='
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
147 Location.__init__(self, baseurl)
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
148
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
149 def process(self, query):
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
150 if query.count(' ') == 2:
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
151 query = ''.join(query.split(' '))
8
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
152 return query
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
153
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
154 def test(self, query):
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
155 query = self.process(query)
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
156 if len(query) != 12:
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
157 return False
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
158 try:
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
159 int(query)
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
160 except ValueError:
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
161 return False
44950f376e98 add FedEx tracking number handler
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
162 return True
10
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
163
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
164 class MercurialRevision(Location):
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
165 def __init__(self):
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
166 baseurl = 'http://hg.mozilla.org/mozilla-central/rev/'
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
167 Location.__init__(self, baseurl)
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
168
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
169 def test(self, query):
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
170 query = set(query)
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
171 if query.issubset(string.digits + 'abcdef'):
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
172 return True
a963acb1713d add a new handler: MercurialRevision
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
173 return False
13
f11ce7b1a349 note to self
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
174
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
175 class UbuntuPackage(Location):
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
176 def __init__(self):
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
177 baseurl = 'http://packages.ubuntu.com/'
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
178 Location.__init__(self, baseurl)
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
179
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
180 def test(self, query):
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
181 if len(self.baseurl.strip().split()) > 1:
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
182 return False # no spaces in packages
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
183
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
184 # use `apt-cache show` for the package name
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
185 # the output could be captured:, e.g.
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
186 # ...
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
187 # Filename: pool/main/h/hello/hello_2.8-2_amd64.deb
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
188 # Size: 28124
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
189 # MD5sum: 73ad59a7920e2adcff9b84c00e38418a
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
190 # SHA1: 70ef927cfa40b8e367f9ca7821e0064a946726c5
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
191 # SHA256: f8341711f6b803e032be9aff2206dfdb4045a0c6c296b0ea0d310d415f10ff4d
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
192 # Description-en: The classic greeting, and a good example
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
193 # The GNU hello program produces a familiar, friendly greeting. It
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
194 # allows non-programmers to use a classic computer science tool which
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
195 # would otherwise be unavailable to them.
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
196 # .
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
197 # Seriously, though: this is an example of how to do a Debian package.
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
198 # It is the Debian version of the GNU Project's `hello world' program
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
199 # (which is itself an example for the GNU Project).
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
200 # Homepage: http://www.gnu.org/software/hello/
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
201 # Description-md5: b7df6fe7ffb325083a3a60819a7df548
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
202 # Bugs: https://bugs.launchpad.net/ubuntu/+filebug
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
203 # Origin: Ubuntu
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
204 # Supported: 18m
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
205
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
206 # in theory both the home page and the ubuntu page could be interesting
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
207 # (different handlers?)
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
208
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
209 returncode = call(['apt-cache', 'show', self.baseurl])
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
210 if returncode:
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
211 return False
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
212
13
f11ce7b1a349 note to self
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
213 # TODO:
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
214 # - https://mozillians.org/en-US/u/jhammel/ handler
13
f11ce7b1a349 note to self
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
215 # - https://mozillians.org/en-US/u/williamr/ handler
14
a62fbff067f8 start bringing this whole thing up to speed
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
216 # ... but no 404???