~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/codehosting/puller/worker.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2008-08-26 07:14:36 UTC
  • mfrom: (6889.2.10 remirroring-vs-transport)
  • Revision ID: launchpad@pqm.canonical.com-20080826071436-4ed3v9h6j8i6elf5
[r=thumper] an imperfect but effective fix for bug 260972 ("branch
        re-mirroring fails")

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
__metaclass__ = type
4
4
 
5
5
import httplib
6
 
import os
7
 
import shutil
8
6
import socket
9
7
import sys
10
8
import urllib2
11
9
 
12
10
from bzrlib.branch import Branch
13
11
from bzrlib.bzrdir import BzrDir
14
 
from bzrlib.errors import (
15
 
    BzrError, NotBranchError, NotStacked, ParamikoNotPresent,
16
 
    UnknownFormatError, UnstackableBranchFormat, UnstackableRepositoryFormat,
17
 
    UnsupportedFormatError)
 
12
from bzrlib import errors
18
13
from bzrlib.progress import DummyProgress
19
14
from bzrlib.transport import get_transport
20
15
import bzrlib.ui
21
16
 
22
17
from canonical.config import config
23
18
from canonical.codehosting import ProgressUIFactory
24
 
from canonical.codehosting.bzrutils import ensure_base
25
19
from canonical.codehosting.puller import get_lock_id_for_branch_id
26
20
from canonical.codehosting.transport import get_puller_server
27
21
from canonical.launchpad.interfaces import BranchType
377
371
        """
378
372
        try:
379
373
            branch = BzrDir.open(self.dest).open_branch()
380
 
        except NotBranchError:
 
374
        except errors.NotBranchError:
381
375
            # Make a new branch in the same format as the source branch.
382
376
            branch = self._createDestBranch(source_branch)
383
377
        else:
401
395
                # pulled before the stacking information is set at all.
402
396
                try:
403
397
                    stacked_on_url = source_branch.get_stacked_on_url()
404
 
                except (UnstackableRepositoryFormat, UnstackableBranchFormat,
405
 
                        NotStacked):
 
398
                except (errors.UnstackableRepositoryFormat,
 
399
                        errors.UnstackableBranchFormat,
 
400
                        errors.NotStacked):
406
401
                    stacked_on_url = None
407
402
                try:
408
403
                    branch.set_stacked_on_url(stacked_on_url)
409
 
                except (UnstackableRepositoryFormat, UnstackableBranchFormat):
 
404
                except (errors.UnstackableRepositoryFormat,
 
405
                        errors.UnstackableBranchFormat):
410
406
                    if stacked_on_url is not None:
411
407
                        raise AssertionError(
412
408
                            "Couldn't set stacked_on_url %r" % stacked_on_url)
419
415
 
420
416
    def _createDestBranch(self, source_branch):
421
417
        """Create the branch to pull to, and copy the source's contents."""
422
 
        if os.path.exists(self.dest):
423
 
            shutil.rmtree(self.dest)
424
 
        ensure_base(get_transport(self.dest))
 
418
        dest_transport = get_transport(self.dest)
 
419
        if dest_transport.has('.'):
 
420
            dest_transport.delete_tree('.')
425
421
        bzrdir = source_branch.bzrdir
426
 
        bzrdir.clone(self.dest, preserve_stacking=True)
 
422
        bzrdir.clone_on_transport(dest_transport, preserve_stacking=True)
427
423
        return Branch.open(self.dest)
428
424
 
429
425
    def _record_oops(self, message=None):
485
481
            msg = 'A socket error occurred: %s' % str(e)
486
482
            self._mirrorFailed(msg)
487
483
 
488
 
        except UnsupportedFormatError, e:
 
484
        except errors.UnsupportedFormatError, e:
489
485
            msg = ("Launchpad does not support branches from before "
490
486
                   "bzr 0.7. Please upgrade the branch using bzr upgrade.")
491
487
            self._mirrorFailed(msg)
492
488
 
493
 
        except UnknownFormatError, e:
 
489
        except errors.UnknownFormatError, e:
494
490
            self._mirrorFailed(e)
495
491
 
496
 
        except (ParamikoNotPresent, BadUrlSsh), e:
 
492
        except (errors.ParamikoNotPresent, BadUrlSsh), e:
497
493
            msg = ("Launchpad cannot mirror branches from SFTP and SSH URLs."
498
494
                   " Please register a HTTP location for this branch.")
499
495
            self._mirrorFailed(msg)
506
502
            msg = "Launchpad does not mirror %s:// URLs." % e.scheme
507
503
            self._mirrorFailed(msg)
508
504
 
509
 
        except NotBranchError, e:
510
 
            hosted_branch_error = NotBranchError("lp:~%s" % self.unique_name)
 
505
        except errors.NotBranchError, e:
 
506
            hosted_branch_error = errors.NotBranchError(
 
507
                "lp:~%s" % self.unique_name)
511
508
            message_by_type = {
512
509
                BranchType.HOSTED: str(hosted_branch_error),
513
510
                BranchType.IMPORTED: "Not a branch.",
524
521
            msg = "Circular branch reference."
525
522
            self._mirrorFailed(msg)
526
523
 
527
 
        except BzrError, e:
 
524
        except errors.BzrError, e:
528
525
            self._mirrorFailed(e)
529
526
 
530
527
        except InvalidURIError, e: