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