Add os.path.expanduser() wrappers to user-supplied paths.
authorW. Trevor King <wking@drexel.edu>
Wed, 29 Sep 2010 13:47:50 +0000 (09:47 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 29 Sep 2010 13:47:50 +0000 (09:47 -0400)
This allows things like
  [gui user interface]
  perspective path = ~/.hooke/resources/gui/perspective
to work as expected.

doc/install.txt
hooke/plugin/command_stack.py
hooke/plugin/config.py
hooke/plugin/curve.py
hooke/plugin/cut.py
hooke/plugin/playlist.py
hooke/plugin/playlists.py
hooke/ui/gui/__init__.py

index 98ea4c17aaab5593c0c4d7eff33fb66cb3c7601b..270f99ea53dc93dd42eb82bccfafbc95e2385781 100644 (file)
@@ -68,6 +68,25 @@ to install Hooke.  Run::
 
 to see a list of installation options you may want to configure.
 
+If you install Hooke, you should probably setup a system- or user-wide
+configuration file (:doc:`config`), and replace any relative paths
+with appropriate absolute paths.  For example::
+
+    # Commands for managing a command stack (similar to macros).
+    [command_stack plugin]
+    # Directory containing command stack files.
+    path = resources/command_stack
+
+    # wxWindows graphical user interface.
+    [gui user interface]
+    # Path to the hooke icon image.
+    icon image = /usr/share/hooke/doc/img/microscope.ico
+    # Path to the Hooke splash screen image.
+    splash screen image = /usr/share/hooke/doc/img/hooke.jpg
+    # Directory containing perspective files.
+    perspective path = ~/.hooke/resources/gui/perspective
+
+
 Running Hooke from the source directory
 =======================================
 
index 59ca5ddbe79e98782ff5d60f3d038cf2293349cf..af7549016c79dd90ca106e5baad2305124c85bc0 100644 (file)
@@ -236,7 +236,8 @@ input command stack.  If the command stack does not have an input file
             params['output'] = 'default'
         if params['output'] != None:
             params['output'] = os.path.join(
-                self.plugin.config['path'], params['output'])
+                os.path.expanduser(self.plugin.config['path']),
+                params['output'])
         return params
 
 class LoadCommand (CommandStackCommand):
@@ -265,7 +266,8 @@ File name for the input command stack.
             params['input'] = 'default'
         if params['input'] != None:
             params['input'] = os.path.join(
-                self.plugin.config['path'], params['input'])
+                os.path.expanduser(self.plugin.config['path']),
+                params['input'])
         return params
 
 
index ea1b0397f9d657ab84008cfab5e5ef87062612d5..71e0611373b8ab4d1e2366c24240bab49a36a215 100644 (file)
@@ -21,6 +21,7 @@ associated :class:`hooke.command.Command`\s for handling
 :mod:`hooke.config` classes.
 """
 
+import os.path
 from StringIO import StringIO
 
 from ..command import Command, Argument, Failure
@@ -126,7 +127,7 @@ most local loaded config file.
         f = None
         try:
             if params['output'] != None:
-                f = open(params['output'], 'w')
+                f = open(os.path.expanduser(params['output']), 'w')
             hooke.config.write(fp=f)
         finally:
             if f != None:
index 3ef141ce0b14aa2d5d707f9108dccfd132c9e5cf..7f1190042f4898130cc6e0512f311cf27f9c24d3 100644 (file)
@@ -25,6 +25,7 @@ associated :class:`hooke.command.Command`\s for handling
 """
 
 import copy
+import os.path
 import re
 
 import numpy
@@ -459,7 +460,7 @@ True if you want the column-naming header line.
     def _run(self, hooke, inqueue, outqueue, params):
         data = self._block(hooke, params)
 
-        with open(params['output'], 'w') as f:
+        with open(os.path.expanduser(params['output']), 'w') as f:
             if params['header'] == True:
                 f.write('# %s \n' % ('\t'.join(data.info['columns'])))
             numpy.savetxt(f, data, delimiter='\t')
