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

Source Code for Module PyFoam.Applications.InitVCSCase

  1  """ 
  2  Application-class that implements pyFoamInitVCSCase.py 
  3  """ 
  4  from optparse import OptionGroup 
  5   
  6  from .PyFoamApplication import PyFoamApplication 
  7   
  8  from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory 
  9   
 10  from PyFoam.Basics.GeneralVCSInterface import getVCS 
 11   
 12  from os import path 
 13  from glob import glob 
 14   
 15  ruleList=[(False,".*\\.gz$"), 
 16            (False,".+~$")] 
 17   
18 -def addRegexpInclude(option,opt,value,parser,*args,**kwargs):
19 ruleList.append((True,value))
20
21 -def addRegexpExclude(option,opt,value,parser,*args,**kwargs):
22 ruleList.append((False,value))
23
24 -class InitVCSCase(PyFoamApplication):
25 - def __init__(self, 26 args=None, 27 **kwargs):
28 description="""\ 29 This utility initializes a Version Control System (VCS) in an 30 OpenFOAM-directory. Certain parts of PyFoam take advantages of this. 31 32 Currenty only Mercurial is supported as a VCS-backend 33 """ 34 PyFoamApplication.__init__(self, 35 args=args, 36 description=description, 37 usage="%prog <caseDirectory>", 38 interspersed=True, 39 changeVersion=False, 40 nr=1, 41 exactNr=False, 42 **kwargs)
43
44 - def addOptions(self):
45 what=OptionGroup(self.parser, 46 "What", 47 "What should be added to version control") 48 self.parser.add_option_group(what) 49 50 what.add_option("--include-files", 51 action="callback", 52 callback=addRegexpInclude, 53 type="string", 54 help="Files that should be added in instead of the usual suspects (Regular expression)") 55 what.add_option("--exclude-files", 56 action="callback", 57 callback=addRegexpExclude, 58 type="string", 59 help="Files that should not be added (regular expression)") 60 what.add_option("--additional", 61 action="append", 62 dest="additional", 63 default=[], 64 help="Additional files and directories to be added") 65 66 vcs=OptionGroup(self.parser, 67 "VCS System", 68 "Control the source-control system") 69 self.parser.add_option_group(vcs) 70 71 vcs.add_option("--no-init", 72 action="store_false", 73 default=True, 74 dest="init", 75 help="Don't initialize the repository (assumes that it is already under source control)") 76 77 self.vcsChoices=["hg"] 78 vcs.add_option("--vcs", 79 type="choice", 80 default="hg", 81 dest="vcs", 82 action="store", 83 choices=self.vcsChoices, 84 help="Which VCS should be used (Choices: "+", ".join(self.vcsChoices)+") Default: %default") 85 86 how=OptionGroup(self.parser, 87 "Behaviour", 88 "What should be done") 89 self.parser.add_option_group(vcs) 90 91 vcs.add_option("--commit-message", 92 action="store", 93 default="Initial commit", 94 dest="commitMessage", 95 help="Message that should be added to the initial commit")
96
97 - def run(self):
98 sol=SolutionDirectory(self.parser.getArgs()[0]) 99 if not self.opts.init: 100 vcs=sol.determineVCS() 101 if vcs==None: 102 self.error("not under version control") 103 if not vcs in self.vcsChoices: 104 self.error("Unsupported VCS",vcs) 105 else: 106 vcs=self.opts.vcs 107 108 vcsInter=getVCS(vcs, 109 path=sol.name, 110 init=self.opts.init) 111 112 vcsInter.addPath(path.join(sol.name,"constant"),rules=ruleList) 113 vcsInter.addPath(path.join(sol.name,"system"),rules=ruleList) 114 if sol.initialDir()!=None: 115 vcsInter.addPath(sol.initialDir(),rules=ruleList) 116 else: 117 self.warning("No initial-directory found") 118 119 # special PyFoam-files 120 for f in ["customRegexp","LocalConfigPyFoam"]: 121 p=path.join(sol.name,f) 122 if path.exists(p): 123 vcsInter.addPath(p,rules=ruleList) 124 125 # Add the usual files from the tutorials 126 for g in ["Allrun*","Allclean*"]: 127 for f in glob(path.join(sol.name,g)): 128 vcsInter.addPath(f,rules=ruleList) 129 130 for a in self.opts.additional: 131 vcsInter.addPath(a,rules=ruleList) 132 133 vcsInter.commit(self.opts.commitMessage)
134 135 # Should work with Python3 and Python2 136