1 """ Utility functions
2
3 Can be used via a class or as functions"""
4
5 from os import popen4
6 from os import listdir
7
8 import re
9
11 """Class with utility methods
12
13 Can be inherited without side effects by classes that need these
14 methods"""
15
17 pass
18
20 """Execute the command cmd
21
22 Currently no error-handling is done
23 @return: A list with all the output-lines of the execution"""
24 if debug:
25 print cmd
26
27 rein,raus=popen4(cmd)
28 tmp=raus.readlines()
29
30
31
32
33
34 return tmp
35
37 """Writes a dummy header so OpenFOAM accepts the file as a dictionary
38 @param f: The file to write to
39 @type f: file"""
40
41 f.write("""
42 // * * * * * * * * * //
43 FoamFile
44 {
45 version 0.5;
46 format ascii;
47 root "ROOT";
48 case "CASE";
49 class dictionary;
50 object nix;
51 }
52 """)
53
54 excludeNames=["^.svn$" , "~$"]
55
57 """Lists the files in a directory, but excludes certain names
58 and files with certain endings
59 @param d: The directory to list
60 @return: List of the found files and directories"""
61
62 result=[]
63
64 excludes=map(re.compile,self.excludeNames)
65
66 for n in listdir(d):
67 ok=True
68
69 for e in excludes:
70 if e.search(n):
71 ok=False
72 break
73
74 if ok:
75 result.append(n)
76
77 return result
78
80 """Calls the method of the same name from the Utilites class"""
81 return Utilities().execute(cmd,debug)
82
86
90