<s> from . file import File <EOL> from sublime_plugin import EventListener , WindowCommand , TextCommand <EOL> from sublime import load_settings , save_settings , load_resource , packages_path <EOL> def clear_cache ( force = False ) : <EOL> """<STR_LIT>""" <EOL> from os . path import getsize , join , isfile , exists <EOL> from os import makedirs , listdir <EOL> from sublime import cache_path <EOL> from shutil import rmtree <EOL> icon_path = join ( cache_path ( ) , "<STR_LIT>" ) <EOL> limit = <NUM_LIT> <EOL> if exists ( icon_path ) : <EOL> size = sum ( getsize ( join ( icon_path , f ) ) for f in listdir ( icon_path ) if isfile ( join ( icon_path , f ) ) ) <EOL> if force or ( size > limit ) : rmtree ( icon_path ) <EOL> if not exists ( icon_path ) : makedirs ( icon_path ) <EOL> def plugin_loaded ( ) : <EOL> clear_cache ( ) <EOL> fix_schemes_in_windows ( ) <EOL> class GutterColorClearCacheCommand ( WindowCommand ) : <EOL> def run ( self ) : <EOL> clear_cache ( True ) <EOL> class GutterColorEventListener ( EventListener ) : <EOL> """<STR_LIT>""" <EOL> def on_activated_async ( self , view ) : <EOL> """<STR_LIT>""" <EOL> if syntax ( view ) in settings ( ) . get ( '<STR_LIT>' ) : <EOL> fix_scheme_in_view ( view ) <EOL> File ( view ) <EOL> def on_modified ( self , view ) : <EOL> """<STR_LIT>""" <EOL> if syntax ( view ) in settings ( ) . get ( '<STR_LIT>' ) : <EOL> File ( view , '<STR_LIT>' ) <EOL> def on_pre_save_async ( self , view ) : <EOL> """<STR_LIT>""" <EOL> if syntax ( view ) in settings ( ) . get ( '<STR_LIT>' ) : <EOL> File ( view , '<STR_LIT>' ) <EOL> def settings ( ) : <EOL> """<STR_LIT>""" <EOL> return load_settings ( "<STR_LIT>" ) <EOL> def syntax ( view ) : <EOL> """<STR_LIT>""" <EOL> syntax = view . settings ( ) . get ( '<STR_LIT>' ) <EOL> return syntax . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] . lower ( ) if syntax is not None else "<STR_LIT>" <EOL> def current_directory ( full = False ) : <EOL> """<STR_LIT>""" <EOL> from os . path import dirname , realpath , split <EOL> if full : <EOL> return dirname ( realpath ( __file__ ) ) <EOL> else : <EOL> return split ( dirname ( realpath ( __file__ ) ) ) [ <NUM_LIT:1> ] <EOL> def fix_schemes_in_windows ( ) : <EOL> """<STR_LIT>""" <EOL> from sublime import windows <EOL> for window in windows ( ) : <EOL> for view in window . views ( ) : <EOL> if syntax ( view ) in settings ( ) . get ( '<STR_LIT>' ) : <EOL> fix_scheme_in_view ( view ) <EOL> def fix_scheme_in_view ( view , regenerate = False , ignore_flags = False ) : <EOL> """<STR_LIT>""" <EOL> fix_flag = settings ( ) . get ( "<STR_LIT>" , False ) <EOL> ( fix_syntax , fix_global , fix_custom ) = ( False , False , False ) <EOL> custom_files = [ ] <EOL> if fix_flag == True : <EOL> ( fix_syntax , fix_global ) = ( True , True ) <EOL> elif isinstance ( fix_flag , list ) : <EOL> for label in fix_flag : <EOL> if label in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> fix_syntax = True <EOL> if label in ( "<STR_LIT:user>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> fix_global = True <EOL> if "<STR_LIT>" in label : <EOL> fix_custom = True <EOL> custom_files . append ( label ) <EOL> elif ignore_flags : <EOL> pass <EOL> else : <EOL> return <EOL> current_scheme = view . settings ( ) . get ( "<STR_LIT>" ) <EOL> modified_marker = "<STR_LIT>" <EOL> if modified_marker in current_scheme : <EOL> if regenerate : <EOL> new_scheme = current_scheme <EOL> else : <EOL> return <EOL> else : <EOL> new_scheme = "<STR_LIT>" + current_directory ( ) + "<STR_LIT:/>" + current_scheme . split ( "<STR_LIT:/>" ) [ - <NUM_LIT:1> ] . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] + modified_marker + current_scheme . split ( "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] <EOL> if fix_custom : <EOL> for custom_filename in custom_files : <EOL> if fix_scheme_in_settings ( custom_filename , current_scheme , new_scheme ) : <EOL> return <EOL> if fix_syntax or ignore_flags : <EOL> syntax_filename = view . settings ( ) . get ( '<STR_LIT>' ) . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> if fix_scheme_in_settings ( syntax_filename , current_scheme , new_scheme ) : <EOL> return <EOL> if fix_global or ignore_flags : <EOL> if fix_scheme_in_settings ( "<STR_LIT>" , current_scheme , new_scheme ) : <EOL> return <EOL> print ( "<STR_LIT>" + current_scheme + "<STR_LIT>" ) <EOL> def fix_scheme_in_settings ( settings_file , current_scheme , new_scheme , regenerate = False ) : <EOL> """<STR_LIT>""" <EOL> from os . path import join , normpath , isfile <EOL> settings = load_settings ( settings_file ) <EOL> settings_scheme = settings . get ( "<STR_LIT>" ) <EOL> if current_scheme == settings_scheme : <EOL> new_scheme_path = join ( packages_path ( ) , normpath ( new_scheme [ len ( "<STR_LIT>" ) : ] ) ) <EOL> if isfile ( new_scheme_path ) and not regenerate : <EOL> settings . set ( "<STR_LIT>" , new_scheme ) <EOL> else : <EOL> generate_scheme_fix ( current_scheme , new_scheme_path ) <EOL> settings . set ( "<STR_LIT>" , new_scheme ) <EOL> save_settings ( settings_file ) <EOL> return True <EOL> return False <EOL> def generate_scheme_fix ( old_scheme , new_scheme_path ) : <EOL> """<STR_LIT>""" <EOL> from os . path import join <EOL> from re import sub <EOL> UUID_REGEX = '<STR_LIT>' <EOL> with open ( join ( packages_path ( ) , current_directory ( ) , '<STR_LIT>' ) ) as f : <EOL> xml = f . read ( ) <EOL> scheme_data = load_resource ( old_scheme ) <EOL> insertion_point = scheme_data . rfind ( "<STR_LIT>" ) <EOL> new_scheme_data = scheme_data [ : insertion_point ] + xml + scheme_data [ insertion_point : ] <EOL> def uuid_gen ( args ) : <EOL> from uuid import uuid4 <EOL> return str ( uuid4 ( ) ) <EOL> new_scheme_data = sub ( UUID_REGEX , uuid_gen , new_scheme_data ) <EOL> with open ( new_scheme_path , "<STR_LIT:wb>" ) as f : <EOL> f . write ( new_scheme_data . encode ( "<STR_LIT:utf-8>" ) ) <EOL> class GutterColorFixCurrentScheme ( TextCommand ) : <EOL> def run ( self , args ) : <EOL> fix_scheme_in_view ( self . view , True , True ) </s>
