/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 breezy/tests/treeshape.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

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