Added modular directory structure.
[hooke.git] / hooke / libhooke.py
old mode 100755 (executable)
new mode 100644 (file)
index 73534f2..05c9837
@@ -10,8 +10,6 @@ With algorithms contributed by Francesco Musiani (University of Bologna, Italy)
 This program is released under the GNU General Public License version 2.
 '''
 
 This program is released under the GNU General Public License version 2.
 '''
 
-import libhookecurve as lhc
-
 import scipy
 import numpy
 import xml.dom.minidom
 import scipy
 import numpy
 import xml.dom.minidom
@@ -20,6 +18,8 @@ import os.path
 import string
 import csv
 
 import string
 import csv
 
+from . import libhookecurve as lhc
+
 HOOKE_VERSION=['0.8.3_devel', 'Seinei', '2008-04-16']
 WX_GOOD=['2.6','2.8']
 
 HOOKE_VERSION=['0.8.3_devel', 'Seinei', '2008-04-16']
 WX_GOOD=['2.6','2.8']
 
@@ -106,8 +106,13 @@ class PlaylistXML(object):
                 new_playlist=[]
                 for myfile in list_of_files:
                     #rebuild a data structure from the xml attributes
                 new_playlist=[]
                 for myfile in list_of_files:
                     #rebuild a data structure from the xml attributes
-                    the_curve=lhc.HookeCurve(myfile.getAttribute('path'))
-                    for attribute in myfile.attributes.keys(): #extract attributes for the single curve
+                    the_curve=lhc.HookeCurve(
+                        os.path.join(os.path.dirname(self.playpath),
+                                     myfile.getAttribute('path')))
+                    for attribute in myfile.attributes.keys():
+                        #extract attributes for the single curve
+                        if attribute == 'path':
+                            continue # we already added this attribute
                         the_curve.__dict__[attribute]=myfile.getAttribute(attribute)
                     new_playlist.append(the_curve)
 
                         the_curve.__dict__[attribute]=myfile.getAttribute(attribute)
                     new_playlist.append(the_curve)
 
@@ -129,6 +134,11 @@ class PlaylistXML(object):
             self.playlist.writexml(outfile,indent='\n')
             outfile.close()
 
             self.playlist.writexml(outfile,indent='\n')
             outfile.close()
 
+def config_file_path(filename, config_dir=None):
+    if config_dir == None:
+        config_dir = os.path.abspath(
+            os.path.join(os.path.dirname(os.path.dirname(__file__)), 'conf'))
+    return os.path.join(config_dir, filename)
 
 class HookeConfig(object):
     '''
 
 class HookeConfig(object):
     '''
@@ -142,18 +152,14 @@ class HookeConfig(object):
 
     def __init__(self, config_dir=None):
         self.config={}
 
     def __init__(self, config_dir=None):
         self.config={}
+        self.config['install']={}
         self.config['plugins']=[]
         self.config['drivers']=[]
         self.config['plotmanips']=[]
         self.config_dir = config_dir
         self.config['plugins']=[]
         self.config['drivers']=[]
         self.config['plotmanips']=[]
         self.config_dir = config_dir
-       if self.config_dir == None:
-            self.config_dir = os.path.abspath(
-               os.path.join(os.path.dirname(os.path.dirname(__file__)),
-                            'conf'))
 
     def load_config(self, filename):
 
     def load_config(self, filename):
-        print 'loading config file', os.path.join(self.config_dir, filename)
-        myconfig=file(os.path.join(self.config_dir, filename))
+        myconfig=file(config_file_path(filename, config_dir=self.config_dir))
 
         #the following 3 lines are needed to strip newlines. otherwise, since newlines
         #are XML elements too, the parser would read them (and re-save them, multiplying
 
         #the following 3 lines are needed to strip newlines. otherwise, since newlines
         #are XML elements too, the parser would read them (and re-save them, multiplying
@@ -175,19 +181,27 @@ class HookeConfig(object):
             return rc
 
         def handleConfig(config):
             return rc
 
         def handleConfig(config):
+            install_elements=config.getElementsByTagName("install")
             display_elements=config.getElementsByTagName("display")
             plugins_elements=config.getElementsByTagName("plugins")
             drivers_elements=config.getElementsByTagName("drivers")
             display_elements=config.getElementsByTagName("display")
             plugins_elements=config.getElementsByTagName("plugins")
             drivers_elements=config.getElementsByTagName("drivers")
-            workdir_elements=config.getElementsByTagName("workdir")
             defaultlist_elements=config.getElementsByTagName("defaultlist")
             plotmanip_elements=config.getElementsByTagName("plotmanips")
             defaultlist_elements=config.getElementsByTagName("defaultlist")
             plotmanip_elements=config.getElementsByTagName("plotmanips")
+            handleInstall(install_elements)
             handleDisplay(display_elements)
             handlePlugins(plugins_elements)
             handleDrivers(drivers_elements)
             handleDisplay(display_elements)
             handlePlugins(plugins_elements)
             handleDrivers(drivers_elements)
-            handleWorkdir(workdir_elements)
             handleDefaultlist(defaultlist_elements)
             handlePlotmanip(plotmanip_elements)
 
             handleDefaultlist(defaultlist_elements)
             handlePlotmanip(plotmanip_elements)
 
+        def handleInstall(install_elements):
+            for install in install_elements:
+                for node in install.childNodes:
+                    if node.nodeType == node.TEXT_NODE:
+                        continue
+                    path = os.path.abspath(getText(node.childNodes).strip())
+                    self.config['install'][str(node.tagName)] = path
+
         def handleDisplay(display_elements):
             for element in display_elements:
                 for attribute in element.attributes.keys():
         def handleDisplay(display_elements):
             for element in display_elements:
                 for attribute in element.attributes.keys():
@@ -214,13 +228,6 @@ class HookeConfig(object):
                 except: #if we allow fancy formatting of xml, there is a text node, so tagName fails for it...
                     pass
 
                 except: #if we allow fancy formatting of xml, there is a text node, so tagName fails for it...
                     pass
 
-        def handleWorkdir(workdir):
-            '''
-            default working directory
-            '''
-            wdir=getText(workdir[0].childNodes)
-            self.config['workdir']=wdir.strip()
-
         def handleDefaultlist(defaultlist):
             '''
             default playlist
         def handleDefaultlist(defaultlist):
             '''
             default playlist