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

Source Code for Module PyFoam.Applications.PackCase

  1  """ 
  2  Application-class that implements pyFoamPackCase.py 
  3  """ 
  4   
  5  from PyFoamApplication import PyFoamApplication 
  6   
  7  from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory 
  8   
  9  from os import path 
 10  from optparse import OptionGroup 
 11   
12 -class PackCase(PyFoamApplication):
13 - def __init__(self,args=None):
14 description="""\ 15 Packs a case into a tar-file copying the system, constant and 16 0-directories. Excludes all .svn-direcotries and all files ending 17 with ~ 18 """ 19 PyFoamApplication.__init__(self, 20 args=args, 21 description=description, 22 usage="%prog <case>", 23 interspersed=True, 24 changeVersion=False, 25 nr=1)
26
27 - def addOptions(self):
28 what=OptionGroup(self.parser, 29 "What", 30 "Define what should be packed") 31 self.parser.add_option_group(what) 32 33 what.add_option("--last", 34 action="store_true", 35 dest="last", 36 default=False, 37 help="Also add the last time-step") 38 what.add_option("--pyfoam", 39 action="store_true", 40 dest="pyfoam", 41 default=False, 42 help="Add all files starting with PyFoam to the tarfile") 43 what.add_option("--chemkin", 44 action="store_true", 45 dest="chemkin", 46 default=False, 47 help="Also add the Chemkin-directory") 48 what.add_option("--add", 49 action="append", 50 dest="additional", 51 default=[], 52 help="Add all files and directories in the case directory that fit a glob-pattern to the tar (can be used more than once)") 53 what.add_option("--exclude", 54 action="append", 55 dest="exclude", 56 default=[], 57 help="Exclude all files and directories that fit this glob pattern from being added, no matter at level (can be used more than once)") 58 what.add_option("--no-polyMesh", 59 action="store_true", 60 dest="noPloyMesh", 61 help="Exclude the polyMesh-directory") 62 self.parser.add_option("--tarname", 63 action="store", 64 dest="tarname", 65 default=None, 66 help='Name of the tarfile. If unset the name of the case plus ".tgz" will be used') 67 self.parser.add_option("--base-name", 68 action="store", 69 dest="basename", 70 default=None, 71 help='Name of the case inside the tar-file. If not set the actual basename of the case is used')
72
73 - def run(self):
74 sName=self.parser.getArgs()[0] 75 if sName[-1]==path.sep: 76 sName=sName[:-1] 77 78 if self.parser.getOptions().tarname!=None: 79 dName=self.parser.getOptions().tarname 80 else: 81 dName=sName+".tgz" 82 if self.parser.getOptions().pyfoam: 83 self.parser.getOptions().additional.append("PyFoam*") 84 85 sol=SolutionDirectory(sName,archive=None,paraviewLink=False) 86 if not sol.isValid(): 87 self.error(sName,"does not look like real OpenFOAM-case because",sol.missingFiles(),"are missing or of the wrong type") 88 89 if self.parser.getOptions().chemkin: 90 sol.addToClone("chemkin") 91 92 if self.opts.noPloyMesh: 93 self.parser.getOptions().exclude.append("polyMesh") 94 95 sol.packCase(dName, 96 last=self.parser.getOptions().last, 97 additional=self.parser.getOptions().additional, 98 exclude=self.parser.getOptions().exclude, 99 base=self.parser.getOptions().basename)
100