~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/treeshape.py

  • Committer: Martin Pool
  • Date: 2005-10-04 10:10:48 UTC
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1403.
  • Revision ID: mbp@sourcefrog.net-20051004101047-bd75d2b341134eff
- capture_tree tool to help in preparing test cases

- capture_tree code should cope with directories containing fifos, etc

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
# comparison.
29
29
 
30
30
import os
 
31
import stat
 
32
 
 
33
from bzrlib.trace import warning
31
34
 
32
35
def build_tree_contents(template):
33
36
    """Reconstitute some files from a text description.
52
55
                f.close()
53
56
 
54
57
 
55
 
def pack_tree_contents(top):
 
58
def capture_tree_contents(top):
56
59
    """Make a Python datastructure description of a tree.
57
60
    
58
61
    If top is an absolute path the descriptions will be absolute."""
61
64
        filenames.sort()
62
65
        for fn in filenames:
63
66
            fullpath = os.path.join(dirpath, fn)
64
 
            yield (fullpath, file(fullpath, 'rb').read())
 
67
            assert fullpath[-1] not in '@/'
 
68
            info = os.lstat(fullpath)
 
69
            if stat.S_ISLNK(info.st_mode):
 
70
                yield (fullpath + '@', os.readlink(fullpath))
 
71
            elif stat.S_ISREG(info.st_mode):
 
72
                yield (fullpath, file(fullpath, 'rb').read())
 
73
            else:
 
74
                warning("can't capture file %s with mode %#o",
 
75
                        fullpath, info.st_mode)
 
76
                pass