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