rev 3667 - in debbugs-illa: . bz bzlink

Pierre Habouzit madcoder at costa.debian.org
Wed Apr 26 15:56:36 UTC 2006


Author: madcoder
Date: 2006-04-26 15:56:35 +0000 (Wed, 26 Apr 2006)
New Revision: 3667

Modified:
   debbugs-illa/TODO
   debbugs-illa/bz/__init__.py
   debbugs-illa/bzlink/__init__.py
   debbugs-illa/bzpull.py
Log:
implement the HTTP cache.
we don't rely on wget anymore



Modified: debbugs-illa/TODO
===================================================================
--- debbugs-illa/TODO	2006-04-26 13:58:24 UTC (rev 3666)
+++ debbugs-illa/TODO	2006-04-26 15:56:35 UTC (rev 3667)
@@ -21,11 +21,6 @@
     * make bzlink figure how to jump from merged closings into other merged
       closings.  => currently user has to use bzsync manually
 
-    * have a ~/.bzlink/ directory with:
-       + cache/ for configs.cgi's and some bug reports
-       + a local .cfg to have credentials (subscribe bugs-fwd, and submit
-         bugs)
-
     * find a way to post new bugs, interactively or not.  call that bzpush.py
       config.cgi helps us a *lot* here.
 

Modified: debbugs-illa/bz/__init__.py
===================================================================
--- debbugs-illa/bz/__init__.py	2006-04-26 13:58:24 UTC (rev 3666)
+++ debbugs-illa/bz/__init__.py	2006-04-26 15:56:35 UTC (rev 3667)
@@ -34,13 +34,16 @@
 import commands, re
 
 class BzInterface:
-    def __init__(self, bzUrl):
+    def __init__(self, bzUrl, httpGet):
         self.baseurl   = bzUrl
-        self._wget_cmd = "wget -O - -o /dev/null %s/xml.cgi?id=%%s" % (self.baseurl)
+        self._GET      = httpGet
         self._bugurl   = re.compile(r"^%s/(?:show_bug.cgi\?id=)?([0-9]*)$" % (self.baseurl))
 
+    def urlFromBug(self, bugNum):
+        return "%s/xml.cgi?id=%s" % (self.baseurl, bugNum)
+
     def getReport(self, bugNum):
-        return BzReport(bugNum, commands.getoutput(self._wget_cmd % (bugNum)))
+        return BzReport(bugNum, self._GET(self.urlFromBug(bugNum)))
 
     def bugnumberFromUrl(self, url):
         m = self._bugurl.match(url)

Modified: debbugs-illa/bzlink/__init__.py
===================================================================
--- debbugs-illa/bzlink/__init__.py	2006-04-26 13:58:24 UTC (rev 3666)
+++ debbugs-illa/bzlink/__init__.py	2006-04-26 15:56:35 UTC (rev 3667)
@@ -28,7 +28,7 @@
 # SUCH DAMAGE.
 ###############################################################################
 
-import os
+import urllib, os, stat, time
 import sender
 from ConfigParser import RawConfigParser
 
@@ -47,9 +47,9 @@
 
 class _BzlinkConfig:
     def __init__(self):
-        self._dotdir = os.path.expanduser('~/.bzlink/')
-        if not os.path.exists(self._dotdir):
-            os.mkdir(self._dotdir)
+        self._dotdir = os.path.expanduser('~/.bzlink')
+        if not os.path.exists(self._dotdir): os.mkdir(self._dotdir)
+        self._purgecache()
         self._cfg = RawConfigParser()
         self._cfg.read(['/etc/bzlink.cfg', './bzlink.cfg', self._dotfile('bzlink.cfg')])
         self._section = None
@@ -57,6 +57,15 @@
     def _dotfile(self, name):
         return os.path.join(self._dotdir, name)
 
+    def _purgecache(self):
+        d = self._dotfile('cache')
+        if not os.path.exists(d): os.mkdir(d)
+        for f in os.listdir(d):
+            f = os.path.join(d, f)
+            if os.stat(f)[stat.ST_MTIME] > time.time() + 3600:
+                os.unlink(f)
+
+
     def setSection(self, section):
         if not self._cfg.has_section(section):
             raise NoSuchSection(section)
@@ -84,7 +93,23 @@
             return url.rstrip('/')
         else: return url
 
+class BzOpener(urllib.FancyURLopener):
+    version = "bzlink"
+
+    def __init__(self):
+        urllib.FancyURLopener.__init__(self)
+        self.addheader(('Accept', '*/*'))
+
 BzlinkConfig = _BzlinkConfig()
+urllib._urlopener = BzOpener()
 
-__all__ = ['BzlinkConfig', 'NoSuchSection']
+def GETc(url):
+    s = BzlinkConfig._dotfile(os.path.join('cache', url.replace('/', '_')))
+    if not os.path.exists(s):
+        urllib.urlretrieve(url, s)
+    f = file(s)
+    res = f.read()
+    f.close()
+    return res
 
+__all__ = ['BzlinkConfig', 'NoSuchSection', 'GETc']

Modified: debbugs-illa/bzpull.py
===================================================================
--- debbugs-illa/bzpull.py	2006-04-26 13:58:24 UTC (rev 3666)
+++ debbugs-illa/bzpull.py	2006-04-26 15:56:35 UTC (rev 3667)
@@ -84,7 +84,7 @@
     except bzlink.NoSuchSection, s:
         die("`%s' is an unknown Bugzilla" % (s))
 
-    bzi  = bz.BzInterface(Cnf.bugzilla())
+    bzi  = bz.BzInterface(Cnf.bugzilla(), bzlink.GETc)
     btsi = None
 
     actions = ["user %s\n" % (Cnf.user())]




More information about the pkg-kde-commits mailing list