~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2009-07-10 04:05:24 UTC
  • Revision ID: aaron@aaronbentley.com-20090710040524-slufgm4he3fx1r4f
Mirror the child_submit_to setting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
from bzrlib.bzrdir import BzrDir
13
13
from bzrlib.errors import NoSuchFile, BzrCommandError, NotBranchError
14
14
from bzrlib.osutils import (pathjoin, isdir, file_iterator, basename,
15
 
                            file_kind)
 
15
                            file_kind, splitpath)
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 top_directory(path):
 
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
 
 
120
def top_path(path):
113
121
    """Return the top directory given in a path."""
114
 
    dirname = os.path.dirname(path)
115
 
    last_dirname = dirname
116
 
    while True:
117
 
        dirname = os.path.dirname(dirname)
118
 
        if dirname == '' or dirname == last_dirname:
119
 
            return last_dirname
120
 
        last_dirname = dirname
 
122
    components = splitpath(path)
 
123
    if len(components) > 0:
 
124
        return components[0]
 
125
    else:
 
126
        return ''
121
127
 
122
128
 
123
129
def common_directory(names):
124
130
    """Determine a single directory prefix from a list of names"""
125
131
    possible_prefix = None
126
132
    for name in names:
127
 
        name_top = top_directory(name)
 
133
        name_top = top_path(name)
128
134
        if name_top == '':
129
135
            return None
130
136
        if possible_prefix is None:
184
190
        tt.delete_contents(trans_id)
185
191
        removed.add(path)
186
192
 
187
 
    added = set() 
 
193
    added = set()
188
194
    implied_parents = set()
189
195
    seen = set()
190
196
    for member in archive_file.getmembers():
191
197
        if member.type == 'g':
192
198
            # type 'g' is a header
193
199
            continue
194
 
        relative_path = member.name 
 
200
        relative_path = member.name
195
201
        if prefix is not None:
196
202
            relative_path = relative_path[len(prefix)+1:]
197
203
            relative_path = relative_path.rstrip('/')
207
213
            tt.cancel_creation(trans_id)
208
214
        seen.add(member.name)
209
215
        if member.isreg():
210
 
            tt.create_file(file_iterator(archive_file.extractfile(member)), 
 
216
            tt.create_file(file_iterator(archive_file.extractfile(member)),
211
217
                           trans_id)
212
218
            executable = (member.mode & 0111) != 0
213
219
            tt.set_executability(executable, trans_id)
257
263
        if tree.changes_from(tree.basis_tree()).has_changed():
258
264
            raise BzrCommandError("Working tree has uncommitted changes.")
259
265
 
260
 
        if (source.endswith('.tar') or source.endswith('.tar.gz') or 
 
266
        if (source.endswith('.tar') or source.endswith('.tar.gz') or
261
267
            source.endswith('.tar.bz2')) or source.endswith('.tgz'):
262
268
            try:
 
269
                tar_input = open_from_url(source)
263
270
                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')
 
271
                    tar_input = StringIO(tar_input.read().decode('bz2'))
268
272
            except IOError, e:
269
273
                if e.errno == errno.ENOENT:
270
274
                    raise NoSuchFile(source)
273
277
            finally:
274
278
                tar_input.close()
275
279
        elif source.endswith('.zip'):
276
 
            import_zip(tree, open(source, 'rb'))
 
280
            import_zip(tree, open_from_url(source))
277
281
        elif file_kind(source) == 'directory':
278
282
            s = StringIO(source)
279
283
            s.seek(0)