Package moap :: Package vcs :: Module cvs
[hide private]
[frames] | no frames]

Source Code for Module moap.vcs.cvs

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  """ 
  5  CVS functionality. 
  6  """ 
  7   
  8  import os 
  9  import re 
 10  import commands 
 11   
 12  import vcs 
 13   
 14  from moap.util import util 
 15   
16 -def detect(path):
17 """ 18 Detect which version control system is being used in the source tree. 19 20 @return: True if the given path looks like a CVS tree. 21 """ 22 if not os.path.exists(os.path.join(path, 'CVS')): 23 return False 24 25 for n in ['Entries', 'Repository', 'Root']: 26 if not os.path.exists(os.path.join(path, 'CVS', n)): 27 return False 28 29 return True
30
31 -class CVS(vcs.VCS):
32 name = 'CVS' 33
34 - def getUnknown(self, path):
35 ret = [] 36 oldPath = os.getcwd() 37 38 # FIXME: the only way I know of to get the list of unignored files 39 # is to do cvs update, which of course has a side effect 40 os.chdir(path) 41 cmd = "cvs update" 42 43 output = commands.getoutput(cmd) 44 lines = output.split("\n") 45 matcher = re.compile('^\?\s+(.*)') 46 for l in lines: 47 m = matcher.search(l) 48 if m: 49 path = m.expand("\\1") 50 ret.append(path) 51 52 # FIXME: would be nice to sort per directory 53 os.chdir(oldPath) 54 return ret
55
56 - def ignore(self, paths, commit=True):
57 # cvs ignores entries by appending to a .cvsignore file in the parent 58 oldPath = os.getcwd() 59 os.chdir(self.path) 60 61 tree = self.createTree(paths) 62 toCommit = [] 63 for path in tree.keys(): 64 # this does the right thing if path == '' 65 cvsignore = os.path.join(path, '.cvsignore') 66 toCommit.append(cvsignore) 67 68 new = False 69 if not os.path.exists(cvsignore): 70 new = True 71 72 handle = open(cvsignore, "a") 73 74 for child in tree[path]: 75 handle.write('%s\n' % child) 76 77 handle.close() 78 79 if new: 80 cmd = "cvs add %s" % cvsignore 81 os.system(cmd) 82 83 # FIXME: also commit .cvsignore flies when done. Should we make 84 # this part of the interface ? 85 if commit and toCommit: 86 cmd = "cvs commit -m 'moap ignore' %s" % " ".join(toCommit) 87 os.system(cmd) 88 89 os.chdir(oldPath)
90
91 - def commit(self, paths, message):
92 oldPath = os.getcwd() 93 os.chdir(self.path) 94 temp = util.writeTemp([message, ]) 95 cmd = "cvs commit -F %s %s" % (temp, " ".join(paths)) 96 os.system(cmd) 97 os.unlink(temp) 98 os.chdir(oldPath)
99
100 - def diff(self, path):
101 oldPath = os.getcwd() 102 os.chdir(self.path) 103 # CVS does not like running cvs diff with an absolute path 104 if path.startswith(self.path): 105 path = path[len(self.path) + 1:] 106 # Don't want "Diffing ..." output, and 3 lines of context 107 cmd = "cvs -q diff -u3 -N %s" % path 108 self.debug('Running command %s' % cmd) 109 output = commands.getoutput(cmd) 110 os.chdir(oldPath) 111 return output
112
113 - def update(self, path):
114 cmd = "cvs update %s" % path 115 status, output = commands.getstatusoutput(cmd) 116 return output
117 118 VCSClass = CVS 119