Package PyFoam :: Package Basics :: Module HgInterface
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Basics.HgInterface

  1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Basics/HgInterface.py 7885 2012-02-26T19:32:53.603570Z bgschaid  $  
  2  """A VCS-interface to Mercurial""" 
  3   
  4  from PyFoam.Error import warning,error 
  5   
  6  from GeneralVCSInterface import GeneralVCSInterface 
  7   
  8  from os import uname 
  9  from os import path as opath 
 10  from mercurial import commands,ui,hg 
 11  from mercurial.node import short 
 12   
13 -class HgInterface(GeneralVCSInterface):
14 """The interface class to mercurial""" 15
16 - def __init__(self, 17 path, 18 init=False):
19 20 GeneralVCSInterface.__init__(self,path,init) 21 22 if init: 23 commands.init(ui.ui(),self.path) 24 open(opath.join(self.path,".hgignore"),"w").write("syntax: re\n\n") 25 26 self.repo=hg.repository(ui.ui(),self.path) 27 self.ui=self.repo.ui 28 29 if init: 30 self.addPath(opath.join(self.repo.root,".hgignore")) 31 self.addStandardIgnores()
32
33 - def getRoot(self,path):
34 return self.executeWithOuput("hg root --cwd %s" % path)
35
36 - def addPath(self, 37 path, 38 rules=[]):
39 try: 40 if not opath.exists(path): 41 error("Path",path,"does not exist") 42 except TypeError: 43 error(path,"is not a path name") 44 45 include=[] 46 exclude=[] 47 if rules!=[]: 48 for inclQ,patt in rules: 49 if inclQ: 50 include.append("re:"+patt) 51 else: 52 exclude.append("re:"+patt) 53 54 commands.add(self.ui, 55 self.repo, 56 path, 57 include=include, 58 exclude=exclude)
59
60 - def clone(self, 61 dest):
62 commands.clone(self.ui, 63 self.repo, 64 dest)
65
66 - def branchName(self):
67 return self.repo.dirstate.branch()
68
69 - def getRevision(self):
70 ctx = self.repo[None] 71 parents = ctx.parents() 72 return '+'.join([short(p.node()) for p in parents])
73
74 - def commit(self, 75 msg):
76 commands.commit(self.ui, 77 self.repo, 78 message=msg)
79
80 - def update(self, 81 timeout=None):
82 ok=True 83 if timeout: 84 self.ui.setconfig("ui","timeout",timeout); 85 86 try: 87 if commands.pull(self.ui, 88 self.repo): 89 ok=False 90 if commands.update(self.ui, 91 self.repo): 92 ok=False 93 except IndexError,e: 94 # except Exception,e: 95 raise e 96 return False 97 98 return ok
99
100 - def addGlobToIgnore(self,expr):
101 self.addToHgIgnore("glob:"+expr)
102
103 - def addRegexpToIgnore(self,expr):
104 self.addToHgIgnore("re:"+expr)
105
106 - def addToHgIgnore(self,expr):
107 open(opath.join(self.repo.root,".hgignore"),"a").write(expr+"\n")
108