-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathabout_module.py
More file actions
161 lines (120 loc) · 4.97 KB
/
about_module.py
File metadata and controls
161 lines (120 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from __future__ import absolute_import
import abc
import os
import sys
import textwrap
from future.utils import with_metaclass
import preditor
class AboutModule(with_metaclass(abc.ABCMeta, object)):
"""Base class for the `preditor.plug.about_module` entry point. Create a
subclass of this method and expose the class object to the entry point.
Properties:
instance: If provided, the instance of PrEditor to generate text for.
"""
indent = " "
"""Use this to indent new lines for text"""
def __init__(self, instance=None):
self.instance = instance
@classmethod
def generate(cls, instance=None):
"""Generates the output text for all plugins.
Outputs this for each plugin:
{name}: {version}
{indent}{text line 1}
{indent}{text line ...}
Name is the name of each entry point. If duplicates are found, a logging
warning is generated. Each line of `self.text()` is indented
"""
ret = []
for name, plugin in preditor.plugins.about_module():
version = "Unknown"
if isinstance(plugin, str):
text = plugin
else:
try:
plug = plugin(instance=instance)
if not plug.enabled():
continue
version = plug.version()
text = plug.text()
except Exception as error:
text = "Error processing: {}".format(error)
text = textwrap.indent(text, cls.indent)
# Build the output string including the version information if provided.
if version is not None:
ret.append("{}: {}\n{}".format(name, version, text))
else:
ret.append("{}:\n{}".format(name, text))
return '\n'.join(ret)
def enabled(self):
"""The plugin can use this to disable reporting by generate."""
return True
@abc.abstractmethod
def text(self):
"""Returns info about this plugin. This can have multiple lines, and
each line will be indented to provide visual distinction between plugins.
"""
@abc.abstractmethod
def version(self):
"""Returns The version as a string to show next to name."""
class AboutPreditor(AboutModule):
"""About module used to show info about PrEditor."""
def text(self):
"""Return the path PrEditor was loaded from for quick debugging."""
ret = []
# Include the core_name of the current PrEditor gui instance if possible
if self.instance:
ret.append("Core Name: {}".format(self.instance.name))
# THe path to the PrEditor package
ret.append("Path: {}".format(os.path.dirname(preditor.__file__)))
return "\n".join(ret)
def version(self):
return preditor.__version__
class AboutQt(AboutModule):
"""Info about Qt modules being used."""
def text(self):
"""Return the path PrEditor was loaded from for quick debugging."""
from Qt import QtCore, __binding__, __version__
ret = ['Qt.py: {}, binding: {}'.format(__version__, __binding__)]
# Attempt to get a version for QtSiteConfig if defined
try:
import QtSiteConfig
ret.append('QtSiteConfig: {}'.format(QtSiteConfig.__version__))
except (ImportError, AttributeError):
pass
# Add info for all Qt5 bindings that have been imported
if 'PyQt5.QtCore' in sys.modules:
ret.append('PyQt5: {}'.format(sys.modules['PyQt5.QtCore'].PYQT_VERSION_STR))
if 'PySide2.QtCore' in sys.modules:
ret.append('PySide2: {}'.format(sys.modules['PySide2.QtCore'].qVersion()))
# Add qt library paths for plugin debugging
for i, path in enumerate(QtCore.QCoreApplication.libraryPaths()):
if i == 0:
ret.append('Library Paths: {}'.format(path))
else:
ret.append(' {}'.format(path))
return "\n".join(ret)
def version(self):
from Qt import __qt_version__
return __qt_version__
class AboutPython(AboutModule):
"""Info about the current instance of python."""
def text(self):
"""Return the path PrEditor was loaded from for quick debugging."""
ret = sys.version
# Windows doesn't add a newline before the compiler info, and it can end
# up being a little long for QMessageBox's with short file paths. Add
# the newline like is present on linux
ret = ret.replace(") [", ")\n[")
return ret
def version(self):
return '{}.{}.{}'.format(*sys.version_info[:3])
class AboutExe(AboutModule):
"""The value of sys.executable, disabled if not set."""
def enabled(self):
return bool(sys.executable)
def text(self):
return sys.executable
def version(self):
"""No version is returned for this class."""
return None