diff options
| author | Stan Seibert <stan@mtrr.org> | 2012-01-20 13:38:10 -0500 | 
|---|---|---|
| committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:38 -0700 | 
| commit | 93d1f42c5c803c3da27312823ec19dedc8f16aa2 (patch) | |
| tree | 0d52533a08bd2c92819a53eca59f546b8e6279fa /bin/chroma-geo | |
| parent | b2bb0a2604d28b0ea25b2f3b3331062a3d6dcabe (diff) | |
| download | chroma-93d1f42c5c803c3da27312823ec19dedc8f16aa2.tar.gz chroma-93d1f42c5c803c3da27312823ec19dedc8f16aa2.tar.bz2 chroma-93d1f42c5c803c3da27312823ec19dedc8f16aa2.zip | |
Super simple geometry cache management tool: chroma-geo
Diffstat (limited to 'bin/chroma-geo')
| -rwxr-xr-x | bin/chroma-geo | 61 | 
1 files changed, 61 insertions, 0 deletions
| diff --git a/bin/chroma-geo b/bin/chroma-geo new file mode 100755 index 0000000..5113609 --- /dev/null +++ b/bin/chroma-geo @@ -0,0 +1,61 @@ +#!/usr/bin/env python +#--*-python-*- +import optparse +import sys +import time + +from chroma.cache import Cache +from chroma.loader import load_geometry_from_string +from chroma.log import logger, logging + +def list_geo(cache, args): +    geometries = cache.list_geometry() +    print 'List of cached geometries:' +    print '\n'.join(geometries) + +def save(cache, args): +    start = time.time() +    geometry = load_geometry_from_string(args[0]) +    print 'Geometry generated in %1.1f seconds.' % (time.time() - start) + +    start = time.time() +    cache.save_geometry(args[1], geometry) +    print 'Geometry saved to cache in %1.1f seconds.' % (time.time() - start) + +def remove(cache, args): +    cache.remove_geometry(args[0]) +    print 'Geometry "%s" removed.' % args[0] + +commands = { 'list' : list_geo, +             'save' : save, +             'remove' : remove } +              + +def main(): +    logger.setLevel(logging.INFO) + +    parser = optparse.OptionParser('%prog <cmd> <options>') +    parser.add_option('-c', '--cache', dest='cache',  +                      default=None, help='Chroma cache directory') +    options, args = parser.parse_args() + +    if len(args) < 1: +        sys.exit(parser.format_help()) + +    if options.cache is None: +        cache = Cache() +    else: +        cache = Cache(options.cache) + +    cmd = args[0] +    cmd_args = args[1:] + +    if cmd in commands: +        commands[cmd](cache, cmd_args) +    else: +        print 'error: unknown cmd %s' % cmd +        sys.exit(1) + +if __name__ == '__main__': +    main() + | 
