def main(self):
        """See `LaunchpadScript`."""
        # Avoid circular imports.
        from lp.registry.model.product import Product
        from lp.registry.model.productseries import ProductSeries

        errorlog.globalErrorUtility.configure(self.config_name)
        if self.options.no_fudge:
            self.fudge_factor = timedelta(0)

        self.logger.info("Exporting to translations branches.")

        self.store = ISlaveStore(Product)

        product_join = Join(
            ProductSeries, Product, ProductSeries.product == Product.id)
        productseries = self.store.using(product_join).find(
            ProductSeries,
            And(
                Product.translations_usage == ServiceUsage.LAUNCHPAD,
                ProductSeries.translations_branch != None))

        # Anything deterministic will do, and even that is only for
        # testing.
        productseries = productseries.order_by(ProductSeries.id)

        bzrserver = get_rw_server()
        bzrserver.start_server()
        try:
            self._exportToBranches(productseries)
        finally:
            bzrserver.stop_server()
Пример #2
0
    def run(self, _check_transaction=False):
        """See `IBranchUpgradeJob`."""
        # Set up the new branch structure
        with server(get_rw_server(), no_replace=True):
            upgrade_branch_path = tempfile.mkdtemp()
            try:
                upgrade_transport = get_transport(upgrade_branch_path)
                upgrade_transport.mkdir('.bzr')
                source_branch_transport = get_transport(
                    self.branch.getInternalBzrUrl())
                source_branch_transport.clone('.bzr').copy_tree_to_transport(
                    upgrade_transport.clone('.bzr'))
                transaction.commit()
                upgrade_branch = BzrBranch.open_from_transport(
                    upgrade_transport)

                # No transactions are open so the DB connection won't be
                # killed.
                with TransactionFreeOperation():
                    # Perform the upgrade.
                    upgrade(upgrade_branch.base)

                # Re-open the branch, since its format has changed.
                upgrade_branch = BzrBranch.open_from_transport(
                    upgrade_transport)
                source_branch = BzrBranch.open_from_transport(
                    source_branch_transport)

                source_branch.lock_write()
                upgrade_branch.pull(source_branch)
                upgrade_branch.fetch(source_branch)
                source_branch.unlock()

                # Move the branch in the old format to backup.bzr
                try:
                    source_branch_transport.delete_tree('backup.bzr')
                except NoSuchFile:
                    pass
                source_branch_transport.rename('.bzr', 'backup.bzr')
                source_branch_transport.mkdir('.bzr')
                upgrade_transport.clone('.bzr').copy_tree_to_transport(
                    source_branch_transport.clone('.bzr'))

                # Re-open the source branch again.
                source_branch = BzrBranch.open_from_transport(
                    source_branch_transport)

                formats = get_branch_formats(source_branch)

                self.branch.branchChanged(
                    self.branch.stacked_on,
                    self.branch.last_scanned_id,
                    *formats)
            finally:
                shutil.rmtree(upgrade_branch_path)
Пример #3
0
    def run(self, _check_transaction=False):
        """See `IBranchUpgradeJob`."""
        # Set up the new branch structure
        with server(get_rw_server(), no_replace=True):
            upgrade_branch_path = tempfile.mkdtemp()
            try:
                upgrade_transport = get_transport(upgrade_branch_path)
                upgrade_transport.mkdir('.bzr')
                source_branch_transport = get_transport(
                    self.branch.getInternalBzrUrl())
                source_branch_transport.clone('.bzr').copy_tree_to_transport(
                    upgrade_transport.clone('.bzr'))
                transaction.commit()
                upgrade_branch = BzrBranch.open_from_transport(
                    upgrade_transport)

                # No transactions are open so the DB connection won't be
                # killed.
                with TransactionFreeOperation():
                    # Perform the upgrade.
                    upgrade(upgrade_branch.base)

                # Re-open the branch, since its format has changed.
                upgrade_branch = BzrBranch.open_from_transport(
                    upgrade_transport)
                source_branch = BzrBranch.open_from_transport(
                    source_branch_transport)

                source_branch.lock_write()
                upgrade_branch.pull(source_branch)
                upgrade_branch.fetch(source_branch)
                source_branch.unlock()

                # Move the branch in the old format to backup.bzr
                try:
                    source_branch_transport.delete_tree('backup.bzr')
                except NoSuchFile:
                    pass
                source_branch_transport.rename('.bzr', 'backup.bzr')
                source_branch_transport.mkdir('.bzr')
                upgrade_transport.clone('.bzr').copy_tree_to_transport(
                    source_branch_transport.clone('.bzr'))

                # Re-open the source branch again.
                source_branch = BzrBranch.open_from_transport(
                    source_branch_transport)

                formats = get_branch_formats(source_branch)

                self.branch.branchChanged(
                    self.branch.stacked_on,
                    self.branch.last_scanned_id,
                    *formats)
            finally:
                shutil.rmtree(upgrade_branch_path)
Пример #4
0
 def main(self):
     if len(self.args) != 3:
         self.parser.error("Wrong number of arguments.")
     brancher = DistroBrancher.fromNames(self.logger, *self.args)
     server = get_rw_server(direct_database=True)
     server.start_server()
     try:
         if self.options.check:
             if not brancher.checkNewBranches():
                 raise LaunchpadScriptFailure("Check failed")
         else:
             brancher.makeNewBranches()
     finally:
         server.stop_server()
Пример #5
0
 def main(self):
     if self.options.dry_run:
         server = get_ro_server()
     else:
         server = get_rw_server()
     server.start_server()
     if self.options.dry_run:
         self.logger.debug('Running read-only')
     self.logger.debug('Beginning processing')
     try:
         self.updateBranches(self.parseFromStream(sys.stdin))
     finally:
         server.stop_server()
     self.logger.info('Done')
Пример #6
0
 def main(self):
     if len(self.args) != 3:
         self.parser.error("Wrong number of arguments.")
     brancher = DistroBrancher.fromNames(self.logger, *self.args)
     server = get_rw_server(direct_database=True)
     server.start_server()
     try:
         if self.options.check:
             if not brancher.checkNewBranches():
                 raise LaunchpadScriptFailure("Check failed")
         else:
             brancher.makeNewBranches()
     finally:
         server.stop_server()
 def main(self):
     if self.options.dry_run:
         server = get_ro_server()
     else:
         server = get_rw_server()
     server.start_server()
     if self.options.dry_run:
         self.logger.debug('Running read-only')
     self.logger.debug('Beginning processing')
     try:
         self.updateBranches(self.parseFromStream(sys.stdin))
     finally:
         server.stop_server()
     self.logger.info('Done')
Пример #8
0
    def mirrorWithoutChecks(self):
        """Mirror the source branch to the destination branch.

        This method doesn't do any error handling or send any messages via the
        reporting protocol -- a "naked mirror", if you will. This is
        particularly useful for tests that want to mirror a branch and be
        informed immediately of any errors.

        :return: ``(branch, revid_before)``, where ``branch`` is the
            destination branch and ``revid_before`` was the tip revision
            *before* the mirroring process ran.
        """
        # Avoid circular import
        from lp.codehosting.vfs import get_rw_server

        server = get_rw_server()
        server.start_server()
        try:
            source_branch = self.branch_mirrorer.open(self.source)
            return self.branch_mirrorer.mirror(source_branch, self.dest)
        finally:
            server.stop_server()