#NEWLINE# def parse_file( self , pythonpath , debug = False ) : #NEWLINE# #INDENT# '\n        This parses the lines of a batchfile according to the following\n        rules:\n\n        Args:\n            pythonpath (str): The dot-python path to the file.\n            debug (bool, optional): Insert delete-commands for\n                deleting created objects.\n\n        Returns:\n            codeblocks (list): A list of all #CODE blocks.\n\n        Notes:\n            1. Lines starting with #HEADER starts a header block (ends other blocks)\n            2. Lines starting with #CODE begins a code block (ends other blocks)\n            3. #CODE headers may be of the following form:\n                                  #CODE (info) objname, objname2, ...\n            4. Lines starting with #INSERT are on form #INSERT filename.\n            5. All lines outside blocks are stripped.\n            6. All excess whitespace beginning/ending a block is stripped.\n\n        ' #NEWLINE# text = '' . join ( read_batchfile ( pythonpath , file_ending = '.py' ) ) #NEWLINE# def clean_block( text ) : #NEWLINE# #INDENT# text = RE_CLEANBLOCK . sub ( '' , text ) #NEWLINE# return '\n' . join ( [ line for line in text . split ( '\n' ) if line ] ) #NEWLINE# #UNINDENT# def replace_insert( match ) : #NEWLINE# #INDENT# 'Map replace entries' #NEWLINE# return '\\#\n' . join ( self . parse_file ( match . group ( 1 ) ) ) #NEWLINE# #UNINDENT# text = RE_INSERT . sub ( replace_insert , text ) #NEWLINE# blocks = RE_CODE_SPLIT . split ( text ) #NEWLINE# headers = [ ] #NEWLINE# codes = [ ] #NEWLINE# if blocks : #NEWLINE# #INDENT# if blocks [ 0 ] : #NEWLINE# #INDENT# code = clean_block ( blocks . pop ( 0 ) ) #NEWLINE# if code : #NEWLINE# #INDENT# codes . append ( ( code , '' ) ) #NEWLINE# #UNINDENT# #UNINDENT# iblock = 0 #NEWLINE# for block in blocks [ : : 2 ] : #NEWLINE# #INDENT# if block . startswith ( '#HEADER' ) : #NEWLINE# #INDENT# headers . append ( clean_block ( blocks [ ( iblock + 1 ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if block . startswith ( '#CODE' ) : #NEWLINE# #INDENT# match = re . search ( '\\(.*?\\)' , block ) #NEWLINE# info = ( match . group ( ) if pythonpath else '' ) #NEWLINE# objs = [ ] #NEWLINE# if debug : #NEWLINE# #INDENT# objs = block [ match . end ( ) : ] . split ( ',' ) #NEWLINE# objs = [ ( "# added by Evennia's debug mode\n%s.delete()" % obj . strip ( ) ) for obj in objs if obj ] #NEWLINE# #UNINDENT# code = '\n' . join ( ( [ clean_block ( blocks [ ( iblock + 1 ) ] ) ] + objs ) ) #NEWLINE# if code : #NEWLINE# #INDENT# codes . append ( ( code , info ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# iblock += 2 #NEWLINE# #UNINDENT# #UNINDENT# headers = '\n' . join ( headers ) #NEWLINE# if codes : #NEWLINE# #INDENT# codes = [ ( '%s\n%s\n%s' % ( ( '#CODE %s: ' % tup [ 1 ] ) , headers , tup [ 0 ] ) ) for tup in codes if tup [ 0 ] ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# codes = [ ( '#CODE: \n' + headers ) ] #NEWLINE# #UNINDENT# return codes