[Checkins] SVN: zc.buildout/branches/tlotze-download-api/src/zc/buildout/download. handle offline mode

Thomas Lotze tl at gocept.com
Mon May 25 03:18:34 EDT 2009


Log message for revision 100353:
  handle offline mode
  

Changed:
  U   zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.py
  U   zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.txt

-=-
Modified: zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.py
===================================================================
--- zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.py	2009-05-24 21:06:54 UTC (rev 100352)
+++ zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.py	2009-05-25 07:18:34 UTC (rev 100353)
@@ -22,6 +22,7 @@
 import shutil
 import urllib
 import urlparse
+import zc.buildout
 
 
 class URLOpener(urllib.FancyURLopener):
@@ -114,6 +115,11 @@
         See __call__.
 
         """
+        if (self.buildout.get('offline')
+            and urlparse.urlparse(url).scheme != 'file'):
+            raise zc.buildout.UserError(
+                "Couldn't download %r in offline mode." % url)
+
         urllib._urlopener = url_opener
         path, headers = urllib.urlretrieve(url, path)
         if not check_md5sum(path, md5sum):

Modified: zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.txt
===================================================================
--- zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.txt	2009-05-24 21:06:54 UTC (rev 100352)
+++ zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.txt	2009-05-25 07:18:34 UTC (rev 100353)
@@ -65,6 +65,18 @@
 >>> cat(path)
 This is a foo text.
 
+Trying to download a file in offline mode will result in an error:
+
+>>> download = Download({'offline': True}, use_cache=False)
+>>> download(server+'foo.txt')
+Traceback (most recent call last):
+UserError: Couldn't download 'http://localhost/foo.txt' in offline mode.
+
+As an exception to this rule, URLs in the ``file`` scheme will still work:
+
+>>> cat(download('file://%s/foo.txt' % root))
+This is a foo text.
+
 >>> remove(path)
 
 Downloading using the download cache
@@ -165,6 +177,13 @@
 >>> cat(path)
 This is a foo text.
 
+In offline mode, downloads from any URL will be successful if the file is
+found in the cache:
+
+>>> download = Download({'download-cache': cache, 'offline': True})
+>>> cat(download(server+'foo.txt'))
+This is a foo text.
+
 >>> remove(path)
 >>> remove(join(cache, 'foo.txt'))
 >>> write(join(root, 'foo.txt'), 'This is a foo text.')



More information about the Checkins mailing list