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