예제 #1
0
def foamInstalledVersions():
    """@return: A list with the installed versions of OpenFOAM"""

    versions=set()

    valid=re.compile("^OpenFOAM-([0-9]\.[0-9].*)$")
    valid2=re.compile("^openfoam(1[0-9]+)$")

    if environ.has_key("WM_PROJECT_INST_DIR"):
        basedir=environ["WM_PROJECT_INST_DIR"]
    else:
        basedir=path.expanduser(config().get("OpenFOAM","Installation"))

    if not path.exists(basedir) or not path.isdir(basedir):
        warning("Basedir",basedir,"does not exist or is not a directory")
        return []

    for bdir in [basedir]+config().getList("OpenFOAM","AdditionalInstallation"):
        for val in [valid,valid2]:
            versions |= findInstalledVersions(bdir,val)

    return list(versions)
예제 #2
0
def changeFoamVersion(new,force64=False,force32=False,compileOption=None):
    """Changes the used FoamVersion. Only valid during the runtime of
    the interpreter (the script or the Python session)
    @param new: The new Version
    @param force64: Forces the 64-bit-version to be chosen
    @param force32: Forces the 32-bit-version to be chosen
    @param compileOption: Forces Debug or Opt"""

    if not new in foamInstalledVersions():
        error("Version",new,"is not an installed version: ",foamInstalledVersions())

    old=None
    if environ.has_key("WM_PROJECT_VERSION"):
        old=environ["WM_PROJECT_VERSION"]
        if new==old:
            warning(new,"is already being used")
    else:
        warning("No OpenFOAM-Version installed")
        
    basedir,prefix=findBaseDir(new)

    if path.exists(path.join(basedir,prefix+new,"etc")):
        script=path.join(basedir,prefix+new,"etc","bashrc")
    else:
        script=path.join(basedir,prefix+new,".OpenFOAM-"+new,"bashrc")

    forceArchOption=None
    if force64:
       forceArchOption="64"
    elif force32:
       forceArchOption="32"

    injectVariables(script,
                    forceArchOption=forceArchOption,
                    compileOption=compileOption)
    
    try:
        if old==environ["WM_PROJECT_VERSION"]:
            warning("Problem while changing to version",new,"old version still used:",environ["WM_PROJECT_VERSION"])
    except KeyError:
        pass