/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/treeshape.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2010 Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
30
30
import os
31
31
import stat
32
32
 
33
 
from ..trace import warning
34
 
from ..osutils import pathjoin
35
 
 
 
33
from bzrlib.trace import warning
 
34
from bzrlib.osutils import pathjoin
36
35
 
37
36
def build_tree_contents(template):
38
37
    """Reconstitute some files from a text description.
42
41
 
43
42
    The template is built relative to the Python process's current
44
43
    working directory.
45
 
 
46
 
    ('foo/',) will build a directory.
47
 
    ('foo', 'bar') will write 'bar' to 'foo'
48
 
    ('foo@', 'linktarget') will raise an error
49
44
    """
50
45
    for tt in template:
51
46
        name = tt[0]
52
47
        if name[-1] == '/':
53
48
            os.mkdir(name)
54
49
        elif name[-1] == '@':
55
 
            os.symlink(tt[1], tt[0][:-1])
 
50
            raise NotImplementedError('symlinks not handled yet')
56
51
        else:
57
 
            with open(name, 'w' + ('b' if isinstance(tt[1], bytes) else '')) as f:
 
52
            f = file(name, 'wb')
 
53
            try:
58
54
                f.write(tt[1])
 
55
            finally:
 
56
                f.close()
59
57
 
60
58
 
61
59
def capture_tree_contents(top):
73
71
            if stat.S_ISLNK(info.st_mode):
74
72
                yield (fullpath + '@', os.readlink(fullpath))
75
73
            elif stat.S_ISREG(info.st_mode):
76
 
                with open(fullpath, 'rb') as f:
77
 
                    file_bytes = f.read()
78
 
                yield (fullpath, file_bytes)
 
74
                yield (fullpath, file(fullpath, 'rb').read())
79
75
            else:
80
76
                warning("can't capture file %s with mode %#o",
81
77
                        fullpath, info.st_mode)