[Checkins] SVN: zc.buildout/trunk/src/zc/buildout/ two changes that make the handling of the download cache match how buildout

Thomas Lotze tl at gocept.com
Thu Aug 13 03:17:25 EDT 2009


Log message for revision 102730:
  two changes that make the handling of the download cache match how buildout
  does it for easy-install:
  
  - require the download cache (but not namespace directories) to be an
    existing directory in order to catch configuration bugs
  
  - made relative download cache paths refer to the buildout directory
  

Changed:
  U   zc.buildout/trunk/src/zc/buildout/download.py
  U   zc.buildout/trunk/src/zc/buildout/download.txt
  U   zc.buildout/trunk/src/zc/buildout/extends-cache.txt

-=-
Modified: zc.buildout/trunk/src/zc/buildout/download.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/download.py	2009-08-13 06:44:08 UTC (rev 102729)
+++ zc.buildout/trunk/src/zc/buildout/download.py	2009-08-13 07:17:25 UTC (rev 102730)
@@ -56,6 +56,7 @@
 
     def __init__(self, options={}, cache=-1, namespace=None,
                  offline=-1, fallback=False, hash_name=False, logger=None):
+        self.directory = options.get('directory', '')
         self.cache = cache
         if cache == -1:
             self.cache = options.get('download-cache')
@@ -69,10 +70,15 @@
         self.logger = logger or logging.getLogger('zc.buildout')
 
     @property
-    def cache_dir(self):
+    def download_cache(self):
         if self.cache is not None:
-            return os.path.join(realpath(self.cache), self.namespace or '')
+            return realpath(os.path.join(self.directory, self.cache))
 
+    @property
+    def cache_dir(self):
+        if self.download_cache is not None:
+            return os.path.join(self.download_cache, self.namespace or '')
+
     def __call__(self, url, md5sum=None, path=None):
         """Download a file according to the utility's configuration.
 
@@ -98,9 +104,15 @@
         but will not remove the copy in that case.
 
         """
+        if not os.path.exists(self.download_cache):
+            raise zc.buildout.UserError(
+                'The directory:\n'
+                '%r\n'
+                "to be used as a download cache doesn't exist.\n"
+                % self.download_cache)
         cache_dir = self.cache_dir
         if not os.path.exists(cache_dir):
-            os.makedirs(cache_dir)
+            os.mkdir(cache_dir)
         cache_key = self.filename(url)
         cached_path = os.path.join(cache_dir, cache_key)
 

Modified: zc.buildout/trunk/src/zc/buildout/download.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/download.txt	2009-08-13 06:44:08 UTC (rev 102729)
+++ zc.buildout/trunk/src/zc/buildout/download.txt	2009-08-13 07:17:25 UTC (rev 102730)
@@ -254,6 +254,15 @@
 
 >>> remove(path)
 
+Finally, let's see what happens if the download cache to be used doesn't exist
+as a directory in the file system yet:
+
+>>> Download(cache=join(cache, 'non-existent'))(server_url+'foo.txt')
+Traceback (most recent call last):
+UserError: The directory:
+'/tmp/tmpZ2cwCfbuildoutSetUp/_TEST_/download-cache/non-existent'
+to be used as a download cache doesn't exist.
+
 Using namespace sub-directories of the download cache
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -453,6 +462,19 @@
 >>> print download.cache_dir
 /download-cache/cmmi
 
+If the ``download-cache`` option specifies a relative path, it is understood
+relative to the current working directory, or to the buildout directory if
+that is given:
+
+>>> download = Download({'download-cache': 'relative-cache'})
+>>> print download.cache_dir
+/sample-buildout/relative-cache/
+
+>>> download = Download({'directory': join(sample_buildout, 'root'),
+...                      'download-cache': 'relative-cache'})
+>>> print download.cache_dir
+/sample-buildout/root/relative-cache/
+
 Keyword parameters take precedence over the corresponding options:
 
 >>> download = Download({'download-cache': cache}, cache=None)

Modified: zc.buildout/trunk/src/zc/buildout/extends-cache.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/extends-cache.txt	2009-08-13 06:44:08 UTC (rev 102729)
+++ zc.buildout/trunk/src/zc/buildout/extends-cache.txt	2009-08-13 07:17:25 UTC (rev 102730)
@@ -66,6 +66,7 @@
 running buildout and the base.cfg file will be put in it (with the file name
 being a hash of the complete URL):
 
+>>> mkdir('cache')
 >>> write('buildout.cfg', """\
 ... [buildout]
 ... extends = %sbase.cfg
@@ -166,6 +167,8 @@
 
 >>> mkdir('home')
 >>> mkdir('home', '.buildout')
+>>> mkdir('cache')
+>>> mkdir('user-cache')
 >>> os.environ['HOME'] = join(sample_buildout, 'home')
 >>> write('home', '.buildout', 'default.cfg', """\
 ... [buildout]



More information about the Checkins mailing list