def reenable_package(self, package, type='upgrade'): """ Re-enables a package after it has been installed or upgraded :param package: The string package name :param type: The type of operation that caused the package to be re-enabled: - "upgrade" - "remove" - "install" - "enable" - "loader" """ settings = sublime.load_settings(preferences_filename()) ignored = load_list_setting(settings, 'ignored_packages') if package in ignored: if type in ['install', 'upgrade']: version = self.get_version(package) tracker_type = 'post_upgrade' if type == 'upgrade' else type events.add(tracker_type, package, version) events.clear(tracker_type, package, future=True) if type == 'upgrade': events.clear('pre_upgrade', package) elif type == 'remove': events.clear('remove', package) settings.set('ignored_packages', list(set(ignored) - set([package]))) sublime.save_settings(preferences_filename()) if type == 'remove' and self.old_theme_package == package: sublime.message_dialog(text.format( u''' Package Control Your active theme was just removed and the Default theme was enabled in its place. You may see some graphical corruption until you restart Sublime Text. ''' )) # By delaying the restore, we give Sublime Text some time to # re-enable the package, making errors less likely def delayed_settings_restore(): if type == 'upgrade' and package in self.old_syntaxes: for view_syntax in self.old_syntaxes[package]: view, syntax = view_syntax view.settings().set('syntax', syntax) if type == 'upgrade' and package in self.old_color_schemes: for view_scheme in self.old_color_schemes[package]: view, scheme = view_scheme view.settings().set('color_scheme', scheme) if type == 'upgrade' and self.old_theme_package == package: settings.set('theme', self.old_theme) sublime.message_dialog(text.format( u''' Package Control Your active theme was just upgraded. You may see some graphical corruption until you restart Sublime Text. ''' )) if type == 'upgrade' and self.old_color_scheme_package == package: settings.set('color_scheme', self.old_color_scheme) sublime.save_settings(preferences_filename()) sublime.set_timeout(delayed_settings_restore, 1000) pc_settings = sublime.load_settings(pc_settings_filename()) in_process = load_list_setting(pc_settings, 'in_process_packages') if package in in_process: in_process.remove(package) pc_settings.set('in_process_packages', in_process) sublime.save_settings(pc_settings_filename())
def disable_packages(self, packages, type='upgrade'): """ Disables one or more packages before installing or upgrading to prevent errors where Sublime Text tries to read files that no longer exist, or read a half-written file. :param packages: The string package name, or an array of strings :param type: The type of operation that caused the package to be disabled: - "upgrade" - "remove" - "install" - "disable" - "loader" """ if not isinstance(packages, list): packages = [packages] disabled = [] settings = sublime.load_settings(preferences_filename()) ignored = load_list_setting(settings, 'ignored_packages') pc_settings = sublime.load_settings(pc_settings_filename()) in_process = load_list_setting(pc_settings, 'in_process_packages') self.old_syntaxes = {} self.old_color_schemes = {} for package in packages: if package not in ignored: in_process.append(package) ignored.append(package) disabled.append(package) if type in ['upgrade', 'remove']: version = self.get_version(package) tracker_type = 'pre_upgrade' if type == 'upgrade' else type events.add(tracker_type, package, version) for window in sublime.windows(): for view in window.views(): view_settings = view.settings() syntax = view_settings.get('syntax') if syntax.find('Packages/' + package + '/') != -1: if package not in self.old_syntaxes: self.old_syntaxes[package] = [] self.old_syntaxes[package].append([view, syntax]) view_settings.set('syntax', 'Packages/Text/Plain text.tmLanguage') scheme = view_settings.get('color_scheme') if scheme.find('Packages/' + package + '/') != -1: if package not in self.old_color_schemes: self.old_color_schemes[package] = [] self.old_color_schemes[package].append([view, scheme]) view_settings.set('color_scheme', 'Packages/Color Scheme - Default/Monokai.tmTheme') # Change the color scheme before disabling the package containing it if settings.get('color_scheme').find('Packages/' + package + '/') != -1: self.old_color_scheme_package = package self.old_color_scheme = settings.get('color_scheme') settings.set('color_scheme', 'Packages/Color Scheme - Default/Monokai.tmTheme') # Change the theme before disabling the package containing it if package_file_exists(package, settings.get('theme')): self.old_theme_package = package self.old_theme = settings.get('theme') settings.set('theme', 'Default.sublime-theme') # We don't mark a package as in-process when disabling it, otherwise # it automatically gets re-enabled the next time Sublime Text starts if type != 'disable': pc_settings.set('in_process_packages', in_process) sublime.save_settings(pc_settings_filename()) settings.set('ignored_packages', ignored) sublime.save_settings(preferences_filename()) return disabled
def reenable_package(self, package, type="upgrade"): """ Re-enables a package after it has been installed or upgraded :param package: The string package name :param type: The type of operation that caused the package to be re-enabled: - "upgrade" - "remove" - "install" - "enable" - "loader" """ global events if events is None: from package_control import events settings = sublime.load_settings(preferences_filename()) ignored = load_list_setting(settings, "ignored_packages") if package in ignored: if type in ["install", "upgrade"]: version = self.get_version(package) tracker_type = "post_upgrade" if type == "upgrade" else type events.add(tracker_type, package, version) events.clear(tracker_type, package, future=True) if type == "upgrade": events.clear("pre_upgrade", package) elif type == "remove": events.clear("remove", package) ignored = list(set(ignored) - set([package])) save_list_setting(settings, preferences_filename(), "ignored_packages", ignored) corruption_notice = u" You may see some graphical corruption until you restart Sublime Text." if type == "remove" and PackageDisabler.old_theme_package == package: message = text.format( u""" Package Control The package containing your active theme was just removed and the Default theme was enabled in its place. """ ) if int(sublime.version()) < 3106: message += corruption_notice sublime.message_dialog(message) # By delaying the restore, we give Sublime Text some time to # re-enable the package, making errors less likely def delayed_settings_restore(): syntax_errors = set() color_scheme_errors = set() if type == "upgrade" and package in PackageDisabler.old_syntaxes: for view_syntax in PackageDisabler.old_syntaxes[package]: view, syntax = view_syntax if resource_exists(syntax): view.settings().set("syntax", syntax) elif syntax not in syntax_errors: console_write(u'The syntax "%s" no longer exists' % syntax) syntax_errors.add(syntax) if type == "upgrade" and PackageDisabler.old_color_scheme_package == package: if resource_exists(PackageDisabler.old_color_scheme): settings.set("color_scheme", PackageDisabler.old_color_scheme) else: color_scheme_errors.add(PackageDisabler.old_color_scheme) sublime.error_message( text.format( u""" Package Control The package containing your active color scheme was just upgraded, however the .tmTheme file no longer exists. Sublime Text has been configured use the default color scheme instead. """ ) ) if type == "upgrade" and package in PackageDisabler.old_color_schemes: for view_scheme in PackageDisabler.old_color_schemes[package]: view, scheme = view_scheme if resource_exists(scheme): view.settings().set("color_scheme", scheme) elif scheme not in color_scheme_errors: console_write(u'The color scheme "%s" no longer exists' % scheme) color_scheme_errors.add(scheme) if type == "upgrade" and PackageDisabler.old_theme_package == package: if package_file_exists(package, PackageDisabler.old_theme): settings.set("theme", PackageDisabler.old_theme) message = text.format( u""" Package Control The package containing your active theme was just upgraded. """ ) if int(sublime.version()) < 3106: message += corruption_notice sublime.message_dialog(message) else: sublime.error_message( text.format( u""" Package Control The package containing your active theme was just upgraded, however the .sublime-theme file no longer exists. Sublime Text has been configured use the default theme instead. """ ) ) sublime.save_settings(preferences_filename()) sublime.set_timeout(delayed_settings_restore, 1000) pc_settings = sublime.load_settings(pc_settings_filename()) in_process = load_list_setting(pc_settings, "in_process_packages") if package in in_process: in_process.remove(package) save_list_setting(pc_settings, pc_settings_filename(), "in_process_packages", in_process)
def disable_packages(self, packages, type="upgrade"): """ Disables one or more packages before installing or upgrading to prevent errors where Sublime Text tries to read files that no longer exist, or read a half-written file. :param packages: The string package name, or an array of strings :param type: The type of operation that caused the package to be disabled: - "upgrade" - "remove" - "install" - "disable" - "loader" :return: A list of package names that were disabled """ global events if events is None: from package_control import events if not isinstance(packages, list): packages = [packages] disabled = [] settings = sublime.load_settings(preferences_filename()) ignored = load_list_setting(settings, "ignored_packages") pc_settings = sublime.load_settings(pc_settings_filename()) in_process = load_list_setting(pc_settings, "in_process_packages") PackageDisabler.old_color_scheme_package = None PackageDisabler.old_color_scheme = None PackageDisabler.old_theme_package = None PackageDisabler.old_theme = None PackageDisabler.old_syntaxes = {} PackageDisabler.old_color_schemes = {} for package in packages: if package not in ignored: in_process.append(package) ignored.append(package) disabled.append(package) if type in ["upgrade", "remove"]: version = self.get_version(package) tracker_type = "pre_upgrade" if type == "upgrade" else type events.add(tracker_type, package, version) global_color_scheme = settings.get("color_scheme") if global_color_scheme.find("Packages/" + package + "/") != -1: PackageDisabler.old_color_scheme_package = package PackageDisabler.old_color_scheme = global_color_scheme settings.set("color_scheme", "Packages/Color Scheme - Default/Monokai.tmTheme") for window in sublime.windows(): for view in window.views(): view_settings = view.settings() syntax = view_settings.get("syntax") if syntax.find("Packages/" + package + "/") != -1: if package not in PackageDisabler.old_syntaxes: PackageDisabler.old_syntaxes[package] = [] PackageDisabler.old_syntaxes[package].append([view, syntax]) view_settings.set("syntax", "Packages/Text/Plain text.tmLanguage") # Handle view-specific color_scheme settings not already taken care # of by resetting the global color_scheme above scheme = view_settings.get("color_scheme") if scheme.find("Packages/" + package + "/") != -1: if package not in PackageDisabler.old_color_schemes: PackageDisabler.old_color_schemes[package] = [] PackageDisabler.old_color_schemes[package].append([view, scheme]) view_settings.set("color_scheme", "Packages/Color Scheme - Default/Monokai.tmTheme") # Change the theme before disabling the package containing it if package_file_exists(package, settings.get("theme")): PackageDisabler.old_theme_package = package PackageDisabler.old_theme = settings.get("theme") settings.set("theme", "Default.sublime-theme") # We don't mark a package as in-process when disabling it, otherwise # it automatically gets re-enabled the next time Sublime Text starts if type != "disable": save_list_setting(pc_settings, pc_settings_filename(), "in_process_packages", in_process) save_list_setting(settings, preferences_filename(), "ignored_packages", ignored) return disabled
def disable_packages(self, packages, type='upgrade'): """ Disables one or more packages before installing or upgrading to prevent errors where Sublime Text tries to read files that no longer exist, or read a half-written file. :param packages: The string package name, or an array of strings :param type: The type of operation that caused the package to be disabled: - "upgrade" - "remove" - "install" - "disable" - "loader" :return: A list of package names that were disabled """ global events if events is None: from package_control import events if not isinstance(packages, list): packages = [packages] disabled = [] settings = sublime.load_settings(preferences_filename()) ignored = load_list_setting(settings, 'ignored_packages') pc_settings = sublime.load_settings(pc_settings_filename()) in_process = load_list_setting(pc_settings, 'in_process_packages') PackageDisabler.old_color_scheme_package = None PackageDisabler.old_color_scheme = None PackageDisabler.old_theme_package = None PackageDisabler.old_theme = None PackageDisabler.old_syntaxes = {} PackageDisabler.old_color_schemes = {} for package in packages: if package not in ignored: in_process.append(package) ignored.append(package) disabled.append(package) if type in ['upgrade', 'remove']: version = self.get_version(package) tracker_type = 'pre_upgrade' if type == 'upgrade' else type events.add(tracker_type, package, version) global_color_scheme = settings.get('color_scheme') if global_color_scheme is not None and global_color_scheme.find( 'Packages/' + package + '/') != -1: PackageDisabler.old_color_scheme_package = package PackageDisabler.old_color_scheme = global_color_scheme settings.set( 'color_scheme', 'Packages/Color Scheme - Default/Monokai.tmTheme') for window in sublime.windows(): for view in window.views(): view_settings = view.settings() syntax = view_settings.get('syntax') if syntax is not None and syntax.find('Packages/' + package + '/') != -1: if package not in PackageDisabler.old_syntaxes: PackageDisabler.old_syntaxes[package] = [] PackageDisabler.old_syntaxes[package].append( [view, syntax]) view_settings.set( 'syntax', 'Packages/Text/Plain text.tmLanguage') # Handle view-specific color_scheme settings not already taken care # of by resetting the global color_scheme above scheme = view_settings.get('color_scheme') if scheme is not None and scheme != global_color_scheme \ and scheme.find('Packages/' + package + '/') != -1: if package not in PackageDisabler.old_color_schemes: PackageDisabler.old_color_schemes[package] = [] PackageDisabler.old_color_schemes[package].append( [view, scheme]) view_settings.set( 'color_scheme', 'Packages/Color Scheme - Default/Monokai.tmTheme') # Change the theme before disabling the package containing it if package_file_exists(package, settings.get('theme')): PackageDisabler.old_theme_package = package PackageDisabler.old_theme = settings.get('theme') settings.set('theme', 'Default.sublime-theme') # We don't mark a package as in-process when disabling it, otherwise # it automatically gets re-enabled the next time Sublime Text starts if type != 'disable': save_list_setting(pc_settings, pc_settings_filename(), 'in_process_packages', in_process) save_list_setting(settings, preferences_filename(), 'ignored_packages', ignored) return disabled
def reenable_package(self, package, type='upgrade'): """ Re-enables a package after it has been installed or upgraded :param package: The string package name :param type: The type of operation that caused the package to be re-enabled: - "upgrade" - "remove" - "install" - "enable" - "loader" """ global events if events is None: from package_control import events settings = sublime.load_settings(preferences_filename()) ignored = load_list_setting(settings, 'ignored_packages') if package in ignored: if type in ['install', 'upgrade']: version = self.get_version(package) tracker_type = 'post_upgrade' if type == 'upgrade' else type events.add(tracker_type, package, version) events.clear(tracker_type, package, future=True) if type == 'upgrade': events.clear('pre_upgrade', package) elif type == 'remove': events.clear('remove', package) ignored = list(set(ignored) - set([package])) save_list_setting(settings, preferences_filename(), 'ignored_packages', ignored) corruption_notice = u' You may see some graphical corruption until you restart Sublime Text.' if type == 'remove' and PackageDisabler.old_theme_package == package: message = text.format(u''' Package Control The package containing your active theme was just removed and the Default theme was enabled in its place. ''') if int(sublime.version()) < 3106: message += corruption_notice sublime.message_dialog(message) # By delaying the restore, we give Sublime Text some time to # re-enable the package, making errors less likely def delayed_settings_restore(): syntax_errors = set() color_scheme_errors = set() if PackageDisabler.old_syntaxes is None: PackageDisabler.old_syntaxes = {} if PackageDisabler.old_color_schemes is None: PackageDisabler.old_color_schemes = {} if type == 'upgrade' and package in PackageDisabler.old_syntaxes: for view_syntax in PackageDisabler.old_syntaxes[package]: view, syntax = view_syntax if resource_exists(syntax): view.settings().set('syntax', syntax) elif syntax not in syntax_errors: console_write(u'The syntax "%s" no longer exists' % syntax) syntax_errors.add(syntax) if type == 'upgrade' and PackageDisabler.old_color_scheme_package == package: if resource_exists(PackageDisabler.old_color_scheme): settings.set('color_scheme', PackageDisabler.old_color_scheme) else: color_scheme_errors.add( PackageDisabler.old_color_scheme) sublime.error_message( text.format(u''' Package Control The package containing your active color scheme was just upgraded, however the .tmTheme file no longer exists. Sublime Text has been configured use the default color scheme instead. ''')) if type == 'upgrade' and package in PackageDisabler.old_color_schemes: for view_scheme in PackageDisabler.old_color_schemes[ package]: view, scheme = view_scheme if resource_exists(scheme): view.settings().set('color_scheme', scheme) elif scheme not in color_scheme_errors: console_write( u'The color scheme "%s" no longer exists' % scheme) color_scheme_errors.add(scheme) if type == 'upgrade' and PackageDisabler.old_theme_package == package: if package_file_exists(package, PackageDisabler.old_theme): settings.set('theme', PackageDisabler.old_theme) message = text.format(u''' Package Control The package containing your active theme was just upgraded. ''') if int(sublime.version()) < 3106: message += corruption_notice sublime.message_dialog(message) else: sublime.error_message( text.format(u''' Package Control The package containing your active theme was just upgraded, however the .sublime-theme file no longer exists. Sublime Text has been configured use the default theme instead. ''')) sublime.save_settings(preferences_filename()) sublime.set_timeout(delayed_settings_restore, 1000) pc_settings = sublime.load_settings(pc_settings_filename()) in_process = load_list_setting(pc_settings, 'in_process_packages') if package in in_process: in_process.remove(package) save_list_setting(pc_settings, pc_settings_filename(), 'in_process_packages', in_process)
def reenable_package(self, package, type='upgrade'): """ Re-enables a package after it has been installed or upgraded :param package: The string package name :param type: The type of operation that caused the package to be re-enabled: - "upgrade" - "remove" - "install" - "enable" - "loader" """ settings = sublime.load_settings(preferences_filename()) ignored = load_list_setting(settings, 'ignored_packages') if package in ignored: if type in ['install', 'upgrade']: version = self.get_version(package) tracker_type = 'post_upgrade' if type == 'upgrade' else type events.add(tracker_type, package, version) events.clear(tracker_type, package, future=True) if type == 'upgrade': events.clear('pre_upgrade', package) elif type == 'remove': events.clear('remove', package) settings.set('ignored_packages', list(set(ignored) - set([package]))) sublime.save_settings(preferences_filename()) if type == 'remove' and self.old_theme_package == package: sublime.message_dialog( text.format(u''' Package Control Your active theme was just removed and the Default theme was enabled in its place. You may see some graphical corruption until you restart Sublime Text. ''')) # By delaying the restore, we give Sublime Text some time to # re-enable the package, making errors less likely def delayed_settings_restore(): if type == 'upgrade' and package in self.old_syntaxes: for view_syntax in self.old_syntaxes[package]: view, syntax = view_syntax view.settings().set('syntax', syntax) if type == 'upgrade' and package in self.old_color_schemes: for view_scheme in self.old_color_schemes[package]: view, scheme = view_scheme view.settings().set('color_scheme', scheme) if type == 'upgrade' and self.old_theme_package == package: settings.set('theme', self.old_theme) sublime.message_dialog( text.format(u''' Package Control Your active theme was just upgraded. You may see some graphical corruption until you restart Sublime Text. ''')) if type == 'upgrade' and self.old_color_scheme_package == package: settings.set('color_scheme', self.old_color_scheme) sublime.save_settings(preferences_filename()) sublime.set_timeout(delayed_settings_restore, 1000) pc_settings = sublime.load_settings(pc_settings_filename()) in_process = load_list_setting(pc_settings, 'in_process_packages') if package in in_process: in_process.remove(package) pc_settings.set('in_process_packages', in_process) sublime.save_settings(pc_settings_filename())
def disable_packages(self, packages, operation_type='upgrade'): """ Disables one or more packages before installing or upgrading to prevent errors where Sublime Text tries to read files that no longer exist, or read a half-written file. :param packages: The string package name, or an array of strings :param operation_type: The type of operation that caused the package to be disabled: - "upgrade" - "remove" - "install" - "disable" - "loader" :return: A list of package names that were disabled """ if self.debug: console_write(u'Calling disable_packages() with: %s, type: %s', (packages, operation_type)) _operation_type = (lambda package_name: operation_type) if not hasattr( operation_type, "__call__") else operation_type if not packages: console_write(u'No packages to process by reenable_package!') return [] if not isinstance(threading.current_thread(), threading._MainThread): raise RuntimeError( 'disable_packages called on a background thread') global events try: from PackagesManager.package_control import events except (ImportError): events = None console_write( u'Warning: Could not run packages events, if any event was scheduled!' ) if not isinstance(packages, list): packages = [packages] in_process = [] settings = sublime.load_settings(preferences_filename()) PackageDisabler.old_color_scheme_package = None PackageDisabler.old_color_scheme = None PackageDisabler.old_theme_package = None PackageDisabler.old_theme = None for package in packages: operation = _operation_type(package) if events and operation in ['upgrade', 'remove']: version = self.get_version(package) tracker_type = 'pre_upgrade' if operation == 'upgrade' else operation events.add(tracker_type, package, version) global_color_scheme = settings.get('color_scheme') if global_color_scheme is not None and global_color_scheme.find( 'Packages/' + package + '/') != -1: PackageDisabler.old_color_scheme_package = package PackageDisabler.old_color_scheme = global_color_scheme settings.set( 'color_scheme', 'Packages/Color Scheme - Default/Monokai.tmTheme') for window in sublime.windows(): for view in window.views(): view_settings = view.settings() syntax = view_settings.get('syntax') if syntax is not None and syntax.find('Packages/' + package + '/') != -1: if package not in PackageDisabler.old_syntaxes: PackageDisabler.old_syntaxes[package] = [] PackageDisabler.old_syntaxes[package].append( [view, syntax]) view_settings.set( 'syntax', 'Packages/Text/Plain text.tmLanguage') # Handle view-specific color_scheme settings not already taken care # of by resetting the global color_scheme above scheme = view_settings.get('color_scheme') if scheme is not None and scheme != global_color_scheme \ and scheme.find('Packages/' + package + '/') != -1: if package not in PackageDisabler.old_color_schemes: PackageDisabler.old_color_schemes[package] = [] PackageDisabler.old_color_schemes[package].append( [view, scheme]) view_settings.set( 'color_scheme', 'Packages/Color Scheme - Default/Monokai.tmTheme') # Change the theme before disabling the package containing it if package_file_exists(package, settings.get('theme')): PackageDisabler.old_theme_package = package PackageDisabler.old_theme = settings.get('theme') settings.set('theme', 'Default.sublime-theme') # We don't mark a package as in-process when disabling it, otherwise # it automatically gets re-enabled the next time Sublime Text starts if operation != 'disable': in_process.append(package) # Force Sublime Text to understand the package is to be ignored self._force_setting(self._force_add, 'in_process_packages', in_process, g_settings.packagesmanager_setting_path()) disabled_packages = [] to_disable = list(packages) while len(to_disable) > 0: MAXIMUM_TO_REENABLE = 10 effectively_added = self._force_setting( self._force_add, 'ignored_packages', to_disable[:MAXIMUM_TO_REENABLE]) disabled_packages.extend(effectively_added) to_disable = to_disable[MAXIMUM_TO_REENABLE:] return disabled_packages
def reenable_package(self, packages, operation_type='upgrade'): """ Re-enables a package(s) after it has been installed or upgraded :param packages: The string packages name or a list of packages name :param operation_type: The type of operation that caused the packages to be re-enabled: - "upgrade" - "remove" - "install" - "enable" - "loader" """ if self.debug: console_write(u'Calling reenable_package() with: %s, type: %s', (packages, operation_type)) if isinstance(packages, str): packages = [packages] _operation_type = (lambda package_name: operation_type) if not hasattr( operation_type, "__call__") else operation_type if not packages: console_write(u'No packages to process by reenable_package!') return if not isinstance(threading.current_thread(), threading._MainThread): raise RuntimeError( 'reenable_package called on a background thread') global events try: from PackagesManager.package_control import events except (ImportError): events = None console_write( u'Warning: Could not run packages events, if any event was scheduled!' ) settings = sublime.load_settings(preferences_filename()) ignored = load_list_setting(settings, 'ignored_packages') if events: for package in packages: operation = _operation_type(package) if package in ignored: if operation in ['install', 'upgrade']: version = self.get_version(package) tracker_type = 'post_upgrade' if operation == 'upgrade' else operation events.add(tracker_type, package, version) events.clear(tracker_type, package, future=True) if operation == 'upgrade': events.clear('pre_upgrade', package) elif operation == 'remove': events.clear('remove', package) # Force Sublime Text to understand the package is to be unignored to_enable = list(packages) while len(to_enable) > 0: MAXIMUM_TO_REENABLE = 10 self._force_setting(self._force_remove, 'ignored_packages', to_enable[:MAXIMUM_TO_REENABLE]) to_enable = to_enable[MAXIMUM_TO_REENABLE:] for package in packages: operation = _operation_type(package) if self.debug: console_write(u'operation: %s, _operation_type: %s', (operation, _operation_type)) if package in ignored: corruption_notice = u' You may see some graphical corruption until you restart Sublime Text.' if operation == 'remove' and PackageDisabler.old_theme_package == package: message = text.format(u''' PackagesManager The package containing your active theme was just removed and the Default theme was enabled in its place. ''') if int(sublime.version()) < 3106: message += corruption_notice sublime.message_dialog(message) # By delaying the restore, we give Sublime Text some time to # re-enable the package, making errors less likely def delayed_settings_restore(): syntax_errors = set() color_scheme_errors = set() if PackageDisabler.old_syntaxes is None: PackageDisabler.old_syntaxes = {} if PackageDisabler.old_color_schemes is None: PackageDisabler.old_color_schemes = {} if operation == 'upgrade' and package in PackageDisabler.old_syntaxes: for view_syntax in PackageDisabler.old_syntaxes[ package]: view, syntax = view_syntax if resource_exists(syntax): view.settings().set('syntax', syntax) elif syntax not in syntax_errors: console_write( u'The syntax "%s" no longer exists' % syntax) syntax_errors.add(syntax) if self.debug: console_write( "PackageDisabler.old_color_scheme_package: %s, \n" "PackageDisabler.old_theme_package: %s, \n" "PackageDisabler.old_color_schemes: %s, \n" "package: %s", (PackageDisabler.old_color_scheme_package, PackageDisabler.old_theme_package, PackageDisabler.old_color_schemes, package)) if operation == 'upgrade' and PackageDisabler.old_color_scheme_package == package: if resource_exists(PackageDisabler.old_color_scheme): settings.set('color_scheme', PackageDisabler.old_color_scheme) else: color_scheme_errors.add( PackageDisabler.old_color_scheme) sublime.error_message( text.format(u''' PackagesManager The package containing your active color scheme was just upgraded, however the .tmTheme file no longer exists. Sublime Text has been configured use the default color scheme instead. ''')) if operation == 'upgrade' and package in PackageDisabler.old_color_schemes: for view_scheme in PackageDisabler.old_color_schemes[ package]: view, scheme = view_scheme if resource_exists(scheme): view.settings().set('color_scheme', scheme) elif scheme not in color_scheme_errors: console_write( u'The color scheme "%s" no longer exists' % scheme) color_scheme_errors.add(scheme) if operation == 'upgrade' and PackageDisabler.old_theme_package == package: if package_file_exists(package, PackageDisabler.old_theme): settings.set('theme', PackageDisabler.old_theme) message = text.format(u''' PackagesManager The package containing your active theme was just upgraded. ''') if int(sublime.version()) < 3106: message += corruption_notice sublime.message_dialog(message) else: sublime.error_message( text.format(u''' PackagesManager The package containing your active theme was just upgraded, however the .sublime-theme file no longer exists. Sublime Text has been configured use the default theme instead. ''')) sublime.save_settings(preferences_filename()) sublime.set_timeout(delayed_settings_restore, 1000) threading.Thread(target=self._delayed_in_progress_removal, args=(packages, )).start()