52 Introduction and usage of CMRimport osfrom cmr import Unitsfrom cmr . base . schema import Schemafrom cmr . base . schema import XML CALCULATORc l a s s NewCSchema( Schema ) :d e f i n i t ( s e l f , name , hash schema=” d e f a u l t ” ) :Schema . i n i t ( s e l f , name , hash schema=hash schema )c a l c u l a t o r = {” ase atomic numbers ” : {”cmr name ” : ” ase atomic numbers ” ,” type ” : ” l o n g a r r a y ” ,” o p t i o n a l ” : ” True ” ,” python type ” : ” l i s t ” ,” m o s t i n n e r p y t h o n t y p e ” : ” i n t ” ,” hash ” : True } ,” a s e p o s i t i o n s ” : {”cmr name ” : ” a s e p o s i t i o n s ” ,” type ” : ” l o n g x a r r a y ” ,” o p t i o n a l ” : ” True ” ,” python type ” : ” l i s t ” ,” m o s t i n n e r p y t h o n t y p e ” : ” i n t ” ,” hash ” : True } ,”atoms ” : {”cmr name ” : ” atoms ” ,” type ” : ” l o n g a r r a y ” ,” o p t i o n a l ” : ” True ” ,” python type ” : ” l i s t ” ,” m o s t i n n e r p y t h o n t y p e ” : ” i n t ” ,” hash ” : True } ,”name ” : {”cmr name ” : ” name ” ,” type ” : ” s t r i n g ” ,” o p t i o n a l ” : ” True ” ,” python type ” : ” s t r ” ,” hash ” : True } ,” p o s i t i o n s ” : {”cmr name ” : ” p o s i t i o n s ” ,” type ” : ” l o n g x a r r a y ” ,” o p t i o n a l ” : ” True ” ,” python type ” : ” l i s t ” ,” m o s t i n n e r p y t h o n t y p e ” : ” i n t ” ,” hash ” : True } ,}s e l f . append (XML CALCULATOR, c a l c u l a t o r )s e l f . a p p l y d e f a u l t v a l u e s ( )s e l f . apply hash schema ( )d e f g e t m y f i l e n a m e ( s e l f ) :r e t u r n os . path . basename ( f i l e )Figure 2.30: newc 03 20110523.py: Creates the main part for a CMR schema automatically.
2.9 Advanced Task 53from cmr import runtimed e f i n f o ( ) :i n f o = [ { ” name ” : ” newc2db ” , #module name” author ” : ” cmr ” ,” type ” : ” c o n v e r t e r ” ,” classname ” : ”NewC2Db” ,” v e r s i o n ” : ” newcalc −0.3 −20110523” ,”module ” : ” newc . newc2db ”} ,{”name ” : ” newc 03 20110523 ” , #module name” author ” : ” cmr ” ,” type ” : ” cmr−schema ” ,” calc name ” : ” newc ” ,” c a l c i n s t a n c e ” : ” ” ,” classname ” : ” NewCSchema” ,” v e r s i o n ” : ” newc −0.3 −20110523” ,”module ” : ” newc . newc ”} , ]r e t u r n i n f oFigure 2.31: information.py: declares module, class name and version of plug-ins.