There are times were I need to generate a manifest, or perform an export of my current CVS sandbox. cvs export works similarly to cvs co, i.e. extracts directly from a repository. I want to generate a clean export, without all the log files, etc, that tend to pollute my work area. I started using os.path.walk and remove what's not in CVS, but in the end the following code was much simpler (especially after taking a look at the source code for os.path.walk :-)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
import os def cvs_walk(currdir): """ walk through a CVS hierarchy Modeled after os.walk, this generator returns a topdown list of (currdir, dirs, files) tuples based on the CVS hierarchy. """ dirs =  files =  if os.path.isdir(dir) and os.path.isdir(os.path.join(currdir, 'CVS')): for entry in open(os.path.join(currdir, 'CVS', 'Entries')): e = entry.split('/') if (len(e) > 1): if e == 'D': dirs.append(e) else: files.append(e) yield (currdir, dirs, files) for d in dirs: for x in cvs_walk(os.path.join(currdir, d)): yield x # # use it just like os.path.walk # for (a_dir, dirs, files) in cvs_walk(top): for file in files: print os.path.join(a_dir, file)
1) Don't use keywords like file, dir for variable names. 2) cvs_walk gives a wrong notion that it will walk the Remote CVS Directory. It does not. It does a os.path.walk on local cvs directory, skipping the CVS maintenance files. Remote directory walk is desirable.
You are right about dir & file. Sorry if the cvs_walk name misled you, but it does exactly what it is intended: walk a local CVS directory tree, skipping the CVS maintenance files/directories, for the purpose of making a release, building a snapshot tar file, etc. For remote CVS (i.e. to extract data directly from the CVS repository), there is 'cvs export' (or just plain 'cvs checkout' :-)