~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-12 22:25:28 UTC
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20060912222528-309c74df59ea80b6
lazy_import inventory.py, avoids importing tarfile

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
# created, but it's not for now.
28
28
ROOT_ID = "TREE_ROOT"
29
29
 
30
 
 
31
 
import collections
32
 
import os.path
 
30
import os
33
31
import re
34
32
import sys
 
33
 
 
34
from bzrlib.lazy_import import lazy_import
 
35
lazy_import(globals(), """
 
36
import collections
35
37
import tarfile
36
 
import types
37
 
from warnings import warn
38
38
 
39
39
import bzrlib
40
 
from bzrlib import errors, osutils
41
 
from bzrlib.osutils import (pumpfile, quotefn, splitpath, joinpath,
42
 
                            pathjoin, sha_strings)
43
 
from bzrlib.errors import (NotVersionedError, InvalidEntryName,
44
 
                           BzrError, BzrCheckError, BinaryFile)
 
40
from bzrlib import (
 
41
    errors,
 
42
    osutils,
 
43
    symbol_versioning,
 
44
    )
 
45
""")
 
46
 
 
47
from bzrlib.errors import (
 
48
    BzrCheckError,
 
49
    BzrError,
 
50
    )
45
51
from bzrlib.trace import mutter
46
52
 
47
53
 
246
252
 
247
253
    def get_tar_item(self, root, dp, now, tree):
248
254
        """Get a tarfile item and a file stream for its content."""
249
 
        item = tarfile.TarInfo(pathjoin(root, dp))
 
255
        item = tarfile.TarInfo(osutils.pathjoin(root, dp))
250
256
        # TODO: would be cool to actually set it to the timestamp of the
251
257
        # revision it was last changed
252
258
        item.mtime = now
281
287
        """
282
288
        assert isinstance(name, basestring), name
283
289
        if '/' in name or '\\' in name:
284
 
            raise InvalidEntryName(name=name)
 
290
            raise errors.InvalidEntryName(name=name)
285
291
        self.executable = False
286
292
        self.revision = None
287
293
        self.text_sha1 = None
311
317
        
312
318
        This is a template method - implement _put_on_disk in subclasses.
313
319
        """
314
 
        fullpath = pathjoin(dest, dp)
 
320
        fullpath = osutils.pathjoin(dest, dp)
315
321
        self._put_on_disk(fullpath, tree)
316
322
        # mutter("  export {%s} kind %s to %s", self.file_id,
317
323
        #         self.kind, fullpath)
514
520
        self.parent_id = None
515
521
        self.name = u''
516
522
        self.revision = None
517
 
        warn('RootEntry is deprecated as of bzr 0.10.  Please use '
518
 
             'InventoryDirectory instead.',
519
 
            DeprecationWarning, stacklevel=2)
 
523
        symbol_versioning.warn('RootEntry is deprecated as of bzr 0.10.'
 
524
                               '  Please use InventoryDirectory instead.',
 
525
                               DeprecationWarning, stacklevel=2)
520
526
 
521
527
    def __eq__(self, other):
522
528
        if not isinstance(other, RootEntry):
645
651
            else:
646
652
                text_diff(to_label, to_text,
647
653
                          from_label, from_text, output_to)
648
 
        except BinaryFile:
 
654
        except errors.BinaryFile:
649
655
            if reverse:
650
656
                label_pair = (to_label, from_label)
651
657
            else:
677
683
 
678
684
    def _put_on_disk(self, fullpath, tree):
679
685
        """See InventoryEntry._put_on_disk."""
680
 
        pumpfile(tree.get_file(self.file_id), file(fullpath, 'wb'))
 
686
        osutils.pumpfile(tree.get_file(self.file_id), file(fullpath, 'wb'))
681
687
        if tree.is_executable(self.file_id):
682
688
            os.chmod(fullpath, 0755)
683
689
 
982
988
            kids = dir_ie.children.items()
983
989
            kids.sort()
984
990
            for name, ie in kids:
985
 
                child_path = pathjoin(dir_path, name)
 
991
                child_path = osutils.pathjoin(dir_path, name)
986
992
                accum.append((child_path, ie))
987
993
                if ie.kind == 'directory':
988
994
                    descend(ie, child_path)
1001
1007
            kids.sort()
1002
1008
 
1003
1009
            for name, child_ie in kids:
1004
 
                child_path = pathjoin(parent_path, name)
 
1010
                child_path = osutils.pathjoin(parent_path, name)
1005
1011
                descend(child_ie, child_path)
1006
1012
        descend(self.root, u'')
1007
1013
        return accum
1068
1074
 
1069
1075
        if entry.name in parent.children:
1070
1076
            raise BzrError("%s is already versioned" %
1071
 
                    pathjoin(self.id2path(parent.file_id), entry.name))
 
1077
                    osutils.pathjoin(self.id2path(parent.file_id), entry.name))
1072
1078
 
1073
1079
        self._byid[entry.file_id] = entry
1074
1080
        parent.children[entry.name] = entry
1093
1099
            parent_path = parts[:-1]
1094
1100
            parent_id = self.path2id(parent_path)
1095
1101
            if parent_id is None:
1096
 
                raise NotVersionedError(path=parent_path)
 
1102
                raise errors.NotVersionedError(path=parent_path)
1097
1103
        ie = make_entry(kind, parts[-1], parent_id, file_id)
1098
1104
        return self.add(ie)
1099
1105
 
1193
1199
 
1194
1200
        Returns None IFF the path is not found.
1195
1201
        """
1196
 
        if isinstance(name, types.StringTypes):
1197
 
            name = splitpath(name)
 
1202
        if isinstance(name, basestring):
 
1203
            name = osutils.splitpath(name)
1198
1204
 
1199
1205
        # mutter("lookup path %r" % name)
1200
1206