~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

  • Committer: Martin Pool
  • Date: 2005-07-11 03:12:55 UTC
  • Revision ID: mbp@sourcefrog.net-20050711031255-56ede11b09be6d32
trace

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib.trace import mutter, note, warning
 
17
import os, sys
 
18
import bzrlib
 
19
 
 
20
from trace import mutter, note
18
21
 
19
22
def glob_expand_for_win32(file_list):
20
23
    import glob
31
34
            expanded_file_list += glob_files
32
35
    return expanded_file_list
33
36
 
34
 
 
35
37
def smart_add(file_list, verbose=True, recurse=True):
36
38
    """Add files to version, optionally recursing into directories.
37
39
 
38
40
    This is designed more towards DWIM for humans than API simplicity.
39
41
    For the specific behaviour see the help for cmd_add().
40
 
 
41
 
    This yields a sequence of (path, kind, file_id) for added files.
42
42
    """
43
 
    import os
44
 
    import sys
45
 
    from bzrlib.osutils import quotefn
 
43
    from bzrlib.osutils import quotefn, kind_marker
46
44
    from bzrlib.errors import BadFileKindError, ForbiddenFileError
47
 
    import bzrlib.branch
48
 
    import bzrlib.osutils
49
45
 
 
46
    assert file_list
 
47
    
50
48
    if sys.platform == 'win32':
51
49
        file_list = glob_expand_for_win32(file_list)
52
 
        
53
 
    if not file_list:
54
 
        file_list = ['.']
55
50
    
56
51
    user_list = file_list[:]
57
52
    assert not isinstance(file_list, basestring)
70
65
            if f in user_list:
71
66
                raise BadFileKindError("cannot add %s of type %s" % (f, kind))
72
67
            else:
73
 
                warning("skipping %s (can't add file of kind '%s')", f, kind)
 
68
                print "skipping %s (can't add file of kind '%s')" % (f, kind)
74
69
                continue
75
70
 
76
71
        mutter("smart add of %r, abs=%r" % (f, af))
90
85
            mutter("added %r kind %r file_id={%s}" % (rf, kind, file_id))
91
86
            count += 1 
92
87
 
93
 
            yield f, kind, file_id
94
 
 
 
88
            print 'added', quotefn(f)
95
89
 
96
90
        if kind == 'directory' and recurse:
97
91
            for subf in os.listdir(af):
104
98
                    mutter("queue to add sub-file %r" % subp)
105
99
                    file_list.append(b.abspath(subp))
106
100
 
107
 
 
108
101
    if count > 0:
109
102
        if verbose:
110
 
            note('added %d entries', count)
 
103
            note('added %d' % count)
111
104
        b._write_inventory(inv)
112