~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz2bzr

  • Committer: Aaron Bentley
  • Date: 2005-05-10 16:15:14 UTC
  • Revision ID: abentley@troll-20050510161514-fa8881dadeaed49d
Nicer handling of unsupported file types

Show diffs side-by-side

added added

removed removed

Lines of Context:
185
185
    try:
186
186
        for result in iter_import_version(output_dir, version, tempdir):
187
187
            progress_bar(result)
 
188
    finally:
188
189
        clear_progress_bar()
189
 
        print "Import complete."
190
 
    finally:
191
190
        shutil.rmtree(tempdir)
 
191
    print "Import complete."
192
192
            
193
193
class UserError(Exception):
194
194
    def __init__(self, message):
233
233
    revision.get(revdir)
234
234
    tree = pybaz.tree_root(revdir)
235
235
    log = tree.iter_logs(reverse=True).next()
236
 
    return bzr_inventory_data(tree), log 
 
236
    try:
 
237
        return bzr_inventory_data(tree), log 
 
238
    except BadFileKind, e:
 
239
        raise UserError("Cannot convert %s because %s is a %s" % (revision,e.path, e.kind) )
 
240
 
237
241
 
238
242
def apply_revision(revdir, revision):
239
243
    tree = pybaz.tree_root(revdir)
240
244
    revision.apply(tree)
241
245
    log = tree.iter_logs(reverse=True).next()
242
 
    return bzr_inventory_data(tree), log 
243
 
 
 
246
    try:
 
247
        return bzr_inventory_data(tree), log
 
248
    except BadFileKind, e:
 
249
        raise UserError("Cannot convert %s because %s is a %s" % (revision,e.path, e.kind) )
 
250
 
 
251
 
 
252
 
 
253
 
 
254
class BadFileKind(Exception):
 
255
    """The file kind is not permitted in bzr inventories"""
 
256
    def __init__(self, tree_root, path, kind):
 
257
        self.tree_root = tree_root
 
258
        self.path = path
 
259
        self.kind = kind
 
260
        Exception.__init__(self, "File %s is of forbidden type %s" %
 
261
                           (os.path.join(tree_root, path), kind))
244
262
 
245
263
def bzr_inventory_data(tree):
246
264
    inv_iter = tree.iter_inventory_ids(source=True, both=True)
250
268
 
251
269
    bzr_inv = []
252
270
    for path, file_id in inv_map.iteritems():
253
 
        kind = bzrlib.osutils.file_kind(os.path.join(tree, path))
254
 
        assert kind in ("file", "directory")
 
271
        full_path = os.path.join(tree, path)
 
272
        kind = bzrlib.osutils.file_kind(full_path)
 
273
        if kind not in ("file", "directory"):
 
274
            raise BadFileKind(tree, path, kind)
255
275
        parent_dir = os.path.dirname(path)
256
276
        if parent_dir != "":
257
277
            parent_id = inv_map[parent_dir]