[serverctl] complete the schema-diff command with options that will fix & enhance it.
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 08 Oct 2013 14:25:05 +0200
changeset 9303 e84414be8506
parent 9302 af36f459d2f0
child 9304 ff61b10e7415
[serverctl] complete the schema-diff command with options that will fix & enhance it. Notably: - filter out eids (doesn't make sense for the filesystem schema) - handle permissions, trying to detect the default ones Needs yams #174042. Closes #2996547.
server/serverctl.py
--- a/server/serverctl.py	Fri Oct 18 16:58:48 2013 +0200
+++ b/server/serverctl.py	Tue Oct 08 14:25:05 2013 +0200
@@ -1065,6 +1065,25 @@
             if val:
                 print key, ':', val
 
+
+
+def permissionshandler(relation, perms):
+    from yams.schema import RelationDefinitionSchema
+    from yams.buildobjs import DEFAULT_ATTRPERMS
+    from cubicweb.schema import (PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS,
+                                 PUB_SYSTEM_ATTR_PERMS, RO_REL_PERMS, RO_ATTR_PERMS)
+    defaultrelperms = (DEFAULT_ATTRPERMS, PUB_SYSTEM_REL_PERMS,
+                       PUB_SYSTEM_ATTR_PERMS, RO_REL_PERMS, RO_ATTR_PERMS)
+    defaulteperms = (PUB_SYSTEM_ENTITY_PERMS,)
+    # canonicalize vs str/unicode
+    for p in ('read', 'add', 'update', 'delete'):
+        rule = perms.get(p)
+        if rule:
+            perms[p] = tuple(str(x) if isinstance(x, basestring) else x
+                             for x in rule)
+    return perms, perms in defaultrelperms or perms in defaulteperms
+
+
 class SchemaDiffCommand(Command):
     """Generate a diff between schema and fsschema description.
 
@@ -1085,7 +1104,7 @@
         repo, cnx = repo_cnx(config)
         session = repo._get_session(cnx.sessionid, setcnxset=True)
         fsschema = config.load_schema(expand_cubes=True)
-        schema_diff(repo.schema, fsschema, diff_tool)
+        schema_diff(fsschema, repo.schema, permissionshandler, diff_tool, ignore=('eid',))
 
 
 for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand,