X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=hooke%2Flibhooke.py;h=05c9837f7e32c5bd17c74b70dad8994a29bf428f;hp=73534f2143e7331da5a077a608d0d05b54a848cb;hb=cd7b8ff4687547d3661c23180d7145d4ccc898ae;hpb=545013bfc6d3d67cb31c9d8501ba5f8a83d642f4 diff --git a/hooke/libhooke.py b/hooke/libhooke.py old mode 100755 new mode 100644 index 73534f2..05c9837 --- a/hooke/libhooke.py +++ b/hooke/libhooke.py @@ -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. ''' -import libhookecurve as lhc - import scipy import numpy import xml.dom.minidom @@ -20,6 +18,8 @@ import os.path 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'] @@ -106,8 +106,13 @@ class PlaylistXML(object): 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) @@ -129,6 +134,11 @@ class PlaylistXML(object): 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): ''' @@ -142,18 +152,14 @@ class HookeConfig(object): 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 - 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): - 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 @@ -175,19 +181,27 @@ class HookeConfig(object): 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") - workdir_elements=config.getElementsByTagName("workdir") defaultlist_elements=config.getElementsByTagName("defaultlist") plotmanip_elements=config.getElementsByTagName("plotmanips") + handleInstall(install_elements) handleDisplay(display_elements) handlePlugins(plugins_elements) handleDrivers(drivers_elements) - handleWorkdir(workdir_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(): @@ -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 - def handleWorkdir(workdir): - ''' - default working directory - ''' - wdir=getText(workdir[0].childNodes) - self.config['workdir']=wdir.strip() - def handleDefaultlist(defaultlist): ''' default playlist