server/serverctl.py
changeset 9303 e84414be8506
parent 9002 f98d1c46ed9f
child 9457 d5ed6efd6448
child 9922 fc02ba8654a7
equal deleted inserted replaced
9302:af36f459d2f0 9303:e84414be8506
  1063         stats = source.pull_data(session, force=True, raise_on_error=True)
  1063         stats = source.pull_data(session, force=True, raise_on_error=True)
  1064         for key, val in stats.iteritems():
  1064         for key, val in stats.iteritems():
  1065             if val:
  1065             if val:
  1066                 print key, ':', val
  1066                 print key, ':', val
  1067 
  1067 
       
  1068 
       
  1069 
       
  1070 def permissionshandler(relation, perms):
       
  1071     from yams.schema import RelationDefinitionSchema
       
  1072     from yams.buildobjs import DEFAULT_ATTRPERMS
       
  1073     from cubicweb.schema import (PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS,
       
  1074                                  PUB_SYSTEM_ATTR_PERMS, RO_REL_PERMS, RO_ATTR_PERMS)
       
  1075     defaultrelperms = (DEFAULT_ATTRPERMS, PUB_SYSTEM_REL_PERMS,
       
  1076                        PUB_SYSTEM_ATTR_PERMS, RO_REL_PERMS, RO_ATTR_PERMS)
       
  1077     defaulteperms = (PUB_SYSTEM_ENTITY_PERMS,)
       
  1078     # canonicalize vs str/unicode
       
  1079     for p in ('read', 'add', 'update', 'delete'):
       
  1080         rule = perms.get(p)
       
  1081         if rule:
       
  1082             perms[p] = tuple(str(x) if isinstance(x, basestring) else x
       
  1083                              for x in rule)
       
  1084     return perms, perms in defaultrelperms or perms in defaulteperms
       
  1085 
       
  1086 
  1068 class SchemaDiffCommand(Command):
  1087 class SchemaDiffCommand(Command):
  1069     """Generate a diff between schema and fsschema description.
  1088     """Generate a diff between schema and fsschema description.
  1070 
  1089 
  1071     <instance>
  1090     <instance>
  1072       the identifier of the instance
  1091       the identifier of the instance
  1083         diff_tool = args.pop(0)
  1102         diff_tool = args.pop(0)
  1084         config = ServerConfiguration.config_for(appid)
  1103         config = ServerConfiguration.config_for(appid)
  1085         repo, cnx = repo_cnx(config)
  1104         repo, cnx = repo_cnx(config)
  1086         session = repo._get_session(cnx.sessionid, setcnxset=True)
  1105         session = repo._get_session(cnx.sessionid, setcnxset=True)
  1087         fsschema = config.load_schema(expand_cubes=True)
  1106         fsschema = config.load_schema(expand_cubes=True)
  1088         schema_diff(repo.schema, fsschema, diff_tool)
  1107         schema_diff(fsschema, repo.schema, permissionshandler, diff_tool, ignore=('eid',))
  1089 
  1108 
  1090 
  1109 
  1091 for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand,
  1110 for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand,
  1092                  GrantUserOnInstanceCommand, ResetAdminPasswordCommand,
  1111                  GrantUserOnInstanceCommand, ResetAdminPasswordCommand,
  1093                  StartRepositoryCommand,
  1112                  StartRepositoryCommand,