Ejemplo n.º 1
0
def get_branches(sourcecode_directory, new_branches,
                 possible_transports=None, tip=False, quiet=False):
    """Get the new branches into sourcecode."""
    for project, (branch_url, revision, optional) in new_branches.iteritems():
        destination = os.path.join(sourcecode_directory, project)
        try:
            remote_branch = Branch.open(
                branch_url, possible_transports=possible_transports)
        except BzrError:
            if optional:
                report_exception(sys.exc_info(), sys.stderr)
                continue
            else:
                raise
        possible_transports.append(
            remote_branch.bzrdir.root_transport)
        if not quiet:
            print 'Getting %s from %s at %s' % (
                    project, branch_url, _format_revision_name(revision, tip))
        # If the 'optional' flag is set, then it's a branch that shares
        # history with Launchpad, so we should share repositories. Otherwise,
        # we should avoid sharing repositories to avoid format
        # incompatibilities.
        force_new_repo = not optional
        revision_id = get_revision_id(revision, remote_branch, tip)
        remote_branch.bzrdir.sprout(
            destination, revision_id=revision_id, create_tree_if_local=True,
            source_branch=remote_branch, force_new_repo=force_new_repo,
            possible_transports=possible_transports)
Ejemplo n.º 2
0
def get_branches(sourcecode_directory,
                 new_branches,
                 possible_transports=None,
                 tip=False,
                 quiet=False):
    """Get the new branches into sourcecode."""
    for project, (branch_url, revision, optional) in new_branches.iteritems():
        destination = os.path.join(sourcecode_directory, project)
        try:
            remote_branch = Branch.open(
                branch_url, possible_transports=possible_transports)
        except BzrError:
            if optional:
                report_exception(sys.exc_info(), sys.stderr)
                continue
            else:
                raise
        possible_transports.append(remote_branch.bzrdir.root_transport)
        if not quiet:
            print 'Getting %s from %s at %s' % (
                project, branch_url, _format_revision_name(revision, tip))
        # If the 'optional' flag is set, then it's a branch that shares
        # history with Launchpad, so we should share repositories. Otherwise,
        # we should avoid sharing repositories to avoid format
        # incompatibilities.
        force_new_repo = not optional
        revision_id = get_revision_id(revision, remote_branch, tip)
        remote_branch.bzrdir.sprout(destination,
                                    revision_id=revision_id,
                                    create_tree_if_local=True,
                                    source_branch=remote_branch,
                                    force_new_repo=force_new_repo,
                                    possible_transports=possible_transports)
Ejemplo n.º 3
0
 def test_report_exception(self):
     """When an error occurs, display bug report details to stderr"""
     try:
         raise AssertionError("failed")
     except AssertionError, e:
         erf = StringIO()
         trace.report_exception(sys.exc_info(), erf)
Ejemplo n.º 4
0
 def test_report_exception(self):
     """When an error occurs, display bug report details to stderr"""
     try:
         raise AssertionError("failed")
     except AssertionError, e:
         erf = StringIO()
         trace.report_exception(sys.exc_info(), erf)
Ejemplo n.º 5
0
def update_branches(sourcecode_directory,
                    update_branches,
                    possible_transports=None,
                    tip=False,
                    quiet=False):
    """Update the existing branches in sourcecode."""
    if possible_transports is None:
        possible_transports = []
    # XXX: JonathanLange 2009-11-09: Rather than updating one branch after
    # another, we could instead try to get them in parallel.
    for project, (branch_url, revision,
                  optional) in (update_branches.iteritems()):
        # Update project from branch_url.
        destination = os.path.join(sourcecode_directory, project)
        if not quiet:
            print 'Updating %s to %s' % (project,
                                         _format_revision_name(revision, tip))
        local_tree = WorkingTree.open(destination)
        try:
            remote_branch = Branch.open(
                branch_url, possible_transports=possible_transports)
        except BzrError:
            if optional:
                report_exception(sys.exc_info(), sys.stderr)
                continue
            else:
                raise
        possible_transports.append(remote_branch.bzrdir.root_transport)
        revision_id = get_revision_id(revision, remote_branch, tip)
        try:
            result = local_tree.pull(remote_branch,
                                     stop_revision=revision_id,
                                     overwrite=True,
                                     possible_transports=possible_transports)
        except IncompatibleRepositories:
            # XXX JRV 20100407: Ideally remote_branch.bzrdir._format
            # should be passed into upgrade() to ensure the format is the same
            # locally and remotely. Unfortunately smart server branches
            # have their _format set to RemoteFormat rather than an actual
            # format instance.
            upgrade(destination)
            # Upgraded, repoen working tree
            local_tree = WorkingTree.open(destination)
            result = local_tree.pull(remote_branch,
                                     stop_revision=revision_id,
                                     overwrite=True,
                                     possible_transports=possible_transports)
        if result.old_revid == result.new_revid:
            if not quiet:
                print '  (No change)'
        else:
            if result.old_revno < result.new_revno:
                change = 'Updated'
            else:
                change = 'Reverted'
            if not quiet:
                print '  (%s from %s to %s)' % (change, result.old_revno,
                                                result.new_revno)
Ejemplo n.º 6
0
 def serve(self, thread_name_suffix=''):
     # Note: There is a temptation to do
     #       signals.register_on_hangup(id(self), self._stop_gracefully)
     #       However, that creates a temporary object which is a bound
     #       method. signals._on_sighup is a WeakKeyDictionary so it
     #       immediately gets garbage collected, because nothing else
     #       references it. Instead, we need to keep a real reference to the
     #       bound method for the lifetime of the serve() function.
     stop_gracefully = self._stop_gracefully
     signals.register_on_hangup(id(self), stop_gracefully)
     self._should_terminate = False
     # for hooks we are letting code know that a server has started (and
     # later stopped).
     self.run_server_started_hooks()
     self._started.set()
     try:
         try:
             while not self._should_terminate:
                 try:
                     conn, client_addr = self._server_socket.accept()
                 except self._socket_timeout:
                     # just check if we're asked to stop
                     pass
                 except self._socket_error, e:
                     # if the socket is closed by stop_background_thread
                     # we might get a EBADF here, or if we get a signal we
                     # can get EINTR, any other socket errors should get
                     # logged.
                     if e.args[0] not in (errno.EBADF, errno.EINTR):
                         trace.warning(gettext("listening socket error: %s")
                                       % (e,))
                 else:
                     if self._should_terminate:
                         conn.close()
                         break
                     self.serve_conn(conn, thread_name_suffix)
                 # Cleanout any threads that have finished processing.
                 self._poll_active_connections()
         except KeyboardInterrupt:
             # dont log when CTRL-C'd.
             raise
         except Exception, e:
             trace.report_exception(sys.exc_info(), sys.stderr)
             raise
     finally:
         try:
             # ensure the server socket is closed.
             self._server_socket.close()
         except self._socket_error:
             # ignore errors on close
             pass
         self._stopped.set()
         signals.unregister_on_hangup(id(self))
         self.run_server_stopped_hooks()
     if self._gracefully_stopping:
         self._wait_for_clients_to_disconnect()
     self._fully_stopped.set()
