[PATCH saem_ref] Set initial value of _count parameter of init_seda_scheme() from db

Denis Laxalde denis.laxalde at logilab.fr
Mon Oct 16 17:31:01 CEST 2017


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1508167844 -7200
#      Mon Oct 16 17:30:44 2017 +0200
# Node ID 86864544ea0fd3234607ca08780d53832b8b0ba9
# Parent  cb66f34c60172f250bfc2835a01685992bc98d5d
Set initial value of _count parameter of init_seda_scheme() from db

Instead of always starting from 0, we use the existing entities' ark as
initial value for generating ARK of imported concept schemes.

diff --git a/cubicweb_saem_ref/site_cubicweb.py b/cubicweb_saem_ref/site_cubicweb.py
--- a/cubicweb_saem_ref/site_cubicweb.py
+++ b/cubicweb_saem_ref/site_cubicweb.py
@@ -116,13 +116,25 @@ ImportSkosData.cw_store_factories['nohoo
 # override seda's scheme initialization to set ark on each scheme, and to use an ark enabled store
 
 @monkeypatch(seda_dataimport)
-def init_seda_scheme(cnx, title, _count=[0]):
+def init_seda_scheme(cnx, title, _count=[]):
     description = u'edition 2009' if title.startswith('SEDA :') else None
     # 25651 = Archives départementales de la Gironde (ADGIRONDE)
     # XXX ensure that:
     # * NAA for those vocabulary is 25651
     # * generated ark are identical from one instance to another (for scheme and concepts, see
     #   below)
+
+    if not _count:
+        rset = cnx.execute(
+            'String ARK ORDERBY CD DESC LIMIT 1'
+            ' WHERE X creation_date CD, X ark LIKE "25651/v%", X ark ARK'
+        )
+        if not rset:
+            value = 0
+        else:
+            value = int(rset[0][0][len('25651/v'):])
+        _count.append(value)
+
     _count[0] += 1
     ark = u'25651/v%s' % _count[0]
     if cnx.vreg.config.repairing:  # XXX seda 0.8 migration


More information about the saem-devel mailing list