← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/strip-initZopeless-out into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/strip-initZopeless-out into lp:launchpad with lp:~wgrant/launchpad/port-to-LaunchpadScript as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/strip-initZopeless-out/+merge/75893

This branch deletes canonical.lp. isZopeless has been inlined into its sole remaining callsite (sendmail), and all initZopeless callsites call the class method on ZopelessTransactionManager directly. LaunchpadScript is still sometimes called with dbuser=None, so move canonical.lp's old compat code to there.
-- 
https://code.launchpad.net/~wgrant/launchpad/strip-initZopeless-out/+merge/75893
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/strip-initZopeless-out into lp:launchpad.
=== modified file 'daemons/buildd-manager.tac'
--- daemons/buildd-manager.tac	2011-09-16 09:00:34 +0000
+++ daemons/buildd-manager.tac	2011-09-18 11:04:27 +0000
@@ -11,12 +11,12 @@
 from lp.buildmaster.manager import BuilddManager
 from lp.services.twistedsupport.loggingsupport import RotatableFileLogObserver
 from canonical.config import config
+from canonical.database.sqlbase import ZopelessTransactionManager
 from canonical.launchpad.daemons import readyservice
 from canonical.launchpad.scripts import execute_zcml_for_scripts
-from canonical.lp import initZopeless
 
 execute_zcml_for_scripts()
-initZopeless(dbuser='buildd_manager')
+ZopelessTransactionManager.initZopeless(dbuser='buildd_manager')
 
 options = ServerOptions()
 options.parseOptions()

=== modified file 'lib/canonical/database/ftests/script_isolation.py'
--- lib/canonical/database/ftests/script_isolation.py	2010-07-16 08:54:42 +0000
+++ lib/canonical/database/ftests/script_isolation.py	2011-09-18 11:04:27 +0000
@@ -16,9 +16,12 @@
     'ignore', '.*(md5|sha|sets)', DeprecationWarning,
     )
 
-from canonical.database.sqlbase import cursor, ISOLATION_LEVEL_SERIALIZABLE
+from canonical.database.sqlbase import (
+    cursor,
+    ISOLATION_LEVEL_SERIALIZABLE,
+    ZopelessTransactionManager,
+    )
 from canonical.launchpad.scripts import execute_zcml_for_scripts
-from canonical.lp import initZopeless
 
 execute_zcml_for_scripts()
 
@@ -37,17 +40,18 @@
     print cur.fetchone()[0]
 
 # First confirm the default isolation level
-txn = initZopeless()
+txn = ZopelessTransactionManager.initZopeless(dbuser='launchpad_main')
 check()
 txn.uninstall()
 
 # We run the checks twice to ensure that both methods of setting the
 # isolation level stick across transaction boundaries.
-txn = initZopeless(isolation=ISOLATION_LEVEL_SERIALIZABLE)
+txn = ZopelessTransactionManager.initZopeless(
+    dbuser='launchpad_main',
+    isolation=ISOLATION_LEVEL_SERIALIZABLE)
 check()
 txn.uninstall()
 
-txn = initZopeless()
+txn = ZopelessTransactionManager.initZopeless(dbuser='launchpad_main')
 txn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE)
 check()
-

=== modified file 'lib/canonical/database/ftests/test_zopelesstransactionmanager.txt'
--- lib/canonical/database/ftests/test_zopelesstransactionmanager.txt	2011-06-09 10:50:25 +0000
+++ lib/canonical/database/ftests/test_zopelesstransactionmanager.txt	2011-09-18 11:04:27 +0000
@@ -8,16 +8,16 @@
 
 == Initialization ==
 
-The ZopelessTransactionManager is initialized with the initZopeless()
-function.
+The ZopelessTransactionManager is initialized with its initZopeless()
+class method.
 
-    >>> from canonical.lp import initZopeless
-    >>> ztm = initZopeless()
+    >>> from canonical.database.sqlbase import ZopelessTransactionManager
+    >>> ztm = ZopelessTransactionManager.initZopeless(
+    ...     dbuser='launchpad_main')
 
 The returned transaction manager happens to be the same as the
 ZopelessTransactionManager class:
 
-    >>> from canonical.database.sqlbase import ZopelessTransactionManager
     >>> ztm is ZopelessTransactionManager
     True
 
@@ -61,7 +61,7 @@
 
 We can log in as alternative users with initZopeless():
 
-    >>> ztm = initZopeless(dbuser='testadmin')
+    >>> ztm = ZopelessTransactionManager.initZopeless(dbuser='testadmin')
     >>> c = cursor()
     >>> c.execute("SELECT current_user")
     >>> print c.fetchone()[0]
@@ -72,8 +72,8 @@
 
     >>> from canonical.database.sqlbase import (
     ...     ISOLATION_LEVEL_SERIALIZABLE)
