[merge] benchmark caching

Martin Pool mbp at canonical.com
Thu Aug 10 04:11:07 BST 2006


+1 with comments, as long as (as it seems?) caching is off by default.

> === modified file 'bzrlib/benchmarks/__init__.py'
> --- bzrlib/benchmarks/__init__.py	2006-07-11 14:47:00 +0000
> +++ bzrlib/benchmarks/__init__.py	2006-08-08 16:23:16 +0000
> @@ -17,30 +17,60 @@
> -    def make_kernel_like_tree(self, url=None):
> +    CACHE_ROOT = None
> +
> +    def get_cache_dir(self, extra):
> +        """Get the directory to use for caching the given object."""
> +
> +        if Benchmark.CACHE_ROOT is None:
> +            Benchmark.CACHE_ROOT = osutils.pathjoin(self.TEST_ROOT, 'CACHE')
> +        if not os.path.isdir(Benchmark.CACHE_ROOT):
> +            os.mkdir(Benchmark.CACHE_ROOT)
> +        cache_dir = osutils.pathjoin(self.CACHE_ROOT, extra)
> +        return cache_dir, os.path.exists(cache_dir)
> +
> +    def make_kernel_like_tree(self, url=None, root='.',
> +                              hardlink_working=False):

It seems like a lot of stuff is being put into this class that doesn't
strongly belong there.  Perhaps we can have a separate class for setting
up the test trees?  I'd prefer that were separated out before this
lands.

> === modified file 'bzrlib/osutils.py'
> --- bzrlib/osutils.py	2006-08-01 19:09:18 +0000
> +++ bzrlib/osutils.py	2006-08-07 23:23:07 +0000
> @@ -927,6 +927,48 @@
>                  pending.append(dir)
>  
>  

> +def copy_tree(from_path, to_path, handlers={}):
> +    """Copy all of the entries in from_path into to_path.
> +
> +    :param from_path: The base directory to copy. 
> +    :param to_path: The target directory. If it does not exist, it will
> +        be created.
> +    :param handlers: A dictionary of functions, which takes a source and
> +        destinations for files, directories, etc.
> +        It is keyed on the file kind, such as 'directory', 'symlink', or 'file'
> +        'file', 'directory', and 'symlink' should always exist.
> +        If they are missing, they will be replaced with 'os.mkdir()',
> +        'os.readlink() + os.symlink()', and 'shutil.copy2()', respectively.
> +    """
> +    # Now, just copy the existing cached tree to the new location
> +    # We use a cheap trick here.
> +    # Absolute paths are prefixed with the first parameter
> +    # relative paths are prefixed with the second.
> +    # So we can get both the source and target returned
> +    # without any extra work.
> +
> +    def copy_dir(source, dest):
> +        os.mkdir(dest)
> +
> +    def copy_link(source, dest):
> +        """Copy the contents of a symlink"""
> +        link_to = os.readlink(source)
> +        os.symlink(link_to, dest)
> +
> +    real_handlers = {'file':shutil.copy2,
> +                     'symlink':copy_link,
> +                     'directory':copy_dir,
> +                    }
> +    real_handlers.update(handlers)
> +
> +    if not os.path.exists(to_path):
> +        real_handlers['directory'](from_path, to_path)
> +
> +    for dir_info, entries in walkdirs(from_path, prefix=to_path):
> +        for relpath, name, kind, st, abspath in entries:
> +            real_handlers[kind](abspath, relpath)

Just a comment: you could also write this as a base class where
particular methods are overridden to specialize handling of particular
files.  I'm not sure doing so would be really much better, but it's
arguably consistent with the generally OO (rather than functional) style
we use.

For example in test_copy_tree_handlers it could accumulate into the
copier object.

-- 
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060810/4ffe9001/attachment-0001.pgp 


More information about the bazaar mailing list