~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz_import.py

  • Committer: Aaron Bentley
  • Date: 2005-10-29 04:53:42 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051029045342-5b7a8ebf57e3f713
ReleaseĀ 0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import os.path
28
28
import shutil
29
29
import bzrlib
30
 
from bzrlib.errors import BzrError, NotBranchError, BzrCommandError
 
30
from bzrlib.errors import BzrError
31
31
import bzrlib.trace
32
32
import bzrlib.merge
33
33
import bzrlib.inventory
223
223
        # the current version is
224
224
        branch = find_branch(output_dir)
225
225
        last_patch = get_last_revision(branch)
226
 
        if last_patch is None:
227
 
            raise NotPreviousImport(branch.base)
228
226
        if version is None:
229
227
            version = last_patch.version
230
228
    elif version is None:
232
230
 
233
231
    try:
234
232
        ancestors = version_ancestry(version)
235
 
        if len(ancestors) > 0 and not ancestors[0].archive.is_registered():
236
 
            ancestors = ancestors[1:]
237
233
    except NoSuchVersion, e:
238
234
        raise UserError(e)
239
235
 
289
285
    try:
290
286
        ancestors, old_revno = get_remaining_revisions(output_dir, version)
291
287
    except NotInABranch, e:
292
 
        raise NotPreviousImport(e.path)
 
288
        raise UserError("%s exists, but is not a bzr branch." % e.path)
293
289
    if len(ancestors) == 0:
294
290
        last_revision = get_last_revision(find_branch(output_dir))
295
291
        print 'Tree is up-to-date with %s' % last_revision
345
341
        shutil.rmtree(tempdir)
346
342
    print "Import complete."
347
343
            
348
 
class UserError(BzrCommandError):
 
344
class UserError(Exception):
349
345
    def __init__(self, message):
350
346
        """Exception to throw when a user makes an impossible request
351
347
        :param message: The message to emit when printing this exception
352
348
        :type message: string
353
349
        """
354
 
        BzrCommandError.__init__(self, message)
355
 
 
356
 
class NotPreviousImport(UserError):
357
 
    def __init__(self, path):
358
 
        UserError.__init__(self, "%s is not the location of a previous import."
359
 
                           % path)
360
 
 
 
350
        Exception.__init__(self, message)
361
351
 
362
352
def revision_id(arch_revision):
363
353
    """
460
450
        rev_id = revision_id(revision)
461
451
        branch.lock_write()
462
452
        try:
463
 
            branch.working_tree().set_inventory(baz_inv)
 
453
            branch.set_inventory(baz_inv)
464
454
            bzrlib.trace.silent = True
465
 
            wt = branch.working_tree()
466
 
            wt.commit(log.summary, verbose=False, committer=log.creator,
467
 
                      timestamp=timestamp, timezone=0, rev_id=rev_id)
 
455
            branch.commit(log.summary, verbose=False, committer=log.creator,
 
456
                          timestamp=timestamp, timezone=0, rev_id=rev_id)
468
457
        finally:
469
458
            bzrlib.trace.silent = False   
470
459
            branch.unlock()
556
545
    """
557
546
    try:
558
547
        return Branch.open(path)
559
 
    except NotBranchError, e:
560
 
        raise NotInABranch(path)
 
548
    except BzrError, e:
 
549
        if e.args[0].endswith("' is not in a branch"):
 
550
            raise NotInABranch(path)
561
551
 
562
552
class cmd_baz_import(Command):
563
553
    """Import an Arch or Baz branch into a bzr branch"""