<s> import sys <EOL> import json <EOL> import sublime <EOL> from . settings import preferences_filename , pc_settings_filename , load_list_setting <EOL> from . package_io import package_file_exists , read_package_file <EOL> from . import events <EOL> class PackageDisabler ( ) : <EOL> old_color_scheme_package = None <EOL> old_color_scheme = None <EOL> old_theme_package = None <EOL> old_theme = None <EOL> old_syntaxes = None <EOL> def get_version ( self , package ) : <EOL> """<STR_LIT>""" <EOL> metadata_json = read_package_file ( package , '<STR_LIT>' ) <EOL> if metadata_json : <EOL> metadata = json . loads ( metadata_json ) <EOL> return metadata . get ( '<STR_LIT:version>' , '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> def disable_packages ( self , packages , type = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( packages , list ) : <EOL> packages = [ packages ] <EOL> disabled = [ ] <EOL> settings = sublime . load_settings ( preferences_filename ( ) ) <EOL> ignored = load_list_setting ( settings , '<STR_LIT>' ) <EOL> pc_settings = sublime . load_settings ( pc_settings_filename ( ) ) <EOL> in_process = load_list_setting ( pc_settings , '<STR_LIT>' ) <EOL> self . old_syntaxes = { } <EOL> self . old_color_schemes = { } <EOL> for package in packages : <EOL> if not package in ignored : <EOL> in_process . append ( package ) <EOL> ignored . append ( package ) <EOL> disabled . append ( package ) <EOL> if type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> version = self . get_version ( package ) <EOL> tracker_type = '<STR_LIT>' if type == '<STR_LIT>' else type <EOL> events . add ( tracker_type , package , version ) <EOL> for window in sublime . windows ( ) : <EOL> for view in window . views ( ) : <EOL> view_settings = view . settings ( ) <EOL> syntax = view_settings . get ( '<STR_LIT>' ) <EOL> if syntax . find ( '<STR_LIT>' + package + '<STR_LIT:/>' ) != - <NUM_LIT:1> : <EOL> if package not in self . old_syntaxes : <EOL> self . old_syntaxes [ package ] = [ ] <EOL> self . old_syntaxes [ package ] . append ( [ view , syntax ] ) <EOL> view_settings . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> scheme = view_settings . get ( '<STR_LIT>' ) <EOL> if scheme . find ( '<STR_LIT>' + package + '<STR_LIT:/>' ) != - <NUM_LIT:1> : <EOL> if package not in self . old_color_schemes : <EOL> self . old_color_schemes [ package ] = [ ] <EOL> self . old_color_schemes [ package ] . append ( [ view , scheme ] ) <EOL> view_settings . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if settings . get ( '<STR_LIT>' ) . find ( '<STR_LIT>' + package + '<STR_LIT:/>' ) != - <NUM_LIT:1> : <EOL> self . old_color_scheme_package = package <EOL> self . old_color_scheme = settings . get ( '<STR_LIT>' ) <EOL> settings . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if package_file_exists ( package , settings . get ( '<STR_LIT>' ) ) : <EOL> self . old_theme_package = package <EOL> self . old_theme = settings . get ( '<STR_LIT>' ) <EOL> settings . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if type != '<STR_LIT>' : <EOL> pc_settings . set ( '<STR_LIT>' , in_process ) <EOL> sublime . save_settings ( pc_settings_filename ( ) ) <EOL> settings . set ( '<STR_LIT>' , ignored ) <EOL> sublime . save_settings ( preferences_filename ( ) ) <EOL> return disabled <EOL> def reenable_package ( self , package , type = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> settings = sublime . load_settings ( preferences_filename ( ) ) <EOL> ignored = load_list_setting ( settings , '<STR_LIT>' ) <EOL> if package in ignored : <EOL> if type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> version = self . get_version ( package ) <EOL> tracker_type = '<STR_LIT>' if type == '<STR_LIT>' else type <EOL> events . add ( tracker_type , package , version ) <EOL> events . clear ( tracker_type , package , future = True ) <EOL> if type == '<STR_LIT>' : <EOL> events . clear ( '<STR_LIT>' , package ) <EOL> elif type == '<STR_LIT>' : <EOL> events . clear ( '<STR_LIT>' , package ) <EOL> settings . set ( '<STR_LIT>' , <EOL> list ( set ( ignored ) - set ( [ package ] ) ) ) <EOL> sublime . save_settings ( preferences_filename ( ) ) <EOL> if type == '<STR_LIT>' and self . old_theme_package == package : <EOL> sublime . message_dialog ( u"<STR_LIT>" + <EOL> u"<STR_LIT>" + <EOL> u"<STR_LIT>" + <EOL> u"<STR_LIT>" ) <EOL> def delayed_settings_restore ( ) : <EOL> if type == '<STR_LIT>' and package in self . old_syntaxes : <EOL> for view_syntax in self . old_syntaxes [ package ] : <EOL> view , syntax = view_syntax <EOL> view . settings ( ) . set ( '<STR_LIT>' , syntax ) <EOL> if type == '<STR_LIT>' and package in self . old_color_schemes : <EOL> for view_scheme in self . old_color_schemes [ package ] : <EOL> view , scheme = view_scheme <EOL> view . settings ( ) . set ( '<STR_LIT>' , scheme ) <EOL> if type == '<STR_LIT>' and self . old_theme_package == package : <EOL> settings . set ( '<STR_LIT>' , self . old_theme ) <EOL> sublime . message_dialog ( u"<STR_LIT>" + <EOL> u"<STR_LIT>" + <EOL> u"<STR_LIT>" ) <EOL> if type == '<STR_LIT>' and self . old_color_scheme_package == package : <EOL> settings . set ( '<STR_LIT>' , self . old_color_scheme ) <EOL> sublime . save_settings ( preferences_filename ( ) ) <EOL> sublime . set_timeout ( delayed_settings_restore , <NUM_LIT:1000> ) <EOL> pc_settings = sublime . load_settings ( pc_settings_filename ( ) ) <EOL> in_process = load_list_setting ( pc_settings , '<STR_LIT>' ) <EOL> if package in in_process : <EOL> in_process . remove ( package ) <EOL> pc_settings . set ( '<STR_LIT>' , in_process ) <EOL> sublime . save_settings ( pc_settings_filename ( ) ) </s>
