/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-28 02:47:10 UTC
  • mfrom: (7519.1.1 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200728024710-a2ylds219f1lsl62
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/388173

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.
51
52
        if name[-1] == '/':
52
53
            os.mkdir(name)
53
54
        elif name[-1] == '@':
54
 
            raise NotImplementedError('symlinks not handled yet')
 
55
            os.symlink(tt[1], tt[0][:-1])
55
56
        else:
56
 
            f = file(name, 'wb')
57
 
            try:
 
57
            with open(name, 'w' + ('b' if isinstance(tt[1], bytes) else '')) as f:
58
58
                f.write(tt[1])
59
 
            finally:
60
 
                f.close()
61
59
 
62
60
 
63
61
def capture_tree_contents(top):
75
73
            if stat.S_ISLNK(info.st_mode):
76
74
                yield (fullpath + '@', os.readlink(fullpath))
77
75
            elif stat.S_ISREG(info.st_mode):
78
 
                yield (fullpath, file(fullpath, 'rb').read())
 
76
                with open(fullpath, 'rb') as f:
 
77
                    file_bytes = f.read()
 
78
                yield (fullpath, file_bytes)
79
79
            else:
80
80
                warning("can't capture file %s with mode %#o",
81
81
                        fullpath, info.st_mode)