Added 'save config'. Adjusted test/tutorial.py (and test/ in general) passes.
authorW. Trevor King <wking@drexel.edu>
Tue, 17 Aug 2010 04:02:33 +0000 (00:02 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 17 Aug 2010 04:02:33 +0000 (00:02 -0400)
doc/config.txt
hooke/plugin/config.py
test/polymer_fit.py
test/tutorial.py

index d2a8d0a..6b72780 100644 (file)
@@ -22,7 +22,11 @@ Examples
 
 Run::
 
-    $ hooke --save-config -c ''
+    $ ./bin/hk.py --save-config -c ''
+
+or::
+
+    $ ./bin/hk.py -c 'save_config --output .hooke.cfg'
 
 To write a well commented example config file to :file:`.hooke.cfg`.
 
@@ -50,5 +54,3 @@ Hooke.
   run will *not be saved* when Hooke exits.  To save the changes,
   either run the `save config` command before closing Hooke, or start
   Hooke with the ``--save-config`` option.
-
-.. todo:: Implement `save config` command.
index 466ca1f..ea1b039 100644 (file)
@@ -32,7 +32,7 @@ class ConfigPlugin (Builtin):
     def __init__(self):
         super(ConfigPlugin, self).__init__(name='config')
         self._commands = [GetCommand(self), SetCommand(self),
-                          PrintCommand(self)]
+                          PrintCommand(self), SaveCommand(self),]
 
 
 # Define common or complicated arguments
@@ -95,7 +95,7 @@ class SetCommand (Command):
         outqueue.put(ReloadUserInterfaceConfig(hooke.config))
 
 class PrintCommand (Command):
-    """Get the current value of all configuration options.
+    """Get the current configuration file text.
     """
     def __init__(self, plugin):
         super(PrintCommand, self).__init__(
@@ -105,3 +105,29 @@ class PrintCommand (Command):
         out = StringIO()
         hooke.config.write(out)
         outqueue.put(out.getvalue())
+
+
+class SaveCommand (Command):
+    """Save the current configuration options.
+    """
+    def __init__(self, plugin):
+        super(SaveCommand, self).__init__(
+            name='save config',
+            arguments=[
+                Argument(name='output', type='file',
+                         help="""
+File name for the output configuration.  Defaults to overwriting the
+most local loaded config file.
+""".strip()),
+                ],
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+        f = None
+        try:
+            if params['output'] != None:
+                f = open(params['output'], 'w')
+            hooke.config.write(fp=f)
+        finally:
+            if f != None:
+                f.close()
index 40d654e..fe5ccc7 100644 (file)
@@ -84,11 +84,11 @@ Data([[ NaN,  NaN],
        [ NaN,  NaN],
        [ NaN,  NaN]])
 >>> retract[1097:1103,-2:]  # doctest: +ELLIPSIS
-Data([[             NaN,   5.220...e-10],
-       [             NaN,   5.592...e-10],
-       [             NaN,   6.104...e-10],
-       [             NaN,   6.261...e-10],
-       [             NaN,   7.058...e-10],
+Data([[             NaN,   5.234...e-10],
+       [             NaN,   5.612...e-10],
+       [             NaN,   6.132...e-10],
+       [             NaN,   6.292...e-10],
+       [             NaN,   7.105...e-10],
        [             NaN,              NaN]])
 >>> retract[-5:,-2:]
 Data([[ NaN,  NaN],
index 32992ef..967cda8 100644 (file)
@@ -219,31 +219,27 @@ Success
 
 *Taking notes*
 
->>> h = r.run_lines(h, ['''set_note "Hi there.\\nI'm a note"'''])
-Success
-<BLANKLINE>
->>> h = r.run_lines(h, ['note_filter_playlist --output_playlist filtered'])
->>> h = r.run_lines(h, ['get_playlist'])
->>> h = r.run_lines(h, ['jump_to_playlist -- -1'])
->>> h = r.run_lines(h, ['get_playlist'])
->>> h = r.run_lines(h, ['get_curve'])
->>> h = r.run_lines(h, ['curve_index'])
->>> h = r.run_lines(h, ['jump_to_curve -- -1'])
->>> h = r.run_lines(h, ['get_curve'])
->>> h = r.run_lines(h, ['curve_index'])
->>> h = r.run_lines(h, ['get_note'])
->>> h = r.run_lines(h, ['set_note ""'])
->>> h = r.run_lines(h, ['get_note'])
+See :file:`note.py`.
 
 *Exporting curves*
 
->>> os.path.exists('mycurve.dat')
->>> h = r.run_lines(h, ['export_bock --output mycurve.dat'])
+>>> export_already_exists = os.path.exists('mycurve.dat')
+>>> export_already_exists
+False
+>>> h = r.run_lines(h, ['export_block --output mycurve.dat'])
+Success
+<BLANKLINE>
 >>> os.path.isfile('mycurve.dat')
+True
+>>> if export_already_exists == False:
+...    os.remove('mycurve.dat')
 
 *Measuring distances and forces*
 
->>> h = r.run_lines(h, ['delta 300 500'])
+>>> h = r.run_lines(h, ['delta 300 500'])  # doctest: +ELLIPSIS
+[('z piezo (m)', -4.913...e-08), ('deflection (m)', -2.834...e-08)]
+Success
+<BLANKLINE>
 
 *Worm like chain and freely jointed chain fitting*
 
@@ -254,9 +250,29 @@ Success
 *Configuring Hooke*
 
 >>> h = r.run_lines(h, ['set_config conditions temperature 300.0'])
+Success
+<BLANKLINE>
 >>> h = r.run_lines(h, ['get_config conditions temperature'])
+300.0
+Success
+<BLANKLINE>
 >>> h = r.run_lines(h, ['set_config conditions temperature 295.3'])
+Success
+<BLANKLINE>
 >>> h = r.run_lines(h, ['get_config conditions temperature'])
->>> h = r.run_lines(h, ['print_config'])
+295.3
+Success
+<BLANKLINE>
+>>> h = r.run_lines(h, ['print_config'])  # doctest: +ELLIPSIS
+# Default environmental conditions in case they are not specified in
+# the force curve data.  Configuration options in this section are
+# available to every plugin.
+[conditions]
+# Temperature in Kelvin
+temperature = 295.3
+<BLANKLINE>
+...
 >>> h = r.run_lines(h, ['save_config'])
+Success
+<BLANKLINE>
 """