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