schema.py revision da97433d5cd26e422a370d186f98659383c06721
da97433d5cd26e422a370d186f98659383c06721csovant# CDDL HEADER START
da97433d5cd26e422a370d186f98659383c06721csovant# The contents of this file are subject to the terms of the
da97433d5cd26e422a370d186f98659383c06721csovant# Common Development and Distribution License, Version 1.0 only
da97433d5cd26e422a370d186f98659383c06721csovant# (the "License"). You may not use this file except in compliance
da97433d5cd26e422a370d186f98659383c06721csovant# with the License.
da97433d5cd26e422a370d186f98659383c06721csovant# You can obtain a copy of the license at
da97433d5cd26e422a370d186f98659383c06721csovant# See the License for the specific language governing permissions
da97433d5cd26e422a370d186f98659383c06721csovant# and limitations under the License.
da97433d5cd26e422a370d186f98659383c06721csovant# When distributing Covered Code, include this CDDL HEADER in each
da97433d5cd26e422a370d186f98659383c06721csovant# file and include the License file at
da97433d5cd26e422a370d186f98659383c06721csovant# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
da97433d5cd26e422a370d186f98659383c06721csovant# add the following below this CDDL HEADER, with the fields enclosed
da97433d5cd26e422a370d186f98659383c06721csovant# information:
da97433d5cd26e422a370d186f98659383c06721csovant# Portions Copyright [yyyy] [name of copyright owner]
da97433d5cd26e422a370d186f98659383c06721csovant# CDDL HEADER END
da97433d5cd26e422a370d186f98659383c06721csovant# Copyright 2009 Sun Microsystems, Inc.
da97433d5cd26e422a370d186f98659383c06721csovant# Global variable containing the list of servers ("Server" class instances) deployed
da97433d5cd26e422a370d186f98659383c06721csovant# Define ChangelogServer class
da97433d5cd26e422a370d186f98659383c06721csovant """OIDDict is a dictionary class that help lookup OID <-> litteral name
da97433d5cd26e422a370d186f98659383c06721csovant of both objeclasses, and attributtypes"""
da97433d5cd26e422a370d186f98659383c06721csovant """given a schema entry definition for objectclass/attributtype
da97433d5cd26e422a370d186f98659383c06721csovant return the tuple (OID,List of names)
da97433d5cd26e422a370d186f98659383c06721csovant the List of aliases starts from list of names[1:] when exist. for ex :
da97433d5cd26e422a370d186f98659383c06721csovant attributeTypes: ( 2.5.4.4 NAME ( 'sn' 'surname' ) SUP name X-ORIGIN 'RFC 4519' )
da97433d5cd26e422a370d186f98659383c06721csovant (2.5.4.4,['sn','surname']
da97433d5cd26e422a370d186f98659383c06721csovant # populate the NAME to OID : "dict" dictionary
da97433d5cd26e422a370d186f98659383c06721csovant # TODO encoded schema is not handled for now
da97433d5cd26e422a370d186f98659383c06721csovant # populate SUP and MUST / MAY, : "sup", "may", "must" dictionaries
da97433d5cd26e422a370d186f98659383c06721csovant """extract a list of attributes for a given myStr section.
da97433d5cd26e422a370d186f98659383c06721csovant The section should contain () when multivalued.
da97433d5cd26e422a370d186f98659383c06721csovant If another section comes after it starts with a Upercase.
da97433d5cd26e422a370d186f98659383c06721csovant example MUST (sn cn) MAY ( description ... )
da97433d5cd26e422a370d186f98659383c06721csovant line : line to parse
da97433d5cd26e422a370d186f98659383c06721csovant myStr : name of the section ex(MAY)
da97433d5cd26e422a370d186f98659383c06721csovant right : right boundary,
da97433d5cd26e422a370d186f98659383c06721csovant if None, function will figure out end of section"""
da97433d5cd26e422a370d186f98659383c06721csovant return None
da97433d5cd26e422a370d186f98659383c06721csovant """will return the attributes the objectclassname MUST implement"""
da97433d5cd26e422a370d186f98659383c06721csovant # avoiding duplication of MUSTs
da97433d5cd26e422a370d186f98659383c06721csovant ret.extend([e for e in self.getMust(h) if ret.count(e) == 0])
da97433d5cd26e422a370d186f98659383c06721csovant """will return the attributes the objectclassname MAY implement"""
da97433d5cd26e422a370d186f98659383c06721csovant # avoiding duplication of MAYs
da97433d5cd26e422a370d186f98659383c06721csovant ret.extend([e for e in self.getMay(h) if ret.count(e) == 0])
da97433d5cd26e422a370d186f98659383c06721csovant """will return the objectclassname that this objectclassname inherit"""
da97433d5cd26e422a370d186f98659383c06721csovant return None
da97433d5cd26e422a370d186f98659383c06721csovant """get the schema as a string
da97433d5cd26e422a370d186f98659383c06721csovant lookit up line by line, extracting OID/literal name for objectclasses
da97433d5cd26e422a370d186f98659383c06721csovant and attributetypes only."""
da97433d5cd26e422a370d186f98659383c06721csovant # not handled for now
da97433d5cd26e422a370d186f98659383c06721csovant # line continuation aggregated into 'line'
da97433d5cd26e422a370d186f98659383c06721csovant elif f.startswith("objectClasses") or f.startswith("attributeTypes"):
da97433d5cd26e422a370d186f98659383c06721csovant # populate the OID <-> Names dictionary
da97433d5cd26e422a370d186f98659383c06721csovant """get example schema.ldif file with :
da97433d5cd26e422a370d186f98659383c06721csovant ldapsearch -b 'cn=schema' -Dcn=directory\ manager -s base -wpassword objectclass=* objectClasses attributeTypes
da97433d5cd26e422a370d186f98659383c06721csovant print "%s\t%s"%(k,v)
da97433d5cd26e422a370d186f98659383c06721csovant print "%s\t%s"%(k,v)
da97433d5cd26e422a370d186f98659383c06721csovant print "%s\t%s"%(k,v)
da97433d5cd26e422a370d186f98659383c06721csovant print "%s\t%s"%(k,v)
da97433d5cd26e422a370d186f98659383c06721csovant for cn in ['rFC822LocalPart','inetOrgPerson','top','doMain','2.5.6.7','BLAH']: