SLIDE 13 Plugin frameworks noufal Introduction
About me About this talk Plugin frameworks
Case #1 : Trac
Trac Component architecture Writing a plugin Example Pros/Cons
Case #2 : py.test
Metaprogramming Writing a plugin Example Pros/Cons
Case #3 : Emacs
Embedded scripting language Writing a plugin Example
Trac : Example plugin
1 # F o l l o w i n g i s the code i n the a p p l i c a t i o n 2 # The i n t e r f a c e and i t ’ s s p e c i f i c a t i o n 3 c l a s s ITodoObserver ( I n t e r f a c e ) : 4 def todo added (name , d e s c r i p t i o n ) : 5 ” C a l l e d when a to−do item i s added . ” 6 7 c l a s s TodoList ( Component ) : 8 # D e c l a r a t i o n
an e x t e n s i o n p o i n t 9
- b s e r v e r s = E x t e n s i o n P o i n t ( ITodoObserver )
10 11 def i n i t ( s e l f ) : 12 s e l f . todos = {} 13 14 def add ( s e l f , name , d e s c r i p t i o n ) : 15 a s s e r t not name i n s e l f . todos , ’To −do a l r e a d y i n l i s t ’ 16 s e l f . todos [ name ] = d e s c r i p t i o n 17 f o r
i n s e l f . o b s e r v e r s : # Using the e x t e n s i o n p o i n t 18
- b s e r v e r . todo added (name ,
d e s c r i p t i o n ) 19 20 21 # A p l u g i n that p r i n t s
d e t a i l s when something i s added 22 c l a s s TodoPrinter ( Component ) : 23 # S t a t i n g which i n t e r f a c e i s implemented 24 implements ( ITodoObserver ) 25 26 def todo added ( s e l f , name , d e s c r i p t i o n ) : 27 p r i n y t ’TODO: ’ , name 28 p r i n t ’ ’ , d e s c r i p t i o n