~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to clean_tree.py

  • Committer: Charlie Shepherd
  • Date: 2007-04-04 18:09:00 UTC
  • mto: This revision was merged to the branch mainline in revision 538.
  • Revision ID: masterdriverz@gentoo.org-20070404180900-ln1hh48xz541nstz
Make clean-tree output to stdout instead of stderr

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import sys
20
20
 
21
21
from bzrlib.osutils import has_symlinks, isdir
22
 
from bzrlib.trace import note
23
22
from bzrlib.workingtree import WorkingTree
24
23
 
25
24
 
43
42
                yield tree.abspath(subp), subp
44
43
 
45
44
 
46
 
def clean_tree(directory, unknown=False, ignored=False, detritus=False, 
47
 
               dry_run=False):
 
45
def clean_tree(directory, out=sys.stdout, unknown=False, ignored=False,
 
46
               detritus=False, dry_run=False):
48
47
    """Remove files in the specified classes from the tree"""
49
48
    tree = WorkingTree.open_containing(directory)[0]
50
49
    tree.lock_read()
56
55
        tree.unlock()
57
56
 
58
57
 
59
 
def delete_items(deletables, dry_run=False):
 
58
def delete_items(deletables, out=sys.stdout, dry_run=False):
60
59
    """Delete files in the deletables iterable"""
61
60
    has_deleted = False
62
61
    for path, subp in deletables:
63
62
        if not has_deleted:
64
 
            note("deleting paths:")
 
63
            print >>out, "deleting paths:"
65
64
            has_deleted = True
66
 
        note('  ' + subp)
 
65
        print >>out, '  ' + subp
67
66
        if not dry_run:
68
67
            if isdir(path):
69
68
                shutil.rmtree(path)
70
69
            else:
71
70
                os.unlink(path)
72
71
    if not has_deleted:
73
 
        note("No files deleted.")
 
72
        print >>out, "No files deleted."