~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2009-04-10 21:11:45 UTC
  • Revision ID: aaron@aaronbentley.com-20090410211145-ibc2ispf7uw2rwg9
Tags: release-1.14.0
Update NEWS for release.

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
 
116
117
            return False
117
118
 
118
119
 
119
 
def top_directory(path):
 
120
def top_path(path):
120
121
    """Return the top directory given in a path."""
121
 
    dirname = os.path.dirname(path)
122
 
    last_dirname = dirname
123
 
    while True:
124
 
        dirname = os.path.dirname(dirname)
125
 
        if dirname == '' or dirname == last_dirname:
126
 
            return last_dirname
127
 
        last_dirname = dirname
 
122
    components = splitpath(path)
 
123
    if len(components) > 0:
 
124
        return components[0]
 
125
    else:
 
126
        return ''
128
127
 
129
128
 
130
129
def common_directory(names):
131
130
    """Determine a single directory prefix from a list of names"""
132
131
    possible_prefix = None
133
132
    for name in names:
134
 
        name_top = top_directory(name)
 
133
        name_top = top_path(name)
135
134
        if name_top == '':
136
135
            return None
137
136
        if possible_prefix is None:
267
266
        if (source.endswith('.tar') or source.endswith('.tar.gz') or
268
267
            source.endswith('.tar.bz2')) or source.endswith('.tgz'):
269
268
            try:
 
269
                tar_input = open_from_url(source)
270
270
                if source.endswith('.bz2'):
271
 
                    tar_input = BZ2File(source, 'r')
272
 
                    tar_input = StringIO(tar_input.read())
273
 
                else:
274
 
                    tar_input = file(source, 'rb')
 
271
                    tar_input = StringIO(tar_input.read().decode('bz2'))
275
272
            except IOError, e:
276
273
                if e.errno == errno.ENOENT:
277
274
                    raise NoSuchFile(source)
280
277
            finally:
281
278
                tar_input.close()
282
279
        elif source.endswith('.zip'):
283
 
            import_zip(tree, open(source, 'rb'))
 
280
            import_zip(tree, open_from_url(source))
284
281
        elif file_kind(source) == 'directory':
285
282
            s = StringIO(source)
286
283
            s.seek(0)