+ added settings parser module
authorFabio <fabio@congo.fml.local>
Wed, 10 Sep 2008 15:25:29 +0000 (17:25 +0200)
committerFabio <fabio@congo.fml.local>
Wed, 10 Sep 2008 15:25:29 +0000 (17:25 +0200)
qpalma/SettingsParser.py [new file with mode: 0644]
scripts/qpalma_pipeline.py

diff --git a/qpalma/SettingsParser.py b/qpalma/SettingsParser.py
new file mode 100644 (file)
index 0000000..cb09308
--- /dev/null
@@ -0,0 +1,71 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os 
+import os.path 
+import pdb 
+import sys 
+from optparse import OptionParser 
+jp = os.path.join
+
+def parseSettingsFile(filename):
+   """
+   """
+   global_settings = {}
+   for line in open(filename):
+      if (not line.strip()) or line.startswith('#'):
+         pass
+      else:
+         key, val = line.strip().replace(' ', '').split('=')
+         global_settings[key] = val
+
+   return global_settings
+
+
+
+def makeSettings(global_settings):
+   """
+   
+   """
+   assert os.path.exists(global_settings['result_dir']),'Error: You have to specify a existing result directory!'
+   result_dir = global_settings['result_dir']
+   global_settings['approximation_dir'] = jp(result_dir, 'approximation')
+   global_settings['preproc_dir'] = jp(result_dir, 'preprocessing')
+   global_settings['postproc_dir'] = jp(result_dir, 'postprocessing')
+   global_settings['prediction_dir'] = jp(result_dir, 'prediction')
+   global_settings['training_dir'] = jp(result_dir, 'training')
+
+   for dir_name in ['approximation_dir', 'preproc_dir', 'postproc_dir',\
+     'prediction_dir', 'training_dir']:
+      try:
+         os.mkdir(global_settings[dir_name])
+         continue
+      except:
+         print ('Error: There was a problem generating the subdirectory: %s' % dir_name)
+
+   try:
+      os.mkdir(global_settings['global_log_fn'])
+   except:
+      print ('Error: There was a problem generating the logfile %s' % global_settings['global_log_fn'])
+
+   return global_settings
+
+
+
+def checkSettings(global_settings):
+   for (key, val,) in global_settings.items():
+      if key.endswith('_fn'):
+         assert os.path.exists(val), 'Error: Path/File %s with value %s does not seem to exist!' % (key,val)
+      if key.endswith('_dir'):
+         assert os.path.exists(val), 'Error: Path/File %s with value %s does not seem to exist!' % (key,val)
+
+   return True
+
+
+
+def parseSettings(filename):
+   global_settings = parseSettingsFile(filename)
+   global_settings = makeSettings(global_settings)
+   assert checkSettings(global_settings),'Check your settings some entries were invalid!'
+
+   return global_settings
index a90c8ea..d39ab6f 100644 (file)
@@ -21,7 +21,7 @@ import sys
 from qpalma.gridtools import ApproximationTask,PreprocessingTask
 from qpalma.gridtools import AlignmentTask,PostprocessingTask
 
-from qpalma.settingsParser import parseSettings
+from qpalma.SettingsParser import parseSettings
 
 
 Errormsg = """Usage is: python qpalma_pipeline.py <config filename>"""