8.10.2 Functions defined in the utils module

congratulations( name,version,typ='module',fatal=False)
Report a detected module/program.

checkVersion( name,version,external=False)
Checks a version of a program/module.

name is either a module or an external program whose availability has been registered. Default is to treat name as a module. Add external=True for a program.

Return value is -1, 0 or 1, depending on a version found that is <, == or > than the requested values. This should normally understand version numbers in the format 2.10.1

checkModule( name)
Check if the named Python module is available, and record its version.

The version string is returned, empty if the module could not be loaded. The (name,version) pair is also inserted into the the_version dict.

hasModule( name,check=False)
Test if we have the named module available.

Returns a nonzero (version) string if the module is available, or an empty string if it is not.

By default, the module is only checked on the first call. The result is remembered in the the_version dict. The optional argument check==True forces a new detection.

checkExternal( name=None,command=None,answer=None)
Check if the named external command is available on the system.

name is the generic command name, command is the command as it will be executed to check its operation, answer is a regular expression to match positive answers from the command. answer should contain at least one group. In case of a match, the contents of the match will be stored in the the_external dict with name as the key. If the result does not match the specified answer, an empty value is inserted.

Usually, command will contain an option to display the version, and the answer re contains a group to select the version string from the result.

As a convenience, we provide a list of predeclared external commands, that can be checked by their name alone. If no name is given, all commands in that list are checked, and no value is returned.

hasExternal( name)
Test if we have the external command 'name' available.

Returns a nonzero string if the command is available, or an empty string if it is not.

The external command is only checked on the first call. The result is remembered in the the_external dict.

reportDetected( )

removeTree( path,top=True)
Remove all files below path. If top==True, also path is removed.

setSaneLocale( )
Set a sane local configuration for LC_NUMERIC.

Some local settings change the LC_NUMERIC setting, so that floating point values are read or written with a comma instead of a the decimal point. Of course this makes your files completely incompatible. You will often not be able to process these files any further and create a lot of troubels for yourself and other people if you do so. The idiots that thought changing the LC_NUMERIC locale was a good thing should be hung.

Anyway, here's a function to set it back to a sane value. It is always called when pyFormex starts.

all_image_extensions( )
Return a list with all known image extensions.

fileDescription( type)
Return a description of the specified file type.

The description of known types are listed in a dict file_description. If the type is unknown, the returned string has the form 'TYPE files (*.type)'

findIcon( name)
Return the file name for an icon with given name.

If no icon file is found, returns the question mark icon.

projectName( fn)
Derive a project name from a file name.

The project name is the basename f the file without the extension.

splitme( s)

mergeme( s1,s2)

mtime( fn)
Return the (UNIX) time of last change of file fn.

countLines( fn)
Return the number of lines in a text file.

runCommand( cmd,RaiseError=True,quiet=False)
Run a command and raise error if exited with error.

spawn( cmd)
Spawn a child process.

changeExt( fn,ext)
Change the extension of a file name.

The extension is the minimal trailing part of the filename starting with a '.'. If the filename has no '.', the extension will be appended. If the given extension does not start with a dot, one is prepended.

tildeExpand( fn)
Perform tilde expansion on a filename.

Bash, the most used command shell in Linux, expands a ' ' in arguments to the users home direction. This function can be used to do the same for strings that did not receive the bash tilde expansion, such as strings in the configuration file.

isPyFormex( filename)
Checks whether a file is a pyFormex script.

A script is considered to be a pyFormex script if its first line starts with '#!' and contains the substring 'pyformex' A file is considered to be a pyFormex script if its name ends in '.py' and the first line of the file contains the substring 'pyformex'. Typically, a pyFormex script starts with a line: #!/usr/bin/env pyformex

splitEndDigits( s)
Split a string in any prefix and a numerical end sequence.

A string like 'abc-0123' will be split in 'abc-' and '0123'. Any of both can be empty.

stuur( x,xval,yval,exp=2.5)
Returns a (non)linear response on the input x.

xval and yval should be lists of 3 values: [xmin,x0,xmax], [ymin,y0,ymax]. Together with the exponent exp, they define the response curve as function of x. With an exponent > 0, the variation will be slow in the neighbourhood of (x0,y0). For values x < xmin or x > xmax, the limit value ymin or ymax is returned.

interrogate( item)
Print useful information about item.

deprecation( message)

deprecated( replacement)

functionWasRenamed( replacement,text=None)

functionBecameMethod( replacement)