[server] drop system_source_cnx for a simpler internal API
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Fri, 15 Mar 2019 21:35:59 +0100
changeset 12884 9754c40c732a
parent 12883 d5bbf030f967
child 12885 194e9ae964ed
[server] drop system_source_cnx for a simpler internal API system_source_cnx() can be replaced with source_cnx(). If system_source_cnx() is called with dbms_system_base=False, it is strictly equivalent to calling source_cnx() with the same source, privileges and interactivity. If system_source_cnx() is called with dbms_system_base=True, it is equivalent to calling source_cnx() with the system database and the same source, privileges and interactivity. No use of the default value for 'special_privs' was found in the code.
cubicweb/devtools/__init__.py
cubicweb/server/serverctl.py
--- a/cubicweb/devtools/__init__.py	Wed Mar 13 00:01:35 2019 +0100
+++ b/cubicweb/devtools/__init__.py	Fri Mar 15 21:35:59 2019 +0100
@@ -624,14 +624,14 @@
     def init_test_database(self):
         """initialize a fresh postgresql database used for testing purpose"""
         from cubicweb.server import init_repository
-        from cubicweb.server.serverctl import system_source_cnx, createdb
+        from cubicweb.server.serverctl import source_cnx, createdb
         # connect on the dbms system base to create our base
         try:
             self._drop(self.system_source['db-name'])
             createdb(self.helper, self.system_source, self.dbcnx, self.cursor)
             self.dbcnx.commit()
-            cnx = system_source_cnx(self.system_source, special_privs='LANGUAGE C',
-                                    interactive=False)
+            cnx = source_cnx(self.system_source, special_privs='LANGUAGE C',
+                             interactive=False)
             templcursor = cnx.cursor()
             try:
                 # XXX factorize with db-create code
--- a/cubicweb/server/serverctl.py	Wed Mar 13 00:01:35 2019 +0100
+++ b/cubicweb/server/serverctl.py	Fri Mar 15 21:35:59 2019 +0100
@@ -26,6 +26,7 @@
 
 from logilab.common.configuration import Configuration, merge_options
 from logilab.common.shellutils import ASK, generate_password
+from logilab.common.deprecation import deprecated
 
 from logilab.database import get_db_helper, get_connection
 
@@ -96,6 +97,9 @@
     return cnx
 
 
+@deprecated('[3.28] instead of system_source_cnx(source, True, **args) use '
+            'source_cnx(source, get_db_helper(source[\'db-driver\']).system_database(), '
+            '**args)')
 def system_source_cnx(source, dbms_system_base=False,
                       special_privs='CREATE/DROP DATABASE', interactive=True):
     """shortcut to get a connextion to the instance system database
@@ -118,8 +122,9 @@
     import logilab.common as lgp
     lgp.USE_MX_DATETIME = False
     # connect on the dbms system base to create our base
-    cnx = system_source_cnx(source, True, special_privs=special_privs,
-                            interactive=interactive)
+    system_db = get_db_helper(source['db-driver']).system_database()
+    cnx = source_cnx(source, system_db, special_privs=special_privs,
+                     interactive=interactive)
     # disable autocommit (isolation_level(1)) because DROP and
     # CREATE DATABASE can't be executed in a transaction
     set_isolation_level = getattr(cnx, 'set_isolation_level', None)
@@ -201,7 +206,7 @@
 @contextmanager
 def db_transaction(source, privilege):
     """Open a transaction to the instance database"""
-    cnx = system_source_cnx(source, special_privs=privilege)
+    cnx = source_cnx(source, special_privs=privilege)
     cursor = cnx.cursor()
     try:
         yield cursor
@@ -379,8 +384,8 @@
             except BaseException:
                 dbcnx.rollback()
                 raise
-        cnx = system_source_cnx(source, special_privs='CREATE LANGUAGE/SCHEMA',
-                                interactive=not automatic)
+        cnx = source_cnx(source, special_privs='CREATE LANGUAGE/SCHEMA',
+                         interactive=not automatic)
         cursor = cnx.cursor()
         helper.init_fti_extensions(cursor)
         namespace = source.get('db-namespace')
@@ -572,7 +577,7 @@
         config = ServerConfiguration.config_for(appid)
         source = config.system_source_config
         set_owner = self.config.set_owner
-        cnx = system_source_cnx(source, special_privs='GRANT')
+        cnx = source_cnx(source, special_privs='GRANT')
         cursor = cnx.cursor()
         schema = config.load_schema()
         try: