1
2 """Getting Information about the Foam-Installation (like the installation directory)"""
3
4 from os import environ,path,listdir
5 from popen2 import popen4
6
7 import re
8
9 from Error import error,warning
10
12 """Gets a path from an environment variable
13 @return: the path
14 @rtype: string
15 @param name: the name of the environment variable"""
16
17 tmp=""
18 if environ.has_key(name):
19 tmp=path.normpath(environ[name])
20
21 return tmp
22
24 """@return: directory in which the tutorials reside"""
25
26 return getPathFromEnviron("FOAM_TUTORIALS")
27
29 """@return the used MPI-Implementation"""
30 if not environ.has_key("WM_MPLIB"):
31 return ()
32 else:
33 vStr=environ["WM_MPLIB"]
34 return vStr
35
37 """@return: tuple that represents the Foam-version as found
38 in $WM_PROJECT_VERSION"""
39
40 if not environ.has_key("WM_PROJECT_VERSION"):
41 return ()
42 else:
43 vStr=environ["WM_PROJECT_VERSION"]
44 res=[]
45
46 for el in vStr.split("."):
47 for e in el.split("-"):
48 try:
49 res.append(int(e))
50 except:
51 res.append(e)
52
53 return tuple(res)
54
56 """@return: tuple that represents the Foam-Version-Number (without
57 strings"""
58
59 ver=foamVersion()
60
61 nr=[]
62
63 for e in ver:
64 if type(e)==int:
65 nr.append(e)
66 else:
67 break
68
69 return tuple(nr)
70
72 """@return: A list with the installed versions of OpenFOAM"""
73
74 versions=[]
75
76 valid=re.compile("^OpenFOAM-([0-9]\.[0-9].*)$")
77
78 for f in listdir(environ["WM_PROJECT_INST_DIR"]):
79 m=valid.match(f)
80 if m:
81 versions.append(m.groups(1)[0])
82
83 return versions
84
86 """Changes the used FoamVersion. Only valid during the runtime of
87 the interpreter (the script or the Python session)
88 @param new: The new Version"""
89
90 if not new in foamInstalledVersions():
91 error("Version",new,"is not an installed version: ",foamInstalledVersions())
92
93 if new==environ["WM_PROJECT_VERSION"]:
94 warning(new,"is already being used")
95 return
96
97 try:
98 if(path.basename(environ["SHELL"])!="bash"):
99 error("Currently only implemented for bash-shell, not for",environ["shell"])
100
101 cmd=". "+path.join(environ["WM_PROJECT_INST_DIR"],"OpenFOAM-"+new,".OpenFOAM-"+new,"bashrc")+'; echo "Starting The Dump Of Variables"; export'
102 except KeyError,name:
103 error("Can't do it, because shell variable",name,"is undefined")
104
105 raus,rein = popen4(cmd)
106 lines=raus.readlines()
107 rein.close()
108 raus.close()
109
110 exp=re.compile('export (.+)="(.*)"\n')
111
112 cnt=0
113
114 for l in lines:
115 m=exp.match(l)
116 if m:
117 cnt+=1
118 environ[m.groups()[0]]=m.groups()[1]
119
120 if new!=environ["WM_PROJECT_VERSION"]:
121 error("Problem while changing to version",new,"old version still used:",environ["WM_PROJECT_VERSION"])
122