Ejemplo n.º 7
0
 def serve(self, thread_name_suffix=''):
     # Note: There is a temptation to do
     #       signals.register_on_hangup(id(self), self._stop_gracefully)
     #       However, that creates a temporary object which is a bound
     #       method. signals._on_sighup is a WeakKeyDictionary so it
     #       immediately gets garbage collected, because nothing else
     #       references it. Instead, we need to keep a real reference to the
     #       bound method for the lifetime of the serve() function.
     stop_gracefully = self._stop_gracefully
     signals.register_on_hangup(id(self), stop_gracefully)
     self._should_terminate = False
     # for hooks we are letting code know that a server has started (and
     # later stopped).
     self.run_server_started_hooks()
     self._started.set()
     try:
         try:
             while not self._should_terminate:
                 try:
                     conn, client_addr = self._server_socket.accept()
                 except self._socket_timeout:
                     # just check if we're asked to stop
                     pass
                 except self._socket_error, e:
                     # if the socket is closed by stop_background_thread
                     # we might get a EBADF here, or if we get a signal we
                     # can get EINTR, any other socket errors should get
                     # logged.
                     if e.args[0] not in (errno.EBADF, errno.EINTR):
                         trace.warning(
                             gettext("listening socket error: %s") % (e, ))
                 else:
                     if self._should_terminate:
                         conn.close()
                         break
                     self.serve_conn(conn, thread_name_suffix)
                 # Cleanout any threads that have finished processing.
                 self._poll_active_connections()
         except KeyboardInterrupt:
             # dont log when CTRL-C'd.
             raise
         except Exception, e:
             trace.report_exception(sys.exc_info(), sys.stderr)
             raise
     finally:
         try:
             # ensure the server socket is closed.
             self._server_socket.close()
         except self._socket_error:
             # ignore errors on close
             pass
         self._stopped.set()
         signals.unregister_on_hangup(id(self))
         self.run_server_stopped_hooks()
     if self._gracefully_stopping:
         self._wait_for_clients_to_disconnect()
     self._fully_stopped.set()
Ejemplo n.º 8
0
def update_branches(sourcecode_directory, update_branches,
                    possible_transports=None, tip=False, quiet=False):
    """Update the existing branches in sourcecode."""
    if possible_transports is None:
        possible_transports = []
    # XXX: JonathanLange 2009-11-09: Rather than updating one branch after
    # another, we could instead try to get them in parallel.
    for project, (branch_url, revision, optional) in (
        update_branches.iteritems()):
        # Update project from branch_url.
        destination = os.path.join(sourcecode_directory, project)
        if not quiet:
            print 'Updating %s to %s' % (
                    project, _format_revision_name(revision, tip))
        local_tree = WorkingTree.open(destination)
        try:
            remote_branch = Branch.open(
                branch_url, possible_transports=possible_transports)
        except BzrError:
            if optional:
                report_exception(sys.exc_info(), sys.stderr)
                continue
            else:
                raise
        possible_transports.append(
            remote_branch.bzrdir.root_transport)
        revision_id = get_revision_id(revision, remote_branch, tip)
        try:
            result = local_tree.pull(
                remote_branch, stop_revision=revision_id, overwrite=True,
                possible_transports=possible_transports)
        except IncompatibleRepositories:
            # XXX JRV 20100407: Ideally remote_branch.bzrdir._format
            # should be passed into upgrade() to ensure the format is the same
            # locally and remotely. Unfortunately smart server branches
            # have their _format set to RemoteFormat rather than an actual
            # format instance.
            upgrade(destination)
            # Upgraded, repoen working tree
            local_tree = WorkingTree.open(destination)
            result = local_tree.pull(
                remote_branch, stop_revision=revision_id, overwrite=True,
                possible_transports=possible_transports)
        if result.old_revid == result.new_revid:
            if not quiet:
                print '  (No change)'
        else:
            if result.old_revno < result.new_revno:
                change = 'Updated'
            else:
                change = 'Reverted'
            if not quiet:
                print '  (%s from %s to %s)' % (
                    change, result.old_revno, result.new_revno)
Ejemplo n.º 9
0
def _format_exception():
    """Format an exception as it would normally be displayed to the user"""
    buf = StringIO()
    report_exception(sys.exc_info(), buf)
    return buf.getvalue()
Ejemplo n.º 10
0
def _format_exception():
    """Format an exception as it would normally be displayed to the user"""
    buf = StringIO()
    report_exception(sys.exc_info(), buf)
    return buf.getvalue()