[cc-commits] [CC SVN] r12044 - in stats/wikibot: . mwclient/simplejson

webmaster at creativecommons.org webmaster at creativecommons.org
Sat Apr 4 12:46:15 EDT 2009


Author: bhy
Date: 2009-04-04 16:46:15 +0000 (Sat, 04 Apr 2009)
New Revision: 12044

Added:
   stats/wikibot/utils.py
Removed:
   stats/wikibot/mwclient/simplejson/tests/
Modified:
   stats/wikibot/linkback_reader.py
   stats/wikibot/views.py
Log:
fix tests, remove simplejson tests.

Modified: stats/wikibot/linkback_reader.py
===================================================================
--- stats/wikibot/linkback_reader.py	2009-04-04 15:53:32 UTC (rev 12043)
+++ stats/wikibot/linkback_reader.py	2009-04-04 16:46:15 UTC (rev 12044)
@@ -8,6 +8,7 @@
 import gzip
 import StringIO
 
+from utils import tries
 DAILY_CSV_NAME = 'linkbacks-daily-Yahoo.csv'
 CSV_DUMPS_URL = "http://a6.creativecommons.org/~paulproteus/csv-dumps/"
 if CSV_DUMPS_URL[-1] <> '/':
@@ -81,25 +82,6 @@
 def urlopen(url, ntries=3):
     #import sys
     #print >>sys.stderr, url
-    return try_thrice(ntries, urllib2.urlopen, url)
+    return tries(ntries, urllib2.urlopen, url)
 
-def try_thrice(ntries, fn, *arglist, **argdict):
-    """
-    Borrowed from Asheesh.
-    """
-    tries = 0
-    while True:
-        try:
-            return fn(*arglist, **argdict)
-        except Exception, e:
-            if isinstance(e, KeyboardInterrupt):
-               raise e
-            print "Huh, while doing %s(%s, %s), %s happened." % (fn, arglist, argdict, e)
-            tries += 1
-            if tries >= ntries:
-                raise
-            sleeptime = 2 ** tries * 10
-            print 'trying again after sleeping for %d' % sleeptime
-            import time
-            time.sleep(sleeptime)
 

Added: stats/wikibot/utils.py
===================================================================
--- stats/wikibot/utils.py	                        (rev 0)
+++ stats/wikibot/utils.py	2009-04-04 16:46:15 UTC (rev 12044)
@@ -0,0 +1,26 @@
+import sys
+import time
+
+def log(s):
+    print >>sys.stderr, s
+    return
+
+def tries(ntries, fn, *arglist, **argdict):
+    """
+    Borrowed from Asheesh.
+    """
+    tried = 0
+    while True:
+        try:
+            return fn(*arglist, **argdict)
+        except Exception, e:
+            if isinstance(e, KeyboardInterrupt):
+               raise e
+            log("Huh, while doing %s(%s, %s), %s happened." % (fn, arglist, argdict, e))
+            tried += 1
+            if tried >= ntries:
+                raise
+            sleeptime = 2 ** tried * 10
+            log('trying again after sleeping for %d' % sleeptime)
+            time.sleep(sleeptime)
+

Modified: stats/wikibot/views.py
===================================================================
--- stats/wikibot/views.py	2009-04-04 15:53:32 UTC (rev 12043)
+++ stats/wikibot/views.py	2009-04-04 16:46:15 UTC (rev 12044)
@@ -76,9 +76,9 @@
     The methods in the View class are generators yielding pages.
 
     >>> view = View()
-    >>> page = view.stats_world().next()
+    >>> page = view.list_juris().next()
     >>> page.title
-    'World'
+    'List of Jurisdictions'
     """
     def __init__(self, data=None):
         if data is None:




More information about the cc-commits mailing list