<s> from __future__ import unicode_literals <EOL> """<STR_LIT>""" <EOL> import frappe , os , frappe . permissions <EOL> class PatchError ( Exception ) : pass <EOL> def run_all ( ) : <EOL> """<STR_LIT>""" <EOL> executed = [ p [ <NUM_LIT:0> ] for p in frappe . db . sql ( """<STR_LIT>""" ) ] <EOL> for patch in get_all_patches ( ) : <EOL> if patch and ( patch not in executed ) : <EOL> if not run_single ( patchmodule = patch ) : <EOL> log ( patch + '<STR_LIT>' ) <EOL> raise PatchError ( patch ) <EOL> def get_all_patches ( ) : <EOL> patches = [ ] <EOL> for app in frappe . get_installed_apps ( ) : <EOL> if app == "<STR_LIT>" : <EOL> continue <EOL> if app == "<STR_LIT>" : <EOL> app = "<STR_LIT>" <EOL> patches . extend ( frappe . get_file_items ( frappe . get_pymodule_path ( app , "<STR_LIT>" ) ) ) <EOL> return patches <EOL> def reload_doc ( args ) : <EOL> import frappe . modules <EOL> run_single ( method = frappe . modules . reload_doc , methodargs = args ) <EOL> def run_single ( patchmodule = None , method = None , methodargs = None , force = False ) : <EOL> from frappe import conf <EOL> conf . developer_mode = <NUM_LIT:0> <EOL> if force or method or not executed ( patchmodule ) : <EOL> return execute_patch ( patchmodule , method , methodargs ) <EOL> else : <EOL> return True <EOL> def execute_patch ( patchmodule , method = None , methodargs = None ) : <EOL> """<STR_LIT>""" <EOL> block_user ( True ) <EOL> frappe . db . begin ( ) <EOL> try : <EOL> log ( '<STR_LIT>' . format ( patch = patchmodule or str ( methodargs ) , <EOL> site = frappe . local . site , db = frappe . db . cur_db_name ) ) <EOL> if patchmodule : <EOL> if patchmodule . startswith ( "<STR_LIT>" ) : <EOL> exec patchmodule . split ( "<STR_LIT>" ) [ <NUM_LIT:1> ] in globals ( ) <EOL> else : <EOL> frappe . get_attr ( patchmodule . split ( ) [ <NUM_LIT:0> ] + "<STR_LIT>" ) ( ) <EOL> update_patch_log ( patchmodule ) <EOL> elif method : <EOL> method ( ** methodargs ) <EOL> except Exception : <EOL> frappe . db . rollback ( ) <EOL> raise <EOL> else : <EOL> frappe . db . commit ( ) <EOL> block_user ( False ) <EOL> log ( '<STR_LIT>' ) <EOL> return True <EOL> def update_patch_log ( patchmodule ) : <EOL> """<STR_LIT>""" <EOL> frappe . get_doc ( { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : patchmodule } ) . insert ( ) <EOL> def executed ( patchmodule ) : <EOL> """<STR_LIT>""" <EOL> done = frappe . db . get_value ( "<STR_LIT>" , { "<STR_LIT>" : patchmodule } ) <EOL> return done <EOL> def block_user ( block ) : <EOL> """<STR_LIT>""" <EOL> frappe . local . flags . in_patch = block <EOL> frappe . db . begin ( ) <EOL> msg = "<STR_LIT>" <EOL> frappe . db . set_global ( '<STR_LIT>' , block and '<STR_LIT>' or None ) <EOL> frappe . db . set_global ( '<STR_LIT>' , block and msg or None ) <EOL> frappe . db . commit ( ) <EOL> def check_session_stopped ( ) : <EOL> if frappe . db . get_global ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> frappe . msgprint ( frappe . db . get_global ( "<STR_LIT>" ) ) <EOL> raise frappe . SessionStopped ( '<STR_LIT>' ) <EOL> def log ( msg ) : <EOL> print msg </s>
