[PATCH 2 of 2 skos] Add a "get_cnx" method in skos-import command

Denis Laxalde denis.laxalde at logilab.fr
Tue Feb 13 15:18:25 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1517827327 -3600
#      Mon Feb 05 11:42:07 2018 +0100
# Node ID f98a95bcd195b2659ddec596a16d56245ae783e2
# Parent  0a30094c26c5f936d020e6350f481cb7f46b58e1
# Available At http://hg.logilab.org/review/cubes/skos
#              hg pull http://hg.logilab.org/review/cubes/skos -r f98a95bcd195
Add a "get_cnx" method in skos-import command

We override this command in cubicweb-saem_ref and now need access to a
repository connection. The repository cannot however be instantiated
more than once in a given process (it is instantiated from admincnx()
call). So make a cached method to retrieve a connection.

diff --git a/ccplugin.py b/ccplugin.py
--- a/ccplugin.py
+++ b/ccplugin.py
@@ -20,6 +20,7 @@ from __future__ import print_function
 import logging
 import sys
 
+from logilab.common.decorators import cached
 from cubicweb.toolsutils import Command, underline_title
 from cubicweb.cwctl import CWCTL
 from cubicweb.utils import admincnx
@@ -104,9 +105,13 @@ class ImportSkosData(Command):
         'rql': _rql_store_factory,
     }
 
+    @cached
+    def get_cnx(self, appid):
+        return admincnx(appid)
+
     def run(self, args):
         appid = args[0]
-        connection = admincnx(appid)
+        connection = self.get_cnx(appid)
 
         if self.get('format') == 'lcsv':
             scheme_uri = self.get('scheme')



More information about the saem-devel mailing list