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())
예제 #2
0
    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)
예제 #3
0
    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())
예제 #4
0
    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, 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()