changeset 2:f084e152dd47

add Trac handler
author k0s <k0scist@gmail.com>
date Sat, 21 Nov 2009 17:49:36 -0500
parents 10fc4904c10f
children c5f19f51e1e8
files setup.py smartopen.ini smartopen/handlers.py
diffstat 3 files changed, 17 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py
+++ b/setup.py
@@ -25,10 +25,11 @@ setup(name='smartopen',
       [console_scripts]
       smartopen = smartopen.smartopen:main
 
       [smartopen.locations]
       URL = smartopen.handlers:URL
       GoogleMaps = smartopen.handlers:GoogleMaps
       Wikipedia = smartopen.handlers:Wikipedia
       Google = smartopen.handlers:Google
+      Trac = smartopen.handlers:Trac
       """,
       )
--- a/smartopen.ini
+++ b/smartopen.ini
@@ -1,5 +1,5 @@
 [DEFAULTS]
-handlers = GoogleMaps, Wikipedia, Google
+handlers = GoogleMaps, Trac, Wikipedia, Google
 
 [Trac]
-url = http://trac.openplans.org/trac
\ No newline at end of file
+baseurl = http://trac.openplans.org/opencore
\ No newline at end of file
--- a/smartopen/handlers.py
+++ b/smartopen/handlers.py
@@ -52,51 +52,32 @@ class GoogleMaps(Location):
         if not theaddress:
             return theaddress
         return urllib.quote_plus(theaddress)
 
     def test(self, query):
         return bool(self.process(query))
 
 class Trac(Location):
-    def __init__(self, url):
-        self.url = url
+    def __init__(self, baseurl):
+        baseurl = baseurl.strip('/') + '/'
+        Location.__init__(self, baseurl)
+
+    def process(self, query):
+        if query[0] == 'r':
+            if query[1:].isdigit():
+                return 'changeset/' + str(query[1:])
+        if query[0] == '#':
+            if query[1:].isdigit():
+                return 'ticket/' + str(query[1:])
+
+    def test(self, query):
+        return bool(self.process(query))
         
 
-# TODO: need configuration
-# class Revision(Location):
-#     def __init__(self):
-#         revision_url = 'http://trac.openplans.org/openplans/changeset/'
-#         Location.__init__(self, revision_url)
-
-#     def process(self, query):
-#         return query[1:]
-
-#     def test(self, query):
-#         if query[0] != 'r':
-#             return False
-#         return query[1:].isdigit()
-            
-# class TracTicket(Location):
-#     def __init__(self):
-#         # url for # data
-#         number_url = 'http://trac.openplans.org/openplans/ticket/'
-#         Location.__init__(self, number_url)
-
-#     def process(self, query):
-#         if query.startswith('#'):
-#             return query[1:]        
-#         return query
-
-#     def test(self, query):
-#         query = self.process(query)
-#         if len(query.split()) != 1:
-#             return False
-#         return query.isdigit()
-
 class Wikipedia(Location):
     """try to open the query in wikipedia"""
     def __init__(self):        
         wikiurl = 'http://en.wikipedia.org/wiki/'
         Location.__init__(self, wikiurl)
 
     def process(self, query):
         return urllib.quote_plus('_'.join(query.split()))