mopidy / mopidy
1 2
import functools
2 2
import os
3 2
import platform
4 2
import sys
5

6 2
import pkg_resources
7

8 2
from mopidy.internal import formatting
9 2
from mopidy.internal.gi import Gst, gi
10

11

12 2
def format_dependency_list(adapters=None):
13 2
    if adapters is None:
14 0
        dist_names = {
15
            ep.dist.project_name
16
            for ep in pkg_resources.iter_entry_points("mopidy.ext")
17
            if ep.dist.project_name != "Mopidy"
18
        }
19 0
        dist_infos = [
20
            functools.partial(pkg_info, dist_name) for dist_name in dist_names
21
        ]
22

23 0
        adapters = (
24
            [
25
                executable_info,
26
                platform_info,
27
                python_info,
28
                functools.partial(pkg_info, "Mopidy", True),
29
            ]
30
            + dist_infos
31
            + [gstreamer_info]
32
        )
33

34 2
    return "\n".join(_format_dependency(a()) for a in adapters)
35

36

37 2
def _format_dependency(dep_info):
38 2
    lines = []
39

40 2
    if "version" not in dep_info:
41 2
        lines.append(f"{dep_info['name']}: not found")
42
    else:
43 2
        source = f" from {dep_info['path']}" if "path" in dep_info else ""
44 2
        lines.append(f"{dep_info['name']}: {dep_info['version']}{source}")
45

46 2
    if "other" in dep_info:
47 2
        details = formatting.indent(dep_info["other"], places=4)
48 2
        lines.append(f"  Detailed information: {details}")
49

50 2
    if dep_info.get("dependencies", []):
51 2
        for sub_dep_info in dep_info["dependencies"]:
52 2
            sub_dep_lines = _format_dependency(sub_dep_info)
53 2
            lines.append(
54
                formatting.indent(sub_dep_lines, places=2, singles=True)
55
            )
56

57 2
    return "\n".join(lines)
58

59

60 2
def executable_info():
61 2
    return {
62
        "name": "Executable",
63
        "version": sys.argv[0],
64
    }
65

66

67 2
def platform_info():
68 2
    return {
69
        "name": "Platform",
70
        "version": platform.platform(),
71
    }
72

73

74 2
def python_info():
75 2
    return {
76
        "name": "Python",
77
        "version": (
78
            f"{platform.python_implementation()} {platform.python_version()}"
79
        ),
80
        "path": os.path.dirname(platform.__file__),
81
    }
82

83

84 2
def pkg_info(
85
    project_name=None, include_transitive_deps=True, include_extras=False
86
):
87 2
    if project_name is None:
88 2
        project_name = "Mopidy"
89 2
    try:
90 2
        distribution = pkg_resources.get_distribution(project_name)
91 2
        extras = include_extras and distribution.extras or []
92 2
        if include_transitive_deps:
93 2
            dependencies = [
94
                pkg_info(
95
                    d.project_name,
96
                    include_transitive_deps=d.project_name != "Mopidy",
97
                )
98
                for d in distribution.requires(extras)
99
            ]
100
        else:
101 0
            dependencies = []
102 2
        return {
103
            "name": project_name,
104
            "version": distribution.version,
105
            "path": distribution.location,
106
            "dependencies": dependencies,
107
        }
108 2
    except pkg_resources.ResolutionError:
109 2
        return {
110
            "name": project_name,
111
        }
112

113

114 2
def gstreamer_info():
115 2
    other = []
116 2
    other.append(f"Python wrapper: python-gi {gi.__version__}")
117

118 2
    found_elements = []
119 2
    missing_elements = []
120 2
    for name, status in _gstreamer_check_elements():
121 2
        if status:
122 2
            found_elements.append(name)
123
        else:
124 2
            missing_elements.append(name)
125

126 2
    other.append("Relevant elements:")
127 2
    other.append("  Found:")
128 2
    for element in found_elements:
129 2
        other.append(f"    {element}")
130 2
    if not found_elements:
131 0
        other.append("    none")
132 2
    other.append("  Not found:")
133 2
    for element in missing_elements:
134 2
        other.append(f"    {element}")
135 2
    if not missing_elements:
136 0
        other.append("    none")
137

138 2
    return {
139
        "name": "GStreamer",
140
        "version": ".".join(map(str, Gst.version())),
141
        "path": os.path.dirname(gi.__file__),
142
        "other": "\n".join(other),
143
    }
144

145

146 2
def _gstreamer_check_elements():
147 2
    elements_to_check = [
148
        # Core playback
149
        "uridecodebin",
150
        # External HTTP streams
151
        "souphttpsrc",
152
        # Spotify
153
        "appsrc",
154
        # Audio sinks
155
        "alsasink",
156
        "osssink",
157
        "oss4sink",
158
        "pulsesink",
159
        # MP3 encoding and decoding
160
        #
161
        # One of flump3dec, mad, and mpg123audiodec is required for MP3
162
        # playback.
163
        "flump3dec",
164
        "id3demux",
165
        "id3v2mux",
166
        "lamemp3enc",
167
        "mad",
168
        "mpegaudioparse",
169
        "mpg123audiodec",
170
        # Ogg Vorbis encoding and decoding
171
        "vorbisdec",
172
        "vorbisenc",
173
        "vorbisparse",
174
        "oggdemux",
175
        "oggmux",
176
        "oggparse",
177
        # Flac decoding
178
        "flacdec",
179
        "flacparse",
180
        # Shoutcast output
181
        "shout2send",
182
    ]
183 2
    known_elements = [
184
        factory.get_name()
185
        for factory in Gst.Registry.get().get_feature_list(Gst.ElementFactory)
186
    ]
187 2
    return [
188
        (element, element in known_elements) for element in elements_to_check
189
    ]

Read our documentation on viewing source code .

Loading