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 what.add_option("--latest-time", 49 action="store_true", 50 dest="latest", 51 default=[], 52 help="Add the latest time-step") 53 54 behave=OptionGroup(self.parser, 55 "Behaviour") 56 self.parser.add_option_group(behave) 57 behave.add_option("--force", 58 action="store_true", 59 dest="force", 60 default=False, 61 help="Overwrite destination if it exists") 62 behave.add_option("--follow-symlinks", 63 action="store_true", 64 dest="followSymlinks", 65 default=False, 66 help="Follow symlinks instead of just copying them")
67
68 - def run(self):
69 if len(self.parser.getArgs())>2: 70 error("Too many arguments:",self.parser.getArgs()[2:],"can not be used") 71 72 sName=self.parser.getArgs()[0] 73 dName=self.parser.getArgs()[1] 74 75 if path.exists(dName): 76 if self.parser.getOptions().force: 77 warning("Replacing",dName,"(--force option)") 78 elif path.exists(path.join(dName,"system","controlDict")): 79 error("Destination",dName,"already existing and a Foam-Case") 80 elif path.isdir(dName): 81 dName=path.join(dName,path.basename(sName)) 82 if path.exists(dName) and not self.parser.getOptions().force: 83 error(dName,"already existing") 84 elif not path.exists(path.dirname(dName)): 85 warning("Directory",path.dirname(dName),"does not exist. Creating") 86 87 sol=SolutionDirectory(sName,archive=None,paraviewLink=False) 88 89 if self.parser.getOptions().chemkin: 90 sol.addToClone("chemkin") 91 92 if self.parser.getOptions().dopyfoam: 93 sol.addToClone("customRegexp") 94 95 for a in self.parser.getOptions().additional: 96 sol.addToClone(a) 97 98 if self.parser.getOptions().latest: 99 sol.addToClone(sol.getLast()) 100 101 sol.cloneCase( 102 dName, 103 followSymlinks=self.parser.getOptions().followSymlinks 104 ) 105 106 self.addToCaseLog(dName,"Cloned to",dName)
107