Commit e95de3f8 authored by Stephen Kennedy's avatar Stephen Kennedy

Refactor to remove redundancy (Vincent Legoll)

svn path=/trunk/; revision=979
parent 6d379650
......@@ -122,3 +122,22 @@ class Vc(object):
def get_capabilities(self):
return 0
def lookup_files(self, dirs, files):
"Assume all files are in the same dir, files is an array of (name, path) tuples."
directory = self._get_directoryname(files, dirs)
if directory is None:
return [], []
else:
return self._get_dirsandfiles(directory, dirs, files)
def _get_directoryname(self, dirs, files):
directory = None
if len(files):
directory = os.path.dirname(files[0][1])
elif len(dirs):
directory = os.path.dirname(dirs[0][1])
return directory
def _get_dirsandfiles(self, directory, dirs, files):
raise NotImplementedError()
......@@ -98,14 +98,8 @@ class Vc(_vc.Vc):
else:
return self._tree_cache
def lookup_files(self, dirs, files):
"files is array of (name, path). assume all files in same dir"
if len(files):
directory = os.path.dirname(files[0][1])
elif len(dirs):
directory = os.path.dirname(dirs[0][1])
else:
return [],[]
def _get_dirsandfiles(self, directory, dirs, files):
tree = self.get_tree(directory)
retfiles = []
......
......@@ -52,14 +52,7 @@ class Vc(_vc.Vc):
def revert_command(self):
return [self.CMD,"update","-C"]
def lookup_files(self, dirs, files):
"files is array of (name, path). assume all files in same dir"
if len(files):
directory = os.path.dirname(files[0][1])
elif len(dirs):
directory = os.path.dirname(dirs[0][1])
else:
return [],[]
def _get_dirsandfiles(self, directory, dirs, files):
try:
entries = open( os.path.join(directory, "CVS/Entries")).read()
......
......@@ -84,16 +84,11 @@ class Vc(_vc.Vc):
def uncache_inventory(self):
self._cached_statuses = None
def lookup_files(self, dirs, files):
"files is array of (name, path). assume all files in same dir"
directory = self._get_directoryname(files, dirs)
if directory is None:
return [], []
else:
whatsnew = self._get_cached_statuses()
retfiles, retdirs = (self._get_statuses(whatsnew, files, _vc.File),
self._get_statuses(whatsnew, dirs, _vc.Dir))
return retfiles, retdirs
def _get_dirsandfiles(self, directory, dirs, files):
whatsnew = self._get_cached_statuses()
retfiles, retdirs = (self._get_statuses(whatsnew, files, _vc.File),
self._get_statuses(whatsnew, dirs, _vc.Dir))
return retfiles, retdirs
def _get_cached_statuses(self):
if self._cached_statuses is None:
......@@ -145,12 +140,3 @@ class Vc(_vc.Vc):
if filename != "_darcs":
rets.append(vcfile)
return rets
def _get_directoryname(self, files, dirs):
directory = None
if len(files):
directory = os.path.dirname(files[0][1])
elif len(dirs):
directory = os.path.dirname(dirs[0][1])
return directory
......@@ -119,16 +119,8 @@ class Vc(_vc.Vc):
return self.lookup_tree()
else:
return self._tree_cache
def lookup_files(self, dirs, files):
"files is array of (name, path). assume all files in same dir"
if len(files):
directory = os.path.dirname(files[0][1])
elif len(dirs):
directory = os.path.dirname(dirs[0][1])
else:
return [],[]
def _get_dirsandfiles(self, directory, dirs, files):
tree = self.get_tree()
......
......@@ -55,14 +55,7 @@ class Vc(_vc.Vc):
def get_working_directory(self, workdir):
return self.root
def lookup_files(self, dirs, files):
"files is array of (name, path). assume all files in same dir"
if len(files):
directory = os.path.dirname(files[0][1])
elif len(dirs):
directory = os.path.dirname(dirs[0][1])
else:
return [],[]
def _get_dirsandfiles(self, directory, dirs, files):
while 1:
try:
......
......@@ -176,16 +176,13 @@ class Vc(_vc.Vc):
else:
return self._tree_cache
# TODO: if get_tree() could be called later,
# we wouldn't need this override for lookup_files()
def lookup_files(self, dirs, files):
"files is array of (name, path). assume all files in same dir"
tree = self.get_tree()
if len(files):
directory = os.path.dirname(files[0][1])
elif len(dirs):
directory = os.path.dirname(dirs[0][1])
else:
return [],[]
_vc.Vc.lookup_files(self, dirs, files)
def _get_dirsandfiles(self, directory, dirs, files):
retfiles = []
retdirs = []
......
......@@ -49,14 +49,7 @@ class Vc(_vc.Vc):
def revert_command(self):
return [self.CMD,"revert"]
def lookup_files(self, dirs, files):
"files is array of (name, path). assume all files in same dir"
if len(files):
directory = os.path.dirname(files[0][1])
elif len(dirs):
directory = os.path.dirname(dirs[0][1])
else:
return [],[]
def _get_dirsandfiles(self, directory, dirs, files):
while 1:
try:
......
......@@ -103,16 +103,11 @@ class Vc(_vc.Vc):
def uncache_inventory(self):
self._cached_statuses = None
def lookup_files(self, dirs, files):
"files is array of (name, path). assume all files in same dir"
directory = self._get_directoryname(files, dirs)
if directory is None:
return [], []
else:
whatsnew = self._get_cached_statuses()
retfiles, retdirs = (self._get_statuses(whatsnew, files, _vc.File),
self._get_statuses(whatsnew, dirs, _vc.Dir))
return retfiles, retdirs
def _get_dirsandfiles(self, directory, dirs, files):
whatsnew = self._get_cached_statuses()
retfiles, retdirs = (self._get_statuses(whatsnew, files, _vc.File),
self._get_statuses(whatsnew, dirs, _vc.Dir))
return retfiles, retdirs
def _get_cached_statuses(self):
if self._cached_statuses is None:
......@@ -151,12 +146,3 @@ class Vc(_vc.Vc):
if filename != "{arch}":
rets.append(vcfile)
return rets
def _get_directoryname(self, files, dirs):
directory = None
if len(files):
directory = os.path.dirname(files[0][1])
elif len(dirs):
directory = os.path.dirname(dirs[0][1])
return directory
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment