1# -*- coding: utf-8 -*-
2#
3# Picard, the next-generation MusicBrainz tagger
4#
5# Copyright (C) 2006-2014 Lukáš Lalinský
6# Copyright (C) 2014-2015, 2017-2018 Laurent Monin
7# Copyright (C) 2016 Sambhav Kothari
8# Copyright (C) 2018-2019 Philipp Wolfer
9#
10# This program is free software; you can redistribute it and/or
11# modify it under the terms of the GNU General Public License
12# as published by the Free Software Foundation; either version 2
13# of the License, or (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
24
25from collections import OrderedDict
26from platform import python_version
27
28from mutagen import version_string as mutagen_version
29
30from PyQt5.QtCore import (
31    PYQT_VERSION_STR as pyqt_version,
32    qVersion,
33)
34from PyQt5.QtNetwork import QSslSocket
35
36from picard import PICARD_FANCY_VERSION_STR
37from picard.disc import discid_version
38from picard.util.astrcmp import astrcmp_implementation
39
40
41_versions = OrderedDict([
42    ("version", PICARD_FANCY_VERSION_STR),
43    ("python-version", python_version()),
44    ("pyqt-version", pyqt_version),
45    ("qt-version", qVersion()),
46    ("mutagen-version", mutagen_version),
47    ("discid-version", discid_version),
48    ("astrcmp", astrcmp_implementation),
49    ("ssl-version", QSslSocket.sslLibraryVersionString())
50])
51
52_names = {
53    "version": "Picard",
54    "python-version": "Python",
55    "pyqt-version": "PyQt",
56    "qt-version": "Qt",
57    "mutagen-version": "Mutagen",
58    "discid-version": "Discid",
59    "astrcmp": "astrcmp",
60    "ssl-version": "SSL",
61}
62
63
64def _value_as_text(value, i18n=False):
65    if not value:
66        value = N_("is not installed")
67        if i18n:
68            return _(value)
69    return value
70
71
72def version_name(key):
73    return _names[key]
74
75
76def as_dict(i18n=False):
77    return OrderedDict([(key, _value_as_text(value, i18n)) for key,
78                        value in
79                        _versions.items()])
80
81
82def as_string(i18n=False, separator=", "):
83    values = as_dict(i18n)
84    return separator.join([_names[key] + " " + value for key, value in
85                           values.items()])
86