-    >>> ztm = initZopeless(dbuser='librarian',
-    ...                    isolation=ISOLATION_LEVEL_SERIALIZABLE)
+    >>> ztm = ZopelessTransactionManager.initZopeless(
+    ...     dbuser='librarian', isolation=ISOLATION_LEVEL_SERIALIZABLE)
     >>> c = cursor()
     >>> c.execute("SHOW transaction_isolation")
     >>> print c.fetchone()[0]

=== modified file 'lib/canonical/database/harness.py'
--- lib/canonical/database/harness.py	2011-09-06 06:37:38 +0000
+++ lib/canonical/database/harness.py	2011-09-18 11:04:27 +0000
@@ -50,16 +50,6 @@
     IStoreSelector, MAIN_STORE, MASTER_FLAVOR, SLAVE_FLAVOR, DEFAULT_FLAVOR)
 
 
-def switch_db_user(dbuser, commit_first=True):
-    global transactionmgr
-    if commit_first:
-        transactionmgr.commit()
-    else:
-        transactionmgr.abort()
-    transactionmgr.uninstall()
-    transactionmgr = initZopeless(dbuser=dbuser)
-
-
 def _get_locals():
     if len(sys.argv) > 1:
         dbuser = sys.argv[1]

=== modified file 'lib/canonical/launchpad/doc/scripts-and-zcml.txt'
--- lib/canonical/launchpad/doc/scripts-and-zcml.txt	2010-11-27 21:42:00 +0000
+++ lib/canonical/launchpad/doc/scripts-and-zcml.txt	2011-09-18 11:04:27 +0000
@@ -12,11 +12,9 @@
    >>> script_file.write("""
    ... from canonical.launchpad.scripts import execute_zcml_for_scripts
    ... from lp.registry.interfaces.person import IPersonSet
-   ... from canonical.lp import initZopeless
    ... from zope.component import getUtility
    ...
    ... execute_zcml_for_scripts()
-   ... initZopeless()
    ... print getUtility(IPersonSet).get(1).displayname
    ... """)
    >>> script_file.flush()

=== removed directory 'lib/canonical/lp'
=== removed file 'lib/canonical/lp/__init__.py'
--- lib/canonical/lp/__init__.py	2011-09-06 09:03:15 +0000
+++ lib/canonical/lp/__init__.py	1970-01-01 00:00:00 +0000
@@ -1,38 +0,0 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""This module provides the Zopeless PG environment.
-
-This module is deprecated.
-"""
-
-# This module uses a different naming convention to support the callsites.
-# pylint: disable-msg=C0103
-
-__metaclass__ = type
-
-from canonical.database.postgresql import ConnectionString
-from canonical.config import dbconfig
-from canonical.database.sqlbase import (
-    ISOLATION_LEVEL_DEFAULT, ZopelessTransactionManager)
-
-
-__all__ = [
-    'isZopeless', 'initZopeless',
-    ]
-
-
-def isZopeless():
-    """Returns True if we are running in the Zopeless environment"""
-    # pylint: disable-msg=W0212
-    return ZopelessTransactionManager._installed is not None
-
-
-def initZopeless(dbuser=None, isolation=ISOLATION_LEVEL_DEFAULT):
-    """Initialize the Zopeless environment."""
-    if dbuser is None:
-        dbuser = (
-            ConnectionString(dbconfig.main_master).user or dbconfig.dbuser)
-
-    return ZopelessTransactionManager.initZopeless(
-        dbuser=dbuser, isolation=isolation)

=== removed directory 'lib/canonical/lp/ftests'
=== removed file 'lib/canonical/lp/ftests/__init__.py'
=== removed file 'lib/canonical/lp/ftests/test_zopeless.py'
--- lib/canonical/lp/ftests/test_zopeless.py	2011-09-13 12:14:00 +0000
+++ lib/canonical/lp/ftests/test_zopeless.py	1970-01-01 00:00:00 +0000
@@ -1,34 +0,0 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""
-Tests to make sure that initZopeless works as expected.
-"""
-
-from doctest import DocTestSuite
-from canonical.lp import initZopeless
-from canonical.testing.layers import ZopelessDatabaseLayer
-
-
-def test_isZopeless():
-    """
-    >>> from canonical.lp import isZopeless
-
-    >>> isZopeless()
-    False
-
-    >>> tm = initZopeless(dbuser='launchpad')
-    >>> isZopeless()
-    True
-
-    >>> tm.uninstall()
-    >>> isZopeless()
-    False
-
-    """
-
-
-def test_suite():
-    doctests = DocTestSuite()
-    doctests.layer = ZopelessDatabaseLayer
-    return doctests

=== modified file 'lib/canonical/testing/layers.py'
--- lib/canonical/testing/layers.py	2011-09-16 09:45:39 +0000
+++ lib/canonical/testing/layers.py	2011-09-18 11:04:27 +0000
@@ -129,7 +129,6 @@
     set_default_timeout_function,
     )
 from canonical.librarian.testing.server import LibrarianServerFixture
-from canonical.lp import initZopeless
 from canonical.testing import reset_logging
 from canonical.testing.profiled import profiled
 from canonical.testing.smtpd import SMTPController
