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

Source Code for Module PyFoam.Basics.HgInterface

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