expose_configuration.py :  » Development » MPI-Python » pyMPI-2.5b0 » utils » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » MPI Python 
MPI Python » pyMPI 2.5b0 » utils » expose_configuration.py
#**************************************************************************#
#* FILE   **************  expose_configuration.py  ************************#
#**************************************************************************#
#* Author: Patrick Miller January 16 2003                                 *#
#**************************************************************************#
"""
Walk through the #defines in the autoconf/automake file and expose
each item as an integer, float, or string
"""

import sys
import re

#sys.stdout = sys.stderr

config_file = sys.argv[1]

def cstring(s):
    return '"'+repr(s)[1:-1].replace('"','\\\"').replace("'",'\\\'')+'"'

# -----------------------------------------------
# Pull #define values out of config.h file
# -----------------------------------------------
pattern = re.compile(r'#define\s+(\S+)\s+(.*)')
last_comment = ''
definitions = {}
for line in open(config_file).xreadlines():
    if line.startswith('/*'):
        last_comment = line[3:-4]
    elif line.startswith('#define'):
        # Parse out the name and value
        match = pattern.match(line)
        name = match.group(1)
        if match.group(2):
            value = eval(match.group(2))
        else:
            value = None
        definitions[name] = (value,last_comment)
        last_comment = ''

# -----------------------------------------------
# Build the configuration file
# -----------------------------------------------
print r'''
/**************************************************************************/
/* FILE ****************  pyMPI_configuration.c ***************************/
/**************************************************************************/
/* Author: Machine generated                                              */
/**************************************************************************/

#include "mpi.h"
#undef _POSIX_C_SOURCE
#include "Python.h"
#include "pyMPI.h"
#include "pyMPI_Macros.h"

START_CPLUSPLUS

/**************************************************************************/
/* GLOBAL **************  pyMPI_configuration_fini ************************/
/**************************************************************************/
/* No global state to clean up here.  Just used to fulfill the contract   */
/* with the PLUGIN macro.                                                 */
/**************************************************************************/
void pyMPI_configuration_fini(void) {
}

/**************************************************************************/
/* LOCAL  **************     increment_refcount    ************************/
/**************************************************************************/
/* This simply is used to adapt to the model of the PARAMETER macro which */
/* expects its "converter" argument to return an owned reference to the   */
/* first argument.  When that argument is a borrowed reference (as here   */
/* where the Py_None singleton is passed in as the parameter), we need to */
/* INCREF it.                                                             */
/**************************************************************************/
static PyObject* increment_refcount(PyObject* x) {
  Py_XINCREF(x);
  return x;
}

/**************************************************************************/
/* GLOBAL **************  pyMPI_configuration_init ************************/
/**************************************************************************/
/* This builds a submodule (mpi.configuration) which is populated with    */
/* the values set in pyMPI_Config.h.  This includes useful information    */
/* like the flags and compilers used to build pyMPI.  This is more direct */
/* and more complete than what we can patch into distutils.               */
/**************************************************************************/
void pyMPI_configuration_init(PyObject** docStringP) {
   PyObject* configuration = 0;
   PyObject* configuration_dictionary = 0;
   PyObject* doc_string = 0;
   static PyMethodDef configuration_methods[] = {{0,0}};

   PYCHECK( configuration /*owned*/ = Py_InitModule("mpi.configuration",
                                                     configuration_methods) );
   PYCHECK( configuration_dictionary /*borrowed*/ = PyModule_GetDict(configuration) );
   PYCHECK( doc_string /*owned*/ = PyString_FromString("pyMPI configuration information\n\nConfiguration information\n\n") );
'''
keys = definitions.keys()
keys.sort()
for key in keys:
    value,comment = definitions[key]
    macro = key
    if isinstance(value,int):
        converter = 'PyInt_FromLong'
    elif isinstance(value,str):
        converter = 'PyString_FromString'
    elif isinstance(value,float):
        converter = 'PyInt_FromLong'
    elif value is None:
        converter = 'increment_refcount'
        macro = 'Py_None'
    else:
        raise key,value
    print '   PARAMETER(%s,"%s",%s,%s,configuration_dictionary,&doc_string);'%(
        macro,key,cstring(comment),converter)

print
print '   PYCHECK( PyDict_SetItemString(configuration_dictionary,"__doc__",doc_string) );'
print '   PYCHECK( PyDict_SetItemString(pyMPI_dictionary,"configuration",configuration) );'
print '   return;'
print ''
print ' pythonError:'
print '   Py_XDECREF(configuration);'
print '   Py_XDECREF(doc_string);'
print '   return;'
print '}'

print
print 'END_CPLUSPLUS'


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.