~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to clean_tree.py

  • Committer: Aaron Bentley
  • Date: 2008-10-10 19:23:14 UTC
  • Revision ID: aaron@aaronbentley.com-20081010192314-oynsoe7p5n0g1lxe
Add prompts before deleting in clean-tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
 
46
46
def clean_tree(directory, unknown=False, ignored=False, detritus=False, 
47
 
               dry_run=False):
 
47
               dry_run=False, no_prompt=False):
48
48
    """Remove files in the specified classes from the tree"""
49
49
    tree = WorkingTree.open_containing(directory)[0]
50
50
    tree.lock_read()
51
51
    try:
52
 
        deletables = iter_deletables(tree, unknown=unknown, ignored=ignored,
53
 
                                     detritus=detritus)
 
52
        deletables = list(iter_deletables(tree, unknown=unknown,
 
53
            ignored=ignored, detritus=detritus))
 
54
        if len(deletables) == 0:
 
55
            note('Nothing to delete.')
 
56
            return 0
 
57
        if not no_prompt:
 
58
            for path, subp in deletables:
 
59
                print subp
 
60
            val = raw_input('Are you sure you wish to delete these [y/N]?')
 
61
            if val.lower() not in ('y', 'yes'):
 
62
                print 'Canceled'
 
63
                return 0
54
64
        delete_items(deletables, dry_run=dry_run)
55
65
    finally:
56
66
        tree.unlock()