[Checkins] SVN: zc.buildout/branches/tlotze-download-api/src/zc/buildout/ handle the offline option's values correctly

Thomas Lotze tl at gocept.com
Thu Jun 11 02:51:51 EDT 2009


Log message for revision 100842:
  handle the offline option's values correctly

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

-=-
Modified: zc.buildout/branches/tlotze-download-api/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/tlotze-download-api/src/zc/buildout/buildout.py	2009-06-11 06:28:46 UTC (rev 100841)
+++ zc.buildout/branches/tlotze-download-api/src/zc/buildout/buildout.py	2009-06-11 06:51:50 UTC (rev 100842)
@@ -113,7 +113,7 @@
 
         for section, option, value in cloptions:
             if (section, option) == ('buildout', 'offline'):
-                offline = value
+                offline = value == 'true'
                 break
         else:
             offline = False
@@ -127,7 +127,7 @@
                                     [], None, offline))
 
         extends_cache = data['buildout'].get('extends-cache')
-        offline = offline or data['buildout'].get('offline', False)
+        offline = offline or data['buildout'].get('offline') == 'true'
 
         # load configuration files
         if config_file:
@@ -1175,9 +1175,12 @@
 
     Recursively open other files based on buildout options found.
     """
-
+    if offline:
+        offline_option = 'true'
+    else:
+        offline_option = 'false'
     download = zc.buildout.download.Download(
-        {'download-cache': cache, 'offline': offline},
+        {'download-cache': cache, 'offline': offline_option},
         use_cache=zc.buildout.download.FALLBACK, hash_name=True)
     if _isurl(filename):
         fp = open(download(filename))
@@ -1216,7 +1219,7 @@
 
     if root_config_file and 'buildout' in result:
         cache = result['buildout'].get('extends-cache', cache)
-        offline = offline or result['buildout'].get('offline', False)
+        offline = offline or result['buildout'].get('offline') == 'true'
 
     if extends:
         extends = extends.split()

Modified: zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.py
===================================================================
--- zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.py	2009-06-11 06:28:46 UTC (rev 100841)
+++ zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.py	2009-06-11 06:51:50 UTC (rev 100842)
@@ -152,7 +152,7 @@
         and scheduled for deletion at process exit.
 
         """
-        if self.buildout.get('offline'):
+        if self.buildout.get('offline') == 'true':
             raise zc.buildout.UserError(
                 "Couldn't download %r in offline mode." % url)
 

Modified: zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.txt
===================================================================
--- zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.txt	2009-06-11 06:28:46 UTC (rev 100841)
+++ zc.buildout/branches/tlotze-download-api/src/zc/buildout/download.txt	2009-06-11 06:51:50 UTC (rev 100842)
@@ -70,7 +70,7 @@
 
 Trying to download a file in offline mode will result in an error:
 
->>> download = Download({'offline': True}, use_cache=False)
+>>> download = Download({'offline': 'true'}, use_cache=False)
 >>> download(server_url+'foo.txt')
 Traceback (most recent call last):
 UserError: Couldn't download 'http://localhost/foo.txt' in offline mode.
@@ -196,7 +196,7 @@
 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})
+>>> download = Download({'download-cache': cache, 'offline': 'true'})
 >>> cat(download(server_url+'foo.txt'))
 This is a foo text.
 
@@ -386,7 +386,7 @@
 >>> write(server_data, 'foo.txt', 'The wrong text.')
 >>> cat(Download({})(server_url+'foo.txt'))
 The wrong text.
->>> offline_download = Download({'download-cache': cache, 'offline': True},
+>>> offline_download = Download({'download-cache': cache, 'offline': 'true'},
 ...                             use_cache=FALLBACK)
 >>> path = offline_download(server_url+'foo.txt')
 >>> cat(path)
@@ -411,3 +411,15 @@
 ChecksumError: MD5 checksum mismatch downloading 'http://localhost/foo.txt'
 >>> cat(cache, 'foo.txt')
 The wrong text.
+
+
+Specifying offline mode
+-----------------------
+
+As usual with zc.buildout, the offline option must assume one of the values
+'true' and 'false'. Turning offline mode on with 'true' has been shown above;
+setting the option to 'false' turns offline mode off explicitly:
+
+>>> download = Download({'offline': 'false'})
+>>> cat(download(server_url+'foo.txt'))
+This is a foo text.

Modified: zc.buildout/branches/tlotze-download-api/src/zc/buildout/extends-cache.txt
===================================================================
--- zc.buildout/branches/tlotze-download-api/src/zc/buildout/extends-cache.txt	2009-06-11 06:28:46 UTC (rev 100841)
+++ zc.buildout/branches/tlotze-download-api/src/zc/buildout/extends-cache.txt	2009-06-11 06:51:50 UTC (rev 100842)
@@ -172,6 +172,7 @@
 >>> write(server_data, 'base_default.cfg', """\
 ... [buildout]
 ... foo = bar
+... offline = false
 ... """)
 
 >>> write('buildout.cfg', """\
@@ -186,6 +187,7 @@
 >>> write(server_data, 'base.cfg', """\
 ... [buildout]
 ... parts =
+... offline = false
 ... """)
 
 Buildout will now assemble its configuration from all of these 6 files,
@@ -199,12 +201,14 @@
 >>> cat('user-cache', os.listdir('user-cache')[0])
 [buildout]
 foo = bar
+offline = false
 
 >>> ls('cache')
 -  c72213127e6eb2208a3e1fc1dba771a7
 >>> cat('cache', os.listdir('cache')[0])
 [buildout]
 parts =
+offline = false
 
 If, on the other hand, the extends caches are specified in files that get
 extended themselves, they won't be used for assembling the configuration they
@@ -243,6 +247,7 @@
 >>> cat('user-cache', os.listdir('user-cache')[0])
 [buildout]
 parts =
+offline = false
 
 >>> ls('cache')
 



More information about the Checkins mailing list