@ -14,6 +14,7 @@ import json
import os
import re
import subprocess
import sys
import urllib
import yaml
@ -153,21 +154,41 @@ def get_json_schema_object_fields(obj, enforce_title=False,
required_keys = set ( obj . get ( " required " , [ ] ) )
fields = {
" title " : obj . get ( " title " ) ,
" rows " : [ ]
}
tables = [ fields ]
obj_title = obj . get ( " title " )
first_table_rows = [ ]
tables = [ ]
for key_name in props :
logger . debug ( " Processing property %s . %s " , obj . get ( ' title ' ) , key_name )
prop = inherit_parents ( props [ key_name ] )
try :
logger . debug ( " Processing property %s . %s " , obj_title , key_name )
required = key_name in required_keys
res = process_prop ( key_name , props [ key_name ] , required ,
mark_required )
first_table_rows . append ( res [ " row " ] )
tables . extend ( res [ " tables " ] )
logger . debug ( " Done property %s " % key_name )
except Exception , e :
e2 = Exception ( " Error reading property %s . %s : %s " %
( obj_title , key_name , str ( e ) ) )
raise e2 , None , sys . exc_info ( ) [ 2 ]
tables . insert ( 0 , {
" title " : obj_title ,
" rows " : first_table_rows ,
} )
return tables
def process_prop ( key_name , prop , required , mark_required ) :
prop = inherit_parents ( prop )
value_type = None
required = key_name in required_keys
desc = prop . get ( " description " , " " )
prop_type = prop . get ( ' type ' )
tables = [ ]
if prop_type is None :
raise KeyError ( " Property ' %s ' of object ' %s ' missing ' type ' field "
@ -233,18 +254,20 @@ def get_json_schema_object_fields(obj, enforce_title=False,
if isinstance ( value_type , list ) :
value_type = " or " . join ( value_type )
if required and mark_required :
desc = " **Required.** " + desc
fields [ " rows " ] . append ( {
return {
" row " : {
" key " : key_name ,
" type " : value_type ,
" id " : value_id ,
" required " : required ,
" desc " : desc ,
} )
logger . debug ( " Done property %s " % key_name )
return tables
} ,
" tables " : tables ,
}
def get_tables_for_schema ( schema , mark_required = True ) :
@ -611,9 +634,21 @@ class MatrixUnits(Units):
if not filename . startswith ( " m. " ) :
continue
filepath = os . path . join ( path , filename )
try :
schemata [ filename ] = self . read_event_schema ( filepath )
except Exception , e :
e2 = Exception ( " Error reading event schema " + filepath + " : " +
str ( e ) )
raise e2 , None , sys . exc_info ( ) [ 2 ]
return schemata
def read_event_schema ( self , filepath ) :
self . log ( " Reading %s " % filepath )
with open ( filepath , " r " ) as f :
json_schema = yaml . load ( f )
schema = {
" typeof " : None ,
" typeof_info " : " " ,
@ -692,8 +727,7 @@ class MatrixUnits(Units):
raise Exception ( " Missing description for state_key " )
schema [ " typeof_info " ] = " ``state_key``: %s " % skey_desc
schemata [ filename ] = schema
return schemata
return schema
def load_changelogs ( self ) :
changelogs = { }