Package PyFoam :: Package Applications :: Module CloneCase
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.CloneCase

 1  """ 
 2  Application-class that implements pyFoamCloneCase.py 
 3  """ 
 4   
 5  from PyFoamApplication import PyFoamApplication 
 6   
 7  from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory 
 8  from PyFoam.Error import error,warning 
 9   
10  from os import path 
11   
12 -class CloneCase(PyFoamApplication):
13 - def __init__(self,args=None):
14 description=""" 15 Clones a case by copying the system, constant and 0-directories 16 """ 17 PyFoamApplication.__init__(self, 18 args=args, 19 description=description, 20 usage="%prog <source> <destination>", 21 changeVersion=False, 22 interspersed=True, 23 nr=2)
24
25 - def addOptions(self):
26 self.parser.add_option("--chemkin", 27 action="store_true", 28 dest="chemkin", 29 default=False, 30 help="Also copy the Chemkin-directory") 31 self.parser.add_option("--add-item", 32 action="append", 33 dest="additional", 34 default=[], 35 help="Add a subdirectory to the list of cloned items (can be used more often than once)") 36 self.parser.add_option("--no-pyfoam", 37 action="store_false", 38 dest="dopyfoam", 39 default=True, 40 help="Don't copy PyFoam-specific stuff") 41 self.parser.add_option("--force", 42 action="store_true", 43 dest="force", 44 default=False, 45 help="Overwrite destination if it exists")
46
47 - def run(self):
48 if len(self.parser.getArgs())>2: 49 error("Too many arguments:",self.parser.getArgs()[2:],"can not be used") 50 51 sName=self.parser.getArgs()[0] 52 dName=self.parser.getArgs()[1] 53 54 if path.exists(dName): 55 if self.parser.getOptions().force: 56 warning("Replacing",dName,"(--force option)") 57 elif path.exists(path.join(dName,"system","controlDict")): 58 error("Destination",dName,"already existing and a Foam-Case") 59 elif path.isdir(dName): 60 dName=path.join(dName,path.basename(sName)) 61 if path.exists(dName) and not self.parser.getOptions().force: 62 error(dName,"already existing") 63 elif not path.exists(path.dirname(dName)): 64 warning("Directory",path.dirname(dName),"does not exist. Creating") 65 66 sol=SolutionDirectory(sName,archive=None,paraviewLink=False) 67 68 if self.parser.getOptions().chemkin: 69 sol.addToClone("chemkin") 70 71 if self.parser.getOptions().dopyfoam: 72 sol.addToClone("customRegexp") 73 74 for a in self.parser.getOptions().additional: 75 sol.addToClone(a) 76 77 sol.cloneCase(dName)
78