changeset 15:1281d999618c

yep
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 01 May 2013 08:06:50 -0700
parents a62fbff067f8
children 12db2d46722d
files smartopen/handlers.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/smartopen/handlers.py	Wed May 01 06:56:12 2013 -0700
+++ b/smartopen/handlers.py	Wed May 01 08:06:50 2013 -0700
@@ -1,8 +1,12 @@
+"""
+handlers for smartopen
+"""
+
 import address
 import string
+import subprocess
 import urllib
 import urllib2
-from subprocess import call
 
 class Location(object):
     """
@@ -14,12 +18,15 @@
         # should/could strip here?
 
     def url(self, query):
+        """the URL to construct"""
         return self.baseurl + self.process(query)
 
     def process(self, query):
-        return query
+        """how to process the query"""
+        return query.strip()
 
     def test(self, query):
+        """whether the handler matches"""
         return True
 
     def exists(self, URL):
@@ -173,12 +180,13 @@
         return False
 
 class UbuntuPackage(Location):
+    # Note: only works where apt-cache is available
     def __init__(self):
         baseurl = 'http://packages.ubuntu.com/'
         Location.__init__(self, baseurl)
 
     def test(self, query):
-        if len(self.baseurl.strip().split()) > 1:
+        if len(query.strip().split()) > 1:
             return False # no spaces in packages
 
         # use `apt-cache show` for the package name
@@ -206,10 +214,12 @@
         # in theory both the home page and the ubuntu page could be interesting
         # (different handlers?)
 
-        returncode = call(['apt-cache', 'show', self.baseurl])
+        returncode = subprocess.call(['apt-cache', 'show', query], stdout=subprocess.PIPE)
         if returncode:
             return False
 
+        return True
+
 # TODO:
 # - https://mozillians.org/en-US/u/jhammel/ handler
 # - https://mozillians.org/en-US/u/williamr/ handler