Add epilogs to each OptionParser in pysawsim.
[sawsim.git] / pysawsim / sawsim.py
index 1500a93038c8322b0de24ad72bae519da4c3a3e4..858db1c8edc76cc49c2ce752ec0c9b5fe2cd7793 100644 (file)
@@ -29,6 +29,7 @@ import hashlib
 from optparse import Option
 import os
 import os.path
+from random import shuffle
 import shutil
 from uuid import uuid4
 
@@ -36,7 +37,7 @@ from .manager import MANAGERS, get_manager, InvokeJob
 
 
 SAWSIM = 'sawsim'  # os.path.expand(os.path.join('~', 'bin', 'sawsim'))
-CACHE_DIR = os.path.expanduser(os.path.join('~', '.sawsim_cache'))
+CACHE_DIR = os.path.expanduser(os.path.join('~', '.sawsim-cache'))
 DEFAULT_PARAM_STRING = (
     '-s cantilever,hooke,0.05 -N1 '
     '-s folded,null -N8 '
@@ -191,7 +192,7 @@ class SawsimRunner (object):
         """
         >>> s = SawsimRunner()
         >>> s._param_cache_dir(DEFAULT_PARAM_STRING)  # doctest: +ELLIPSIS
-        '/.../.sawsim_cache/...'
+        '/.../.sawsim-cache/...'
         """
         return os.path.join(
             self._cache_dir, hashlib.sha256(param_string).hexdigest())
@@ -204,7 +205,7 @@ class SawsimRunner (object):
 
     def _load_cached_data(self, param_string):
         pcd = self._param_cache_dir(param_string)
-        for filename in os.listdir(pcd):
+        for filename in shuffle(os.listdir(pcd)):
             if not filename.endswith('.dat'):
                 continue
             with open(os.path.join(pcd, filename), 'r') as f:
@@ -285,8 +286,13 @@ def main(argv=None):
 
     sr = SawsimRunner()
 
-    usage = "%prog [options]"
-    parser = OptionParser(usage)
+    usage = '%prog [options]'
+    epilog = '\n'.join([
+            'Python wrapper around `sawsim`.  Distribute `N` runs using',
+            'one of the possible job "managers".  Also supports caching',
+            'results to speed future runs.'
+            ])
+    parser = OptionParser(usage, epilog=epilog)
     for option in sr.optparse_options:
         parser.add_option(option)