diff --git a/Default.sublime-commands b/Default.sublime-commands index 3d351d40..a17eeb59 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -59,6 +59,10 @@ "caption": "Package Control: List Unmanaged Packages", "command": "list_unmanaged_packages" }, + { + "caption": "Package Control: Show Package Report", + "command": "show_package_report" + }, { "caption": "Package Control: Remove Channel", "command": "remove_channel" diff --git a/package_report.py b/package_report.py new file mode 100644 index 00000000..8e99605c --- /dev/null +++ b/package_report.py @@ -0,0 +1,193 @@ +import html +import sublime +import sublime_plugin + +from package_control.package_disabler import PackageDisabler +from package_control.package_manager import PackageManager + + +sheet = None + + +def plugin_loaded(): + PackageListener.start() + +def plugin_unloaded(): + PackageListener.stop() + + +class PackageListener: + _ignored = [] + _settings = None + _uuid = "5b991c43-d049-4ac7-878e-c22f201a4b3c" + + @classmethod + def settings(cls): + return sublime.load_settings("Preferences.sublime-settings") + + @classmethod + def start(cls): + if cls._settings is None: + cls._settings = sublime.load_settings("Preferences.sublime-settings") + cls._ignored = cls._settings.get("ignored_packages", []) + cls._settings.add_on_change(cls._uuid, cls._on_change) + + @classmethod + def stop(cls): + if cls._settings is not None: + cls.settings().clear_on_change(cls._uuid) + cls._settings = None + + @classmethod + def _on_change(cls): + if not cls._settings: + return + + ignored = cls._settings.get("ignored_packages", []) + if ignored == cls._ignored: + return + + cls._ignored = ignored + sublime.run_command("show_package_report", {"update_only": True}) + + +class ShowPackageReportCommand(sublime_plugin.ApplicationCommand): + + def run(self, update_only=False): + global sheet + + window = sublime.active_window() + if not window: + return + + if update_only: + if sheet is None or sheet.window() is None: + return + + package_manager = PackageManager() + + content = """ + + + + """ + + disabled_packages = PackageDisabler.ignored_packages() + + package_htmls = [] + + for package in sorted(package_manager.list_packages(), key=lambda s: s.lower()): + p_html = "

" + package + "

" + + # meta data line + meta = package_manager.get_metadata(package) + + p_html += '
' + is_enabled = package not in disabled_packages + if is_enabled: + p_html += '' + else: + p_html += '' + p_html += ' | ' + p_html += meta.get("version", "unknown") + p_html += ' | ' + p_html += "py " + str(package_manager.get_python_version(package)) + p_html += ' | ' + p_html += "managed" if package_manager.is_managed(package) else "unmanaged" + + url = meta.get("url") + if url: + p_html += ' | ' + p_html += '' + url + "" + + p_html += "
" + + # commands + p_html += '
' + if is_enabled: + p_html += '[ disable ]' + else: + p_html += '[ enable ]' + p_html += ' ' + p_html += '[ remove ]' + + p_html += "
" + + # package body + p_html += '
' + p_html += ( + "

" + html.escape(meta.get("description", "no description")) + "

" + ) + + libraries = package_manager.get_libraries(package) + if libraries: + p_html += "

Requirements:

" + p_html += "" + + p_html += "
" + + package_htmls.append(p_html) + + content += "".join(package_htmls) + content += "" + content += "" + + if sheet is None or sheet.window() is None: + window = sublime.active_window() + if not window: + window = sublime.windows()[0] + + sheet = window.new_html_sheet("Package Details", content) + + else: + sheet.set_contents(content)