[Mumps2Py:] [74] added the beginning of a configuration system for Mumps to Python conversion .

[ Thread Index | Date Index | More lists.mumps2py.org/discuss Archives ]


Revision: 74
Author:   pgallot
Date:     2008-01-31 21:39:41 +0000 (Thu, 31 Jan 2008)

Log Message:
-----------
added the beginning of a configuration system for Mumps to Python conversion.  An m2p file points to an input file, and has filter rules for what routines to include or exclude from translation/analysis. 

Modified Paths:
--------------
    trunk/mumps2py/mumps2py_config.py


Modified: trunk/mumps2py/mumps2py_config.py
===================================================================
--- trunk/mumps2py/mumps2py_config.py	2008-01-31 21:35:10 UTC (rev 73)
+++ trunk/mumps2py/mumps2py_config.py	2008-01-31 21:39:41 UTC (rev 74)
@@ -1,3 +1,89 @@
-"""
-mumps2py_config contains all code for reading and writing any configuration
+# Copyright 2008 Patrick Gallot
+
+##    This file is part of Mumps2Py.
+##
+##    Mumps2Py is free software: you can redistribute it and/or modify
+##    it under the terms of the GNU General Public License as published by
+##    the Free Software Foundation, either version 3 of the License, or
+##    (at your option) any later version.
+##
+##    Mumps2Py is distributed in the hope that it will be useful,
+##    but WITHOUT ANY WARRANTY; without even the implied warranty of
+##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##    GNU General Public License for more details.
+##
+##    You should have received a copy of the GNU General Public License
+##    along with Mumps2Py.  If not, see <http://www.gnu.org/licenses/>.
+
+"""mumps2py_config contains all code for reading and writing any configuration
 settings related to mumps2py's translation of Mumps code to Python."""
+import ConfigParser
+
+def create_m2p_file(m2p_fname, input_fname, output_dir = None):
+    """ creates a new m2p file."""
+    config = ConfigParser.ConfigParser()
+    config.set("DEFAULT", "in_filter_id", 0)
+    config.set("DEFAULT", "out_filter_id", 0)
+    config.add_section("input")
+    config.add_section("output")
+    config.add_section("filter_in")
+    config.add_section("filter_out")
+    config.set("input", "file", input_fname)
+    if output_dir:
+        config.set("output", "dir", output_dir)
+    else:
+        config.set("output", "dir", "./out")
+    m2p_file = open(m2p_fname, 'w+')
+    config.write(m2p_file)
+    m2p_file.close()
+
+def add_m2p_filter_out_rule(m2p_fname, rule):
+    """ adds a new exclusion filter rule to an m2p filter"""
+    config = ConfigParser.ConfigParser()
+    config.read(m2p_fname)
+
+    out_filter_id = config.getint("DEFAULT", "out_filter_id")
+    new_id = out_filter_id + 1
+    rule_id = "rule_%d" % new_id
+
+    config.set("filter_out", rule_id, rule)
+    config.set("DEFAULT", "out_filter_id", new_id)
+    cfg_file = open(m2p_fname, 'w')
+    config.write(cfg_file)
+    cfg_file.close()
+
+def add_m2p_filter_in_rule(m2p_fname, rule):
+    """ adds a new inclusion filter rule to an m2p filter"""
+    config = ConfigParser.ConfigParser()
+    config.read(m2p_fname)
+
+    in_filter_id = config.getint("DEFAULT", "in_filter_id")
+    new_id = in_filter_id + 1
+    rule_id = "rule_%d" % new_id
+
+    config.set("filter_in", rule_id, rule)
+    config.set("DEFAULT", "in_filter_id", new_id)
+    cfg_file = open(m2p_fname, 'w')
+    config.write(cfg_file)
+    cfg_file.close()
+
+def get_m2p_info(m2p_fname):
+    """extracts the info from an m2p file into a dictionary"""
+    config = ConfigParser.ConfigParser()
+    config.read(m2p_fname)
+    info = {}
+
+    info['inputfile'] = config.get("input", "file")
+    info['outputdir'] = config.get("output", "dir")
+    info['filter_out'] = []
+    info['filter_in'] = []
+    
+    if config.has_section("filter_out"):
+        for rule in config.options("filter_out"):
+            info['filter_out'].append(config.get("filter_out", rule))
+
+    if config.has_section("filter_in"):
+        for rule in config.options("filter_in"):
+            info['filter_in'].append(config.get("filter_in", rule))
+
+    return info


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/