[PATCH 1 of 2 saem_ref] Call sys.exit() and shutdown repository out of cnx context manager in skos-import command

Denis Laxalde denis.laxalde at logilab.fr
Wed Feb 14 13:27:55 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1518606672 -3600
#      Wed Feb 14 12:11:12 2018 +0100
# Node ID 443b6d88fe674dc029ce6a32157f2914b1c177ab
# Parent  cf2932ee1017b70f43bf0b20d93d0e160574868c
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 443b6d88fe67
# EXP-Topic ark/postgres-generated
Call sys.exit() and shutdown repository out of cnx context manager in skos-import command

Otherwise, the repository isn't properly shut down and this will pose
problem when we'll use postgres in tests.

diff --git a/cubicweb_saem_ref/ccplugin.py b/cubicweb_saem_ref/ccplugin.py
--- a/cubicweb_saem_ref/ccplugin.py
+++ b/cubicweb_saem_ref/ccplugin.py
@@ -145,24 +145,29 @@ def run(self, args):
             sys.exit(1)
         scheme_ark = scheme_ark.strip().decode('utf-8')
         appid = args[0]
-        with self.get_cnx(appid) as cnx:
-            if scheme_ark.startswith(u'ark:/'):
-                scheme_ark = scheme_ark[len(u'ark:/'):]
-            rset = cnx.find('ConceptScheme', ark=scheme_ark)
-            if not rset:
-                print(u'command failed: no concept scheme found matching "%s"'
-                      % scheme_ark)
-                sys.exit(1)
-            scheme = rset.one()
-            # cubicweb-skos's command need a cwuri for --scheme.
-            setattr(self.config, 'scheme', scheme.cwuri)
-            # Per schema, ark_naa is optional for ConceptScheme.
-            if not scheme.ark_naa:
-                print(u'command failed: specified concept scheme "%s" must have an ARK NAA set'
-                      % scheme_ark)
-                sys.exit(1)
-            naa_what = scheme.ark_naa[0].what
-            print(u'Importing concepts in %s' % scheme.absolute_url())
+        connection = self.get_cnx(appid)
+        try:
+            with connection as cnx:
+                if scheme_ark.startswith(u'ark:/'):
+                    scheme_ark = scheme_ark[len(u'ark:/'):]
+                rset = cnx.find('ConceptScheme', ark=scheme_ark)
+                if not rset:
+                    print(u'command failed: no concept scheme found matching "%s"'
+                          % scheme_ark)
+                    raise Exception
+                scheme = rset.one()
+                # cubicweb-skos's command need a cwuri for --scheme.
+                setattr(self.config, 'scheme', scheme.cwuri)
+                # Per schema, ark_naa is optional for ConceptScheme.
+                if not scheme.ark_naa:
+                    print(u'command failed: specified concept scheme "%s" must have an ARK NAA set'
+                          % scheme_ark)
+                    raise Exception
+                naa_what = scheme.ark_naa[0].what
+                print(u'Importing concepts in %s' % scheme.absolute_url())
+        except Exception:
+            connection.repo.shutdown()
+            sys.exit(1)
         # Set a "config" attribute which will be retrieved from metadata
         # generator defined in __init__.py.
         setattr(self.config, 'naa_what', naa_what)



More information about the saem-devel mailing list