@@ -1529,7 +1528,7 @@
         if ZopelessTransactionManager._installed is not None:
             raise LayerIsolationError(
                 "Last test using Zopeless failed to tearDown correctly")
-        initZopeless()
+        ZopelessTransactionManager.initZopeless(dbuser='launchpad_main')
 
         # Connect Storm
         reconnect_stores()
@@ -1565,7 +1564,7 @@
         initZopeless with the given keyword arguments.
         """
         ZopelessTransactionManager.uninstall()
-        initZopeless(**kw)
+        ZopelessTransactionManager.initZopeless(**kw)
 
 
 class ExperimentalLaunchpadZopelessLayer(LaunchpadZopelessLayer):

=== modified file 'lib/lp/services/job/runner.py'
--- lib/lp/services/job/runner.py	2011-09-09 19:35:12 +0000
+++ lib/lp/services/job/runner.py	2011-09-18 11:04:27 +0000
@@ -55,9 +55,9 @@
 from zope.security.proxy import removeSecurityProxy
 
 from canonical.config import config
+from canonical.database.sqlbase import ZopelessTransactionManager
 from canonical.launchpad import scripts
 from canonical.launchpad.webapp import errorlog
-from canonical.lp import initZopeless
 from lp.services.job.interfaces.job import (
     IJob,
     IRunnableJob,
@@ -369,7 +369,7 @@
             raise TimeoutError
         scripts.execute_zcml_for_scripts(use_web_security=False)
         signal(SIGHUP, handler)
-        initZopeless(dbuser=cls.dbuser)
+        ZopelessTransactionManager.initZopeless(dbuser=cls.dbuser)
 
     @staticmethod
     def __exit__(exc_type, exc_val, exc_tb):

=== modified file 'lib/lp/services/mail/sendmail.py'
--- lib/lp/services/mail/sendmail.py	2011-09-18 11:04:27 +0000
+++ lib/lp/services/mail/sendmail.py	2011-09-18 11:04:27 +0000
@@ -51,7 +51,7 @@
 from zope.sendmail.interfaces import IMailDelivery
 
 from canonical.config import config
-from canonical.lp import isZopeless
+from canonical.database.sqlbase import ZopelessTransactionManager
 from lp.app import versioninfo
 from lp.services.encoding import is_ascii_only
 from lp.services.mail.stub import TestMailer
@@ -422,7 +422,7 @@
 
     raw_message = message.as_string()
     message_detail = message['Subject']
-    if isZopeless():
+    if ZopelessTransactionManager._installed is not None:
         # Zopeless email sending is not unit tested, and won't be.
         # The zopeless specific stuff is pretty simple though so this
         # should be fine.

=== modified file 'lib/lp/services/scripts/base.py'
--- lib/lp/services/scripts/base.py	2011-08-14 23:11:45 +0000
+++ lib/lp/services/scripts/base.py	2011-09-18 11:04:27 +0000
@@ -32,8 +32,12 @@
 import pytz
 from zope.component import getUtility
 
-from canonical.config import config
-from canonical.database.sqlbase import ISOLATION_LEVEL_DEFAULT
+from canonical.config import config, dbconfig
+from canonical.database.postgresql import ConnectionString
+from canonical.database.sqlbase import (
+    ISOLATION_LEVEL_DEFAULT,
+    ZopelessTransactionManager,
+    )
 from canonical.launchpad import scripts
 from canonical.launchpad.scripts.logger import OopsHandler
 from canonical.launchpad.webapp.errorlog import globalErrorUtility
@@ -41,7 +45,6 @@
     ANONYMOUS,
     setupInteractionByEmail,
     )
-from canonical.lp import initZopeless
 from lp.services.features import (
     get_relevant_feature_controller,
     install_feature_controller,
@@ -352,7 +355,12 @@
 
         Can be overriden for testing purpose.
         """
-        self.txn = initZopeless(dbuser=self.dbuser, isolation=isolation)
+        dbuser = self.dbuser
+        if dbuser is None:
+            connstr = ConnectionString(dbconfig.main_master)
+            dbuser = connstr.user or dbconfig.dbuser
+        self.txn = ZopelessTransactionManager.initZopeless(
+            dbuser=dbuser, isolation=isolation)
 
     def record_activity(self, date_started, date_completed):
         """Hook to record script activity."""

=== modified file 'utilities/check-templates.sh'
--- utilities/check-templates.sh	2011-02-25 10:12:09 +0000
+++ utilities/check-templates.sh	2011-09-18 11:04:27 +0000
@@ -7,7 +7,7 @@
 
 LPDIR=lib/canonical/launchpad
 REGISTRY="lib/canonical/launchpad/zcml/*.zcml lib/canonical/*.zcml
-          lib/canonical/launchpad/*.zcml lib/canonical/lp/*.zcml *.zcml 
+          lib/canonical/launchpad/*.zcml *.zcml 
           lib/zope/app/exception/browser/configure.zcml
           lib/zope/app/debugskin/configure.zcml
           lib/canonical/launchpad/webapp/*.zcml