Skip to content

Commit

Permalink
Add support info command
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Jul 18, 2016
1 parent f3a61f3 commit 8bf15c4
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children":
[
Expand Down Expand Up @@ -29,6 +27,11 @@
},
"caption": "Settings – User"
},
{ "caption": "-" },
{
"caption": "Support Info",
"command": "color_helper_support_info"
},
{ "caption": "-" }
]
}
Expand Down
92 changes: 92 additions & 0 deletions support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""Support command."""
import sublime
import sublime_plugin
import textwrap

__version__ = "1.4.2"
__pc_name__ = 'ColorHelper'


def list2string(obj):
"""Convert list to string."""

return '.'.join([str(x) for x in obj])


def format_version(module, attr, call=False):
"""Format the version."""

try:
if call:
version = getattr(module, attr)()
else:
version = getattr(module, attr)
except Exception as e:
print(e)
version = 'Version could not be acquired!'

if not isinstance(version, str):
version = list2string(version)
return version


def is_installed_by_package_control():
"""Check if installed by package control."""

settings = sublime.load_settings('Package Control.sublime-settings')
return str(__pc_name__ in set(settings.get('installed_packages', [])))


class ColorHelperSupportInfoCommand(sublime_plugin.ApplicationCommand):
"""Support info."""

def run(self):
"""Run command."""

info = {}

info["platform"] = sublime.platform()
info["version"] = sublime.version()
info["arch"] = sublime.arch()
info["ch_version"] = __version__
info["pc_install"] = is_installed_by_package_control()
try:
import mdpopups
info["mdpopups_version"] = format_version(mdpopups, 'version', call=True)
except Exception:
info["mdpopups_version"] = 'Version could not be acquired!'

try:
import markdown
info["markdown_version"] = format_version(markdown, 'version')
except Exception:
info["markdown_version"] = 'Version could not be acquired!'

try:
import jinja2
info["jinja_version"] = format_version(jinja2, '__version__')
except Exception:
info["jinja_version"] = 'Version could not be acquired!'

try:
import pygments
info["pygments_version"] = format_version(pygments, '__version__')
except Exception:
info["pygments_version"] = 'Version could not be acquired!'

msg = textwrap.dedent(
"""\
- ST ver.: %(version)s
- Platform: %(platform)s
- Arch: %(arch)s
- Plugin ver.: %(ch_version)s
- Install via PC: %(pc_install)s
- mdpopups ver.: %(mdpopups_version)s
- markdown ver.: %(markdown_version)s
- pygments ver.: %(pygments_version)s
- jinja2 ver.: %(jinja_version)s
""" % info
)

sublime.message_dialog(msg + '\nInfo has been copied to the clipboard.')
sublime.set_clipboard(msg)

0 comments on commit 8bf15c4

Please sign in to comment.