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 d2a8d0ac8e25050a3229cd6774a52a253725454f..6b72780835f729ae95283b3b580a12e778f0bf60 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 466ca1f32f09c1555182cef0615c58a345a38034..ea1b0397f9d657ab84008cfab5e5ef87062612d5 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 40d654e45767ca67215dc7bba838e8c568e47225..fe5ccc76a26e09bb07c89ed84c7463de16713402 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 32992ef5db77e3ee38650f193e9af7476c32c671..967cda8498f57afd472b2e790ff1747b34f02bdd 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>
 """