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, 16 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Sat Nov 21 17:29:39 2009 -0500
+++ b/setup.py	Sat Nov 21 17:49:36 2009 -0500
@@ -30,5 +30,6 @@
       GoogleMaps = smartopen.handlers:GoogleMaps
       Wikipedia = smartopen.handlers:Wikipedia
       Google = smartopen.handlers:Google
+      Trac = smartopen.handlers:Trac
       """,
       )
--- a/smartopen.ini	Sat Nov 21 17:29:39 2009 -0500
+++ b/smartopen.ini	Sat Nov 21 17:49:36 2009 -0500
@@ -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	Sat Nov 21 17:29:39 2009 -0500
+++ b/smartopen/handlers.py	Sat Nov 21 17:49:36 2009 -0500
@@ -57,40 +57,21 @@
         return bool(self.process(query))
 
 class Trac(Location):
-    def __init__(self, url):
-        self.url = url
-        
-
-# 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 __init__(self, baseurl):
+        baseurl = baseurl.strip('/') + '/'
+        Location.__init__(self, baseurl)
 
-#     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[0] == 'r':
+            if query[1:].isdigit():
+                return 'changeset/' + str(query[1:])
+        if query[0] == '#':
+            if query[1:].isdigit():
+                return 'ticket/' + str(query[1:])
 
-#     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()
+    def test(self, query):
+        return bool(self.process(query))
+        
 
 class Wikipedia(Location):
     """try to open the query in wikipedia"""