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