~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to clean_tree.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-08-27 02:40:27 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20050827024027-1cb9fbbcc46dda38
Added clean-tree command

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import errno
 
2
import os
 
3
import shutil
 
4
from bzrlib.branch import Branch
 
5
 
 
6
def clean_tree(unknowns=True, ignored=False):
 
7
    def deletables(tree):
 
8
        for subp in tree.extras():
 
9
            if tree.is_ignored(subp):
 
10
                if ignored:
 
11
                    yield tree.abspath(subp)
 
12
            else:
 
13
                if unknowns:
 
14
                    yield tree.abspath(subp)
 
15
    br = Branch('.')
 
16
    tree = br.working_tree()
 
17
    printed_once = False
 
18
    for path in deletables(tree):
 
19
        if not printed_once:
 
20
            print "deletings paths:"
 
21
            printed_once = True
 
22
        print ' ', path
 
23
        try:
 
24
            os.unlink(path)
 
25
        except OSError, e:
 
26
            if e.errno != errno.EISDIR:
 
27
                raise
 
28
            shutil.rmtree(path)