/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 tools/capture_tree.py

  • Committer: Jelmer Vernooij
  • Date: 2020-02-07 02:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200207021430-m49iq3x4x8xlib6x
Drop python2 support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
 
3
# Copyright (C) 2005 Canonical Ltd
 
4
 
 
5
"""Print to stdout a description of the current directory,
 
6
formatted as a Python data structure.
 
7
 
 
8
This can be useful in tests that need to recreate directory
 
9
contents."""
 
10
 
 
11
from __future__ import print_function
 
12
 
 
13
import os
 
14
import sys
 
15
 
 
16
from breezy.trace import enable_default_logging
 
17
enable_default_logging()
 
18
from breezy.selftest.treeshape import capture_tree_contents
 
19
 
 
20
def main(argv):
 
21
    # a lame reimplementation of pformat that splits multi-line
 
22
    # strings into concatenated string literals.
 
23
    print('[')
 
24
    for tt in capture_tree_contents('.'):
 
25
        assert isinstance(tt, tuple)
 
26
        print('    (', repr(tt[0]) + ',', end=' ')
 
27
        if len(tt) == 1:
 
28
            print('),')
 
29
        else:
 
30
            assert len(tt) == 2
 
31
            val = tt[1]
 
32
            print()
 
33
            if val == '':
 
34
                print("        ''")
 
35
            else:
 
36
                for valline in val.splitlines(True):
 
37
                    print('       ', repr(valline))
 
38
            print('    ),')
 
39
    print(']')
 
40
 
 
41
if __name__ == '__main__':
 
42
    sys.exit(main(sys.argv))