<s> '''<STR_LIT>''' <EOL> from treemodel import traverse_list , Visitor <EOL> from omnifocus import build_model , find_database <EOL> import os <EOL> import codecs <EOL> '''<STR_LIT>''' <EOL> class GenerateTagDBVisitor ( Visitor ) : <EOL> def begin_folder ( self , folder ) : <EOL> self . generate_entry ( '<STR_LIT>' , folder ) <EOL> def begin_project ( self , project ) : <EOL> self . generate_entry ( '<STR_LIT>' , project ) <EOL> def begin_context ( self , context ) : <EOL> self . generate_entry ( '<STR_LIT>' , context ) <EOL> def generate_entry ( self , link_type , item ) : <EOL> if '<STR_LIT>' in item . ofattribs : <EOL> ident = item . ofattribs [ '<STR_LIT>' ] <EOL> link = '<STR_LIT>' + link_type + '<STR_LIT:/>' + ident <EOL> base = item . name . replace ( '<STR_LIT:/>' , '<STR_LIT:_>' ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) . replace ( '<STR_LIT>' , '<STR_LIT:_>' ) <EOL> file_name = os . environ [ '<STR_LIT>' ] + '<STR_LIT>' + base + '<STR_LIT:U+0020>' + ident + '<STR_LIT>' <EOL> out = codecs . open ( file_name , '<STR_LIT:w>' , '<STR_LIT:utf-8>' ) <EOL> link = '<STR_LIT>' + link_type + '<STR_LIT:/>' + ident <EOL> print >> out , '<STR_LIT>' <EOL> print >> out , '<STR_LIT>' <EOL> print >> out , '<STR_LIT>' + link + '<STR_LIT>' <EOL> print >> out , '<STR_LIT>' <EOL> print >> out , '<STR_LIT>' <EOL> print >> out , '<STR_LIT>' + link + '<STR_LIT>' + self . escape ( item . name ) + '<STR_LIT>' <EOL> print >> out , '<STR_LIT>' <EOL> print >> out , '<STR_LIT>' <EOL> out . close ( ) <EOL> def escape ( self , val ) : <EOL> return val . replace ( '<STR_LIT:">' , '<STR_LIT>' ) . replace ( '<STR_LIT:&>' , '<STR_LIT>' ) . replace ( '<STR_LIT:<>' , '<STR_LIT>' ) . replace ( '<STR_LIT:>>' , '<STR_LIT>' ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> root_projects_and_folders , root_contexts = build_model ( find_database ( ) ) <EOL> traverse_list ( GenerateTagDBVisitor ( ) , root_projects_and_folders ) <EOL> traverse_list ( GenerateTagDBVisitor ( ) , root_contexts , project_mode = False ) </s>
