Source code for fudge.core.fudgemisc
# <<BEGIN-copyright>>
# <<END-copyright>>
"""
This module contains useful top-level fudge routines that do not fit into any other module.
"""
import os
import sys
from fudge import fudgeParameters
[docs]def readOnly( ) :
"""Sets Fudge's internal readonly flag which causes fudge to not create working directories
for the isotopes read in. Note, you cannot unset this flag once readOnly has been called."""
fudgeParameters.ReadOnly = 1
[docs]def verbose( mode = 1 ) :
"""Sets Fudge's internal verbose flag to mode. Mode = 0 suppress all informational messages."""
fudgeParameters.VerboseMode = int( mode )
[docs]def checkMessagesToString( message, indentation = ' ', subIndentation = ' ' ) :
s = []
if( type( message ) == type( '' ) ) :
s += [ indentation + message ]
else :
for m in message :
if( type( m ) == type( '' ) ) :
s += [ indentation + m ]
elif( ( type( m ) == type( [] ) ) or ( type( m ) == type( [] ) ) ) :
if( len( m ) != 2 ) : raise Exception( 'Error in checkMessagesToString: len( m ) = %d != 2 )' % len( m ) )
s += [ indentation + m[0] ]
s += checkMessagesToString( m[1], indentation = indentation + subIndentation )
else :
raise Exception( 'Error in checkMessagesToString: invalid message type = %s' % type( m ) )
return( s )
[docs]def printWarning( s ) :
sys.stderr.write( s )
if( s[-1:] != '\n' ) : sys.stderr.write( '\n' )
[docs]def findPythonFile( file ) :
"""For internal use only."""
if( os.path.exists( file ) ) : return file
if( 'PYTHONPATH' in os.environ ) :
ps = os.environ['PYTHONPATH'].split( ":" )
for p in ps :
f = os.path.join( p, file )
if( os.path.exists( f ) ) : return f
f = os.path.join( os.path.dirname( __file__ ), file )
if( os.path.exists( f ) ) : return f
f = os.path.join( "/usr/apps/fudge/current/bin", file )
if( os.path.exists( f ) ) : return f
return None
[docs]def stringWithPrefixSuffix( list, Prefix = "", Suffix = "" ) :
"""For internal use only."""
PS = "\n"
if( len( list ) > 0 ) :
list[0] = Prefix + list[0]
list[-1] = list[-1] + Suffix + "\n"
PS = Suffix + "\n" + Prefix
list = PS.join( list )
return list