community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1730721 - /comdev/projects.apache.org/scripts/cronjobs/urlutils.py
Date Tue, 16 Feb 2016 17:21:09 GMT
Author: sebb
Date: Tue Feb 16 17:21:09 2016
New Revision: 1730721

URL: http://svn.apache.org/viewvc?rev=1730721&view=rev
Log:
Allow debug print to be separately controlled

Modified:
    comdev/projects.apache.org/scripts/cronjobs/urlutils.py

Modified: comdev/projects.apache.org/scripts/cronjobs/urlutils.py
URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/scripts/cronjobs/urlutils.py?rev=1730721&r1=1730720&r2=1730721&view=diff
==============================================================================
--- comdev/projects.apache.org/scripts/cronjobs/urlutils.py (original)
+++ comdev/projects.apache.org/scripts/cronjobs/urlutils.py Tue Feb 16 17:21:09 2016
@@ -49,7 +49,7 @@ def mod_date(t):
         return None
     return time.strftime(_HTTP_TIME_FORMAT, time.gmtime(t))
 
-def getIfNewer(url, sinceTime, encoding=None, errors=None, silent=False):
+def getIfNewer(url, sinceTime, encoding=None, errors=None, silent=False, debug=False):
     """
         Get a URL if it is not newer
     
@@ -73,8 +73,8 @@ def getIfNewer(url, sinceTime, encoding=
         req = Request(url, headers=headers)
         resp = urlopen(req)
         # Debug - detect why json sometimes returned as HTML but no error code
-        if not silent: print("STATUS %s" % resp.getcode()) # Works for Py2/3
-        if not silent: print(resp.headers)
+        if debug and not silent: print("STATUS %s" % resp.getcode()) # Works for Py2/3
+        if debug and not silent: print(resp.headers)
         try:
             lastMod = resp.headers['Last-Modified']
             if not lastMod: # e.g. responses to git blob-plain URLs don't seem to have dates
@@ -123,11 +123,12 @@ class UrlCache(object):
             t = -1 # so cannot be confused with a valid mtime
         return t
 
-    def __init__(self, cachedir=None, interval=300, silent=False):
+    def __init__(self, cachedir=None, interval=300, silent=False, debug=False):
         __CACHE = 'data/cache'
         self.__interval = interval
         self.__cachedir = None
         self.__silent = silent
+        self.__debug = debug and not silent # don't allow debug if silent
         if cachedir: # assumed to be correct
             self.__cachedir = cachedir
         else:
@@ -208,7 +209,7 @@ class UrlCache(object):
 
         if not upToDate:
             sinceTime = mod_date(fileTime)
-            lastMod, response = getIfNewer(url, sinceTime, silent=self.__silent)
+            lastMod, response = getIfNewer(url, sinceTime, silent=self.__silent, debug=self.__debug)
             if response: # we have a new version
                 if lastMod:
                     try:



Mime
View raw message