<s> from __future__ import unicode_literals <EOL> import frappe , os <EOL> from frappe . model . document import Document <EOL> class ModuleDef ( Document ) : <EOL> def on_update ( self ) : <EOL> """<STR_LIT>""" <EOL> if frappe . conf . get ( "<STR_LIT>" ) : <EOL> self . create_modules_folder ( ) <EOL> self . add_to_modules_txt ( ) <EOL> def create_modules_folder ( self ) : <EOL> """<STR_LIT>""" <EOL> module_path = frappe . get_app_path ( self . app_name , self . name ) <EOL> if not os . path . exists ( module_path ) : <EOL> os . mkdir ( module_path ) <EOL> with open ( os . path . join ( module_path , "<STR_LIT>" ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> def add_to_modules_txt ( self ) : <EOL> """<STR_LIT>""" <EOL> modules = None <EOL> if not frappe . local . module_app . get ( frappe . scrub ( self . name ) ) : <EOL> with open ( frappe . get_app_path ( self . app_name , "<STR_LIT>" ) , "<STR_LIT:r>" ) as f : <EOL> content = f . read ( ) <EOL> if not self . name in content . splitlines ( ) : <EOL> modules = filter ( None , content . splitlines ( ) ) <EOL> modules . append ( self . name ) <EOL> if modules : <EOL> with open ( frappe . get_app_path ( self . app_name , "<STR_LIT>" ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT:\n>" . join ( modules ) ) <EOL> frappe . clear_cache ( ) <EOL> frappe . setup_module_map ( ) </s>
