~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2007-01-08 17:27:48 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070108172748-1b22qtszaadoby89
Improve bzr import docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from bzrlib.trace import warning
17
17
from bzrlib.transform import TreeTransform, resolve_conflicts, cook_conflicts
18
18
from bzrlib.workingtree import WorkingTree
19
 
from bzrlib.plugins.bzrtools.bzrtools import open_from_url
20
19
 
21
20
class ZipFileWrapper(object):
22
21
 
41
40
 
42
41
 
43
42
class ZipInfoWrapper(object):
44
 
 
 
43
    
45
44
    def __init__(self, zipfile, info):
46
45
        self.info = info
47
46
        self.type = None
109
108
    def isdir(self):
110
109
        return stat.S_ISDIR(self.mode)
111
110
 
112
 
    def issym(self):
113
 
        if stat.S_ISLNK(self.mode):
114
 
            self.linkname = os.readlink(self.fullpath)
115
 
            return True
116
 
        else:
117
 
            return False
118
 
 
119
 
 
 
111
        
120
112
def top_directory(path):
121
113
    """Return the top directory given in a path."""
122
114
    dirname = os.path.dirname(path)
192
184
        tt.delete_contents(trans_id)
193
185
        removed.add(path)
194
186
 
195
 
    added = set()
 
187
    added = set() 
196
188
    implied_parents = set()
197
189
    seen = set()
198
190
    for member in archive_file.getmembers():
199
191
        if member.type == 'g':
200
192
            # type 'g' is a header
201
193
            continue
202
 
        relative_path = member.name
 
194
        relative_path = member.name 
203
195
        if prefix is not None:
204
196
            relative_path = relative_path[len(prefix)+1:]
205
 
            relative_path = relative_path.rstrip('/')
206
197
        if relative_path == '':
207
198
            continue
208
199
        add_implied_parents(implied_parents, relative_path)
215
206
            tt.cancel_creation(trans_id)
216
207
        seen.add(member.name)
217
208
        if member.isreg():
218
 
            tt.create_file(file_iterator(archive_file.extractfile(member)),
 
209
            tt.create_file(file_iterator(archive_file.extractfile(member)), 
219
210
                           trans_id)
220
211
            executable = (member.mode & 0111) != 0
221
212
            tt.set_executability(executable, trans_id)
265
256
        if tree.changes_from(tree.basis_tree()).has_changed():
266
257
            raise BzrCommandError("Working tree has uncommitted changes.")
267
258
 
268
 
        if (source.endswith('.tar') or source.endswith('.tar.gz') or
 
259
        if (source.endswith('.tar') or source.endswith('.tar.gz') or 
269
260
            source.endswith('.tar.bz2')) or source.endswith('.tgz'):
270
261
            try:
271
 
                tar_input = open_from_url(source)
272
262
                if source.endswith('.bz2'):
273
 
                    tar_input = StringIO(tar_input.read().decode('bz2'))
 
263
                    tar_input = BZ2File(source, 'r')
 
264
                    tar_input = StringIO(tar_input.read())
 
265
                else:
 
266
                    tar_input = file(source, 'rb')
274
267
            except IOError, e:
275
268
                if e.errno == errno.ENOENT:
276
269
                    raise NoSuchFile(source)
279
272
            finally:
280
273
                tar_input.close()
281
274
        elif source.endswith('.zip'):
282
 
            import_zip(tree, open_from_url(source))
 
275
            import_zip(tree, open(source, 'rb'))
283
276
        elif file_kind(source) == 'directory':
284
277
            s = StringIO(source)
285
278
            s.seek(0)