~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2009-03-11 01:19:53 UTC
  • Revision ID: aaron@aaronbentley.com-20090311011953-2xgksl6krrs1yb4d
bzr patch handles URLs with trailing slashes

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