#NEWLINE# def execute_directives( self ) : #NEWLINE# #INDENT# global __KV_INCLUDES__ #NEWLINE# for ( ln , cmd ) in self . directives : #NEWLINE# #INDENT# cmd = cmd . strip ( ) #NEWLINE# if __debug__ : #NEWLINE# #INDENT# trace ( ( 'Parser: got directive <%s>' % cmd ) ) #NEWLINE# #UNINDENT# if ( cmd [ : 5 ] == 'kivy ' ) : #NEWLINE# #INDENT# version = cmd [ 5 : ] . strip ( ) #NEWLINE# if ( len ( version . split ( '.' ) ) == 2 ) : #NEWLINE# #INDENT# version += '.0' #NEWLINE# #UNINDENT# require ( version ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd [ : 4 ] == 'set ' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( name , value ) = cmd [ 4 : ] . strip ( ) . split ( ' ' , 1 ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# Logger . exception ( '' ) #NEWLINE# raise ParserException ( self , ln , 'Invalid directive syntax' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# value = eval ( value , global_idmap ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# Logger . exception ( '' ) #NEWLINE# raise ParserException ( self , ln , 'Invalid value' ) #NEWLINE# #UNINDENT# global_idmap [ name ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd [ : 8 ] == 'include ' ) : #NEWLINE# #INDENT# ref = cmd [ 8 : ] . strip ( ) #NEWLINE# force_load = False #NEWLINE# if ( ref [ : 6 ] == 'force ' ) : #NEWLINE# #INDENT# ref = ref [ 6 : ] . strip ( ) #NEWLINE# force_load = True #NEWLINE# #UNINDENT# if ( ref [ ( - 3 ) : ] != '.kv' ) : #NEWLINE# #INDENT# Logger . warn ( 'WARNING: {0} does not have a valid KivyLanguage extension (.kv)' . format ( ref ) ) #NEWLINE# break #NEWLINE# #UNINDENT# if ( ref in __KV_INCLUDES__ ) : #NEWLINE# #INDENT# if ( not os . path . isfile ( ( resource_find ( ref ) or ref ) ) ) : #NEWLINE# #INDENT# raise ParserException ( self , ln , 'Invalid or unknown file: {0}' . format ( ref ) ) #NEWLINE# #UNINDENT# if ( not force_load ) : #NEWLINE# #INDENT# Logger . warn ( 'WARNING: {0} has already been included!' . format ( ref ) ) #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# Logger . debug ( 'Reloading {0} because include was forced.' . format ( ref ) ) #NEWLINE# kivy . lang . builder . Builder . unload_file ( ref ) #NEWLINE# kivy . lang . builder . Builder . load_file ( ref ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# Logger . debug ( 'Including file: {0}' . format ( 0 ) ) #NEWLINE# __KV_INCLUDES__ . append ( ref ) #NEWLINE# kivy . lang . builder . Builder . load_file ( ref ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd [ : 7 ] == 'import ' ) : #NEWLINE# #INDENT# package = cmd [ 7 : ] . strip ( ) #NEWLINE# l = package . split ( ) #NEWLINE# if ( len ( l ) != 2 ) : #NEWLINE# #INDENT# raise ParserException ( self , ln , 'Invalid import syntax' ) #NEWLINE# #UNINDENT# ( alias , package ) = l #NEWLINE# try : #NEWLINE# #INDENT# if ( package not in sys . modules ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# mod = __import__ ( package ) #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# mod = __import__ ( '.' . join ( package . split ( '.' ) [ : ( - 1 ) ] ) ) #NEWLINE# #UNINDENT# for part in package . split ( '.' ) [ 1 : ] : #NEWLINE# #INDENT# mod = getattr ( mod , part ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# mod = sys . modules [ package ] #NEWLINE# #UNINDENT# global_idmap [ alias ] = mod #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# Logger . exception ( '' ) #NEWLINE# raise ParserException ( self , ln , ( 'Unable to import package %r' % package ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise ParserException ( self , ln , 'Unknown directive' )