index 5d7d79c0e7eae4d7d30b5716c399aa75736b32c1..6aef07695bd38ea16ee8444c95d387a29c2f5e1c 100644 (file)
@@ -22,6 +22,8 @@
 :class:`CutCommand`.
 """
 
+import os.path
+
 import numpy
 
 from ..command import Command, Argument, Failure
@@ -97,7 +99,7 @@ True if you want the column-naming header line.
         cut_data = data[i_min:i_max+1,:] # slice rows from row-major data
         # +1 to include data[i_max] row
 
-        f = open(params['output'], 'w')
+        f = open(os.path.expanduser(params['output']), 'w')
         if params['header'] == True:
             f.write('# %s \n' % ('\t'.join(cut_data.info['columns'])))
         numpy.savetxt(f, cut_data, delimiter='\t')
index 616cfed6739c52ff73627cd0aff6ffc97cb19973..6dced289e376d6642489d568dcca4963820809bd 100644 (file)
@@ -247,7 +247,8 @@ created from scratch with 'new playlist'), this option is required.
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-       self._playlist(hooke, params).save(params['output'])
+       self._playlist(hooke, params).save(
+            os.path.expanduser(params['output']))
 
 
 class LoadCommand (PlaylistAddingCommand):
@@ -270,7 +271,8 @@ Drivers for loading curves.
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-        p = load(path=params['input'], drivers=params['drivers'], hooke=hooke)
+        p = load(os.path.expanduser(path=params['input']),
+                 drivers=params['drivers'], hooke=hooke)
         self._set_playlist(hooke, params, p)
        outqueue.put(p)
 
@@ -295,7 +297,7 @@ Additional information for the input :class:`hooke.curve.Curve`.
 
     def _run(self, hooke, inqueue, outqueue, params):
         self._playlist(hooke, params).append_curve_by_path(
-            params['input'], params['info'], hooke=hooke)
+            os.path.expanduser(params['input']), params['info'], hooke=hooke)
 
 
 class AddGlobCommand (PlaylistCommand):
index e047cb881e5ef1abe2feeba620838871f74c8a05..d15740eefe09780b342451efa2beb4e321041886 100644 (file)
@@ -21,6 +21,8 @@ several associated :class:`hooke.command.Command`\s for handling
 lists of :class:`hooke.playlist.Playlist` classes.
 """
 
+import os.path
+
 from ..command import Command, Argument, Failure
 from ..playlist import FilePlaylist
 from . import Builtin
@@ -117,7 +119,7 @@ Default filename for future saves.
     def _run(self, hooke, inqueue, outqueue, params):
         p = FilePlaylist(
             drivers=hooke.drivers,
-            path=params['file'],
+            path=os.path.expanduser(params['file']),
             )
         self._set_playlist(hooke, params, p)
         outqueue.put(p)
index 6f1a02161493309df7840357b347ce499e390304..a4d91f1b045946bdeb8933942a384a635ff61e0a 100644 (file)
@@ -71,7 +71,9 @@ class HookeFrame (wx.Frame):
         self._perspectives = {}  # {name: perspective_str}
         self._c = {}
 
-        self.SetIcon(wx.Icon(self.gui.config['icon image'], wx.BITMAP_TYPE_ICO))
+        self.SetIcon(wx.Icon(
+                os.path.expanduser(self.gui.config['icon image']),
+                wx.BITMAP_TYPE_ICO))
 
         # setup frame manager
         self._c['manager'] = aui.AuiManager()
@@ -707,7 +709,7 @@ class HookeFrame (wx.Frame):
         self._perspectives = {
             'Default': self._c['manager'].SavePerspective(),
             }
-        path = self.gui.config['perspective path']
+        path = os.path.expanduser(self.gui.config['perspective path'])
         if os.path.isdir(path):
             files = sorted(os.listdir(path))
             for fname in files:
@@ -784,7 +786,7 @@ class HookeFrame (wx.Frame):
         if name == 'Default':
             name = 'New perspective'
         name = select_save_file(
-            directory=self.gui.config['perspective path'],
+            directory=os.path.expanduser(self.gui.config['perspective path']),
             name=name,
             extension=self.gui.config['perspective extension'],
             parent=self,
@@ -793,7 +795,8 @@ class HookeFrame (wx.Frame):
         if name == None:
             return
         self._save_perspective(
-            perspective, self.gui.config['perspective path'], name=name,
+            perspective,
+            os.path.expanduser(self.gui.config['perspective path']), name=name,
             extension=self.gui.config['perspective extension'])
 
     def _on_delete_perspective(self, *args, **kwargs):
@@ -814,8 +817,8 @@ class HookeFrame (wx.Frame):
         names = [options[i] for i in dialog.selected]
         dialog.Destroy()
         self._delete_perspectives(
-            self.gui.config['perspective path'], names=names,
-            extension=self.gui.config['perspective extension'])
+            os.path.expanduser(self.gui.config['perspective path']),
+            names=names, extension=self.gui.config['perspective extension'])
 
     def _on_select_perspective(self, _class, method, name):
         self._restore_perspective(name)
@@ -867,7 +870,7 @@ class HookeApp (wx.App):
 
     def _setup_splash_screen(self):
         if self.gui.config['show splash screen'] == True:
-            path = self.gui.config['splash screen image']
+            path = os.path.expanduser(self.gui.config['splash screen image'])
             if os.path.isfile(path):
                 duration = self.gui.config['splash screen duration']
                 wx.SplashScreen(