~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2007-03-07 14:14:01 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070307141401-lpvmug502lgcg504
Release script checks for uncommitted changes

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