2018-05-22 13:16:13 +02:00
|
|
|
"""
|
|
|
|
Utility functions to check the availability of dependencies
|
|
|
|
and suggest how it may be installed
|
|
|
|
"""
|
2014-08-06 08:40:41 +02:00
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
import sys
|
2014-08-06 08:40:41 +02:00
|
|
|
|
2018-03-21 11:17:55 +01:00
|
|
|
# Only really old versions of Python don't have sys.hexversion. We don't
|
|
|
|
# support them. The logging module was introduced in Python 2.3
|
2014-08-06 08:40:41 +02:00
|
|
|
if not hasattr(sys, 'hexversion') or sys.hexversion < 0x20300F0:
|
2018-04-18 12:34:12 +02:00
|
|
|
sys.exit(
|
|
|
|
'Python version: %s\n'
|
2018-05-24 10:53:07 +02:00
|
|
|
'PyBitmessage requires Python 2.7.4 or greater (but not Python 3)'
|
2018-04-18 12:34:12 +02:00
|
|
|
% sys.version
|
|
|
|
)
|
2014-08-06 08:40:41 +02:00
|
|
|
|
|
|
|
import logging
|
2018-05-22 13:16:13 +02:00
|
|
|
import os
|
|
|
|
from importlib import import_module
|
|
|
|
|
|
|
|
# We can now use logging so set up a simple configuration
|
2018-07-21 11:16:22 +02:00
|
|
|
formatter = logging.Formatter('%(levelname)s: %(message)s')
|
2014-08-06 08:40:41 +02:00
|
|
|
handler = logging.StreamHandler(sys.stdout)
|
|
|
|
handler.setFormatter(formatter)
|
2018-05-22 13:16:13 +02:00
|
|
|
logger = logging.getLogger('both')
|
2014-08-06 08:40:41 +02:00
|
|
|
logger.addHandler(handler)
|
|
|
|
logger.setLevel(logging.ERROR)
|
|
|
|
|
2018-07-21 11:16:22 +02:00
|
|
|
|
2018-06-23 13:01:28 +02:00
|
|
|
OS_RELEASE = {
|
2018-07-22 13:42:29 +02:00
|
|
|
"Debian GNU/Linux".lower(): "Debian",
|
2018-06-23 13:01:28 +02:00
|
|
|
"fedora": "Fedora",
|
|
|
|
"opensuse": "openSUSE",
|
|
|
|
"ubuntu": "Ubuntu",
|
|
|
|
"gentoo": "Gentoo",
|
|
|
|
"calculate": "Gentoo"
|
|
|
|
}
|
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
PACKAGE_MANAGER = {
|
|
|
|
"OpenBSD": "pkg_add",
|
|
|
|
"FreeBSD": "pkg install",
|
|
|
|
"Debian": "apt-get install",
|
|
|
|
"Ubuntu": "apt-get install",
|
|
|
|
"Ubuntu 12": "apt-get install",
|
|
|
|
"openSUSE": "zypper install",
|
|
|
|
"Fedora": "dnf install",
|
|
|
|
"Guix": "guix package -i",
|
|
|
|
"Gentoo": "emerge"
|
|
|
|
}
|
|
|
|
|
|
|
|
PACKAGES = {
|
|
|
|
"PyQt4": {
|
|
|
|
"OpenBSD": "py-qt4",
|
|
|
|
"FreeBSD": "py27-qt4",
|
|
|
|
"Debian": "python-qt4",
|
|
|
|
"Ubuntu": "python-qt4",
|
|
|
|
"Ubuntu 12": "python-qt4",
|
|
|
|
"openSUSE": "python-qt",
|
|
|
|
"Fedora": "PyQt4",
|
|
|
|
"Guix": "python2-pyqt@4.11.4",
|
|
|
|
"Gentoo": "dev-python/PyQt4",
|
|
|
|
"optional": True,
|
|
|
|
"description":
|
|
|
|
"You only need PyQt if you want to use the GUI."
|
|
|
|
" When only running as a daemon, this can be skipped.\n"
|
|
|
|
"However, you would have to install it manually"
|
|
|
|
" because setuptools does not support PyQt."
|
|
|
|
},
|
|
|
|
"msgpack": {
|
|
|
|
"OpenBSD": "py-msgpack",
|
|
|
|
"FreeBSD": "py27-msgpack-python",
|
|
|
|
"Debian": "python-msgpack",
|
|
|
|
"Ubuntu": "python-msgpack",
|
|
|
|
"Ubuntu 12": "msgpack-python",
|
|
|
|
"openSUSE": "python-msgpack-python",
|
|
|
|
"Fedora": "python2-msgpack",
|
|
|
|
"Guix": "python2-msgpack",
|
|
|
|
"Gentoo": "dev-python/msgpack",
|
|
|
|
"optional": True,
|
|
|
|
"description":
|
|
|
|
"python-msgpack is recommended for improved performance of"
|
|
|
|
" message encoding/decoding"
|
|
|
|
},
|
|
|
|
"pyopencl": {
|
|
|
|
"FreeBSD": "py27-pyopencl",
|
|
|
|
"Debian": "python-pyopencl",
|
|
|
|
"Ubuntu": "python-pyopencl",
|
|
|
|
"Ubuntu 12": "python-pyopencl",
|
|
|
|
"Fedora": "python2-pyopencl",
|
|
|
|
"openSUSE": "",
|
|
|
|
"OpenBSD": "",
|
|
|
|
"Guix": "",
|
|
|
|
"Gentoo": "dev-python/pyopencl",
|
|
|
|
"optional": True,
|
|
|
|
"description":
|
|
|
|
"If you install pyopencl, you will be able to use"
|
|
|
|
" GPU acceleration for proof of work.\n"
|
|
|
|
"You also need a compatible GPU and drivers."
|
|
|
|
},
|
|
|
|
"setuptools": {
|
|
|
|
"OpenBSD": "py-setuptools",
|
|
|
|
"FreeBSD": "py27-setuptools",
|
|
|
|
"Debian": "python-setuptools",
|
|
|
|
"Ubuntu": "python-setuptools",
|
|
|
|
"Ubuntu 12": "python-setuptools",
|
|
|
|
"Fedora": "python2-setuptools",
|
|
|
|
"openSUSE": "python-setuptools",
|
|
|
|
"Guix": "python2-setuptools",
|
|
|
|
"Gentoo": "dev-python/setuptools",
|
|
|
|
"optional": False,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def detectOS():
|
|
|
|
if detectOS.result is not None:
|
|
|
|
return detectOS.result
|
|
|
|
if sys.platform.startswith('openbsd'):
|
|
|
|
detectOS.result = "OpenBSD"
|
|
|
|
elif sys.platform.startswith('freebsd'):
|
|
|
|
detectOS.result = "FreeBSD"
|
|
|
|
elif sys.platform.startswith('win'):
|
|
|
|
detectOS.result = "Windows"
|
|
|
|
elif os.path.isfile("/etc/os-release"):
|
|
|
|
detectOSRelease()
|
|
|
|
elif os.path.isfile("/etc/config.scm"):
|
|
|
|
detectOS.result = "Guix"
|
|
|
|
return detectOS.result
|
|
|
|
|
|
|
|
|
|
|
|
detectOS.result = None
|
|
|
|
|
|
|
|
|
|
|
|
def detectOSRelease():
|
|
|
|
with open("/etc/os-release", 'r') as osRelease:
|
|
|
|
version = None
|
|
|
|
for line in osRelease:
|
|
|
|
if line.startswith("NAME="):
|
2018-06-23 13:01:28 +02:00
|
|
|
detectOS.result = OS_RELEASE.get(
|
2018-07-19 13:06:34 +02:00
|
|
|
line.replace('"', '').split("=")[-1].strip().lower())
|
2018-06-23 13:01:28 +02:00
|
|
|
elif line.startswith("VERSION_ID="):
|
2018-05-22 13:16:13 +02:00
|
|
|
try:
|
|
|
|
version = float(line.split("=")[1].replace("\"", ""))
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
if detectOS.result == "Ubuntu" and version < 14:
|
|
|
|
detectOS.result = "Ubuntu 12"
|
|
|
|
|
|
|
|
|
|
|
|
def try_import(module, log_extra=False):
|
|
|
|
try:
|
|
|
|
return import_module(module)
|
|
|
|
except ImportError:
|
|
|
|
module = module.split('.')[0]
|
|
|
|
logger.error('The %s module is not available.', module)
|
|
|
|
if log_extra:
|
|
|
|
logger.error(log_extra)
|
|
|
|
dist = detectOS()
|
|
|
|
logger.error(
|
|
|
|
'On %s, try running "%s %s" as root.',
|
|
|
|
dist, PACKAGE_MANAGER[dist], PACKAGES[module][dist])
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2018-03-21 11:17:55 +01:00
|
|
|
# We need to check hashlib for RIPEMD-160, as it won't be available
|
|
|
|
# if OpenSSL is not linked against or the linked OpenSSL has RIPEMD
|
|
|
|
# disabled.
|
2014-08-06 08:40:41 +02:00
|
|
|
def check_hashlib():
|
2018-03-21 11:17:55 +01:00
|
|
|
"""Do hashlib check.
|
|
|
|
|
|
|
|
The hashlib module check with version as if it included or not
|
2018-04-18 12:34:12 +02:00
|
|
|
in The Python Standard library, it's a module containing an
|
2018-03-21 11:17:55 +01:00
|
|
|
interface to the most popular hashing algorithms. hashlib
|
|
|
|
implements some of the algorithms, however if OpenSSL
|
|
|
|
installed, hashlib is able to use this algorithms as well.
|
|
|
|
"""
|
2014-08-06 08:40:41 +02:00
|
|
|
if sys.hexversion < 0x020500F0:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'The hashlib module is not included in this version of Python.')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
|
|
|
import hashlib
|
|
|
|
if '_hashlib' not in hashlib.__dict__:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'The RIPEMD-160 hash algorithm is not available.'
|
|
|
|
' The hashlib module is not linked against OpenSSL.')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
|
|
|
try:
|
|
|
|
hashlib.new('ripemd160')
|
|
|
|
except ValueError:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'The RIPEMD-160 hash algorithm is not available.'
|
|
|
|
' The hashlib module utilizes an OpenSSL library with'
|
|
|
|
' RIPEMD disabled.')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2018-03-22 10:57:37 +01:00
|
|
|
|
2014-08-06 08:40:41 +02:00
|
|
|
def check_sqlite():
|
2018-03-22 10:57:37 +01:00
|
|
|
"""Do sqlite check.
|
2018-03-21 11:17:55 +01:00
|
|
|
|
|
|
|
Simply check sqlite3 module if exist or not with hexversion
|
|
|
|
support in python version for specifieed platform.
|
|
|
|
"""
|
2014-08-06 08:40:41 +02:00
|
|
|
if sys.hexversion < 0x020500F0:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'The sqlite3 module is not included in this version of Python.')
|
2017-02-14 01:33:16 +01:00
|
|
|
if sys.platform.startswith('freebsd'):
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'On FreeBSD, try running "pkg install py27-sqlite3" as root.')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
2018-05-22 13:16:13 +02:00
|
|
|
|
|
|
|
sqlite3 = try_import('sqlite3')
|
|
|
|
if not sqlite3:
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.info('sqlite3 Module Version: %s', sqlite3.version)
|
|
|
|
logger.info('SQLite Library Version: %s', sqlite3.sqlite_version)
|
|
|
|
# sqlite_version_number formula: https://sqlite.org/c3ref/c_source_id.html
|
|
|
|
sqlite_version_number = (
|
2018-05-22 13:16:13 +02:00
|
|
|
sqlite3.sqlite_version_info[0] * 1000000 +
|
|
|
|
sqlite3.sqlite_version_info[1] * 1000 +
|
|
|
|
sqlite3.sqlite_version_info[2]
|
2018-04-18 12:34:12 +02:00
|
|
|
)
|
2014-08-06 08:40:41 +02:00
|
|
|
|
|
|
|
conn = None
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
conn = sqlite3.connect(':memory:')
|
|
|
|
if sqlite_version_number >= 3006018:
|
2018-04-18 12:34:12 +02:00
|
|
|
sqlite_source_id = conn.execute(
|
|
|
|
'SELECT sqlite_source_id();'
|
|
|
|
).fetchone()[0]
|
|
|
|
logger.info('SQLite Library Source ID: %s', sqlite_source_id)
|
2014-08-06 08:40:41 +02:00
|
|
|
if sqlite_version_number >= 3006023:
|
2018-04-18 12:34:12 +02:00
|
|
|
compile_options = ', '.join(map(
|
|
|
|
lambda row: row[0],
|
|
|
|
conn.execute('PRAGMA compile_options;')
|
|
|
|
))
|
|
|
|
logger.info(
|
|
|
|
'SQLite Library Compile Options: %s', compile_options)
|
|
|
|
# There is no specific version requirement as yet, so we just
|
|
|
|
# use the first version that was included with Python.
|
2014-08-06 08:40:41 +02:00
|
|
|
if sqlite_version_number < 3000008:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'This version of SQLite is too old.'
|
|
|
|
' PyBitmessage requires SQLite 3.0.8 or later')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
except sqlite3.Error:
|
|
|
|
logger.exception('An exception occured while checking sqlite.')
|
|
|
|
return False
|
|
|
|
finally:
|
|
|
|
if conn:
|
|
|
|
conn.close()
|
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
|
2014-08-06 08:40:41 +02:00
|
|
|
def check_openssl():
|
2018-03-21 11:17:55 +01:00
|
|
|
"""Do openssl dependency check.
|
|
|
|
|
|
|
|
Here we are checking for openssl with its all dependent libraries
|
|
|
|
and version checking.
|
|
|
|
"""
|
2018-05-22 13:16:13 +02:00
|
|
|
|
|
|
|
ctypes = try_import('ctypes')
|
|
|
|
if not ctypes:
|
|
|
|
logger.error('Unable to check OpenSSL.')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
# We need to emulate the way PyElliptic searches for OpenSSL.
|
2014-08-06 08:40:41 +02:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
paths = ['libeay32.dll']
|
|
|
|
if getattr(sys, 'frozen', False):
|
|
|
|
import os.path
|
2016-01-20 22:31:15 +01:00
|
|
|
paths.insert(0, os.path.join(sys._MEIPASS, 'libeay32.dll'))
|
2014-08-06 08:40:41 +02:00
|
|
|
else:
|
2018-03-09 15:41:20 +01:00
|
|
|
paths = ['libcrypto.so', 'libcrypto.so.1.0.0']
|
2014-08-06 08:40:41 +02:00
|
|
|
if sys.platform == 'darwin':
|
|
|
|
paths.extend([
|
|
|
|
'libcrypto.dylib',
|
|
|
|
'/usr/local/opt/openssl/lib/libcrypto.dylib',
|
|
|
|
'./../Frameworks/libcrypto.dylib'
|
|
|
|
])
|
|
|
|
import re
|
|
|
|
if re.match(r'linux|darwin|freebsd', sys.platform):
|
|
|
|
try:
|
|
|
|
import ctypes.util
|
|
|
|
path = ctypes.util.find_library('ssl')
|
|
|
|
if path not in paths:
|
|
|
|
paths.append(path)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2017-01-13 12:02:34 +01:00
|
|
|
openssl_version = None
|
|
|
|
openssl_hexversion = None
|
|
|
|
openssl_cflags = None
|
2014-08-06 08:40:41 +02:00
|
|
|
|
|
|
|
cflags_regex = re.compile(r'(?:OPENSSL_NO_)(AES|EC|ECDH|ECDSA)(?!\w)')
|
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
import pyelliptic.openssl
|
|
|
|
|
2014-08-06 08:40:41 +02:00
|
|
|
for path in paths:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.info('Checking OpenSSL at %s', path)
|
2014-08-06 08:40:41 +02:00
|
|
|
try:
|
|
|
|
library = ctypes.CDLL(path)
|
|
|
|
except OSError:
|
|
|
|
continue
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.info('OpenSSL Name: %s', library._name)
|
2018-05-26 14:43:21 +02:00
|
|
|
try:
|
2018-04-18 12:34:12 +02:00
|
|
|
openssl_version, openssl_hexversion, openssl_cflags = \
|
|
|
|
pyelliptic.openssl.get_version(library)
|
2018-05-26 14:43:21 +02:00
|
|
|
except AttributeError: # sphinx chokes
|
|
|
|
return True
|
2017-01-13 12:02:34 +01:00
|
|
|
if not openssl_version:
|
2014-08-06 08:40:41 +02:00
|
|
|
logger.error('Cannot determine version of this OpenSSL library.')
|
|
|
|
return False
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.info('OpenSSL Version: %s', openssl_version)
|
|
|
|
logger.info('OpenSSL Compile Options: %s', openssl_cflags)
|
|
|
|
# PyElliptic uses EVP_CIPHER_CTX_new and EVP_CIPHER_CTX_free which were
|
|
|
|
# introduced in 0.9.8b.
|
2014-08-06 08:40:41 +02:00
|
|
|
if openssl_hexversion < 0x90802F:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'This OpenSSL library is too old. PyBitmessage requires'
|
|
|
|
' OpenSSL 0.9.8b or later with AES, Elliptic Curves (EC),'
|
|
|
|
' ECDH, and ECDSA enabled.')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
2017-01-13 12:02:34 +01:00
|
|
|
matches = cflags_regex.findall(openssl_cflags)
|
2014-08-06 08:40:41 +02:00
|
|
|
if len(matches) > 0:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'This OpenSSL library is missing the following required'
|
|
|
|
' features: %s. PyBitmessage requires OpenSSL 0.9.8b'
|
|
|
|
' or later with AES, Elliptic Curves (EC), ECDH,'
|
|
|
|
' and ECDSA enabled.', ', '.join(matches))
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
|
|
|
|
# TODO: The minimum versions of pythondialog and dialog need to be determined
|
2014-08-06 08:40:41 +02:00
|
|
|
def check_curses():
|
2018-03-21 11:17:55 +01:00
|
|
|
"""Do curses dependency check.
|
|
|
|
|
2018-05-26 14:43:21 +02:00
|
|
|
Here we are checking for curses if available or not with check
|
2018-03-21 11:17:55 +01:00
|
|
|
as interface requires the pythondialog\ package and the dialog
|
|
|
|
utility.
|
|
|
|
"""
|
2014-08-06 08:40:41 +02:00
|
|
|
if sys.hexversion < 0x20600F0:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'The curses interface requires the pythondialog package and'
|
|
|
|
' the dialog utility.')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
2018-05-22 13:16:13 +02:00
|
|
|
curses = try_import('curses')
|
|
|
|
if not curses:
|
|
|
|
logger.error('The curses interface can not be used.')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
2018-05-22 13:16:13 +02:00
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.info('curses Module Version: %s', curses.version)
|
2018-05-22 13:16:13 +02:00
|
|
|
|
|
|
|
dialog = try_import('dialog')
|
|
|
|
if not dialog:
|
|
|
|
logger.error('The curses interface can not be used.')
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
2018-05-22 13:16:13 +02:00
|
|
|
|
|
|
|
import subprocess
|
|
|
|
|
2018-05-26 14:43:21 +02:00
|
|
|
try:
|
|
|
|
subprocess.check_call('which dialog')
|
|
|
|
except subprocess.CalledProcessError:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'Curses requires the `dialog` command to be installed as well as'
|
|
|
|
' the python library.')
|
2018-05-26 14:43:21 +02:00
|
|
|
return False
|
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.info('pythondialog Package Version: %s', dialog.__version__)
|
2014-08-06 08:40:41 +02:00
|
|
|
dialog_util_version = dialog.Dialog().cached_backend_version
|
2018-04-18 12:34:12 +02:00
|
|
|
# The pythondialog author does not like Python2 str, so we have to use
|
|
|
|
# unicode for just the version otherwise we get the repr form which
|
|
|
|
# includes the module and class names along with the actual version.
|
|
|
|
logger.info('dialog Utility Version %s', unicode(dialog_util_version))
|
2014-08-06 08:40:41 +02:00
|
|
|
return True
|
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
|
2014-08-06 08:40:41 +02:00
|
|
|
def check_pyqt():
|
2018-03-21 11:17:55 +01:00
|
|
|
"""Do pyqt dependency check.
|
|
|
|
|
|
|
|
Here we are checking for PyQt4 with its version, as for it require
|
2018-05-22 13:16:13 +02:00
|
|
|
PyQt 4.8 or later.
|
2018-03-21 11:17:55 +01:00
|
|
|
"""
|
2018-05-22 13:16:13 +02:00
|
|
|
QtCore = try_import(
|
|
|
|
'PyQt4.QtCore', 'PyBitmessage requires PyQt 4.8 or later and Qt 4.7 or later.')
|
|
|
|
|
|
|
|
if not QtCore:
|
2014-08-06 08:40:41 +02:00
|
|
|
return False
|
2018-05-22 13:16:13 +02:00
|
|
|
|
|
|
|
logger.info('PyQt Version: %s', QtCore.PYQT_VERSION_STR)
|
|
|
|
logger.info('Qt Version: %s', QtCore.QT_VERSION_STR)
|
2014-08-06 08:40:41 +02:00
|
|
|
passed = True
|
2018-05-22 13:16:13 +02:00
|
|
|
if QtCore.PYQT_VERSION < 0x40800:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'This version of PyQt is too old. PyBitmessage requries'
|
|
|
|
' PyQt 4.8 or later.')
|
2014-08-06 08:40:41 +02:00
|
|
|
passed = False
|
2018-05-22 13:16:13 +02:00
|
|
|
if QtCore.QT_VERSION < 0x40700:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
|
|
|
'This version of Qt is too old. PyBitmessage requries'
|
|
|
|
' Qt 4.7 or later.')
|
2014-08-06 08:40:41 +02:00
|
|
|
passed = False
|
|
|
|
return passed
|
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
|
2017-02-14 01:33:16 +01:00
|
|
|
def check_msgpack():
|
2018-03-21 11:17:55 +01:00
|
|
|
"""Do sgpack module check.
|
|
|
|
|
2018-05-26 14:43:21 +02:00
|
|
|
simply checking if msgpack package with all its dependency
|
2018-03-21 11:17:55 +01:00
|
|
|
is available or not as recommended for messages coding.
|
|
|
|
"""
|
2018-05-22 13:16:13 +02:00
|
|
|
return try_import(
|
|
|
|
'msgpack', 'It is highly recommended for messages coding.') is not False
|
2017-02-14 01:33:16 +01:00
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
|
|
|
|
def check_dependencies(verbose=False, optional=False):
|
2018-03-21 11:17:55 +01:00
|
|
|
"""Do dependency check.
|
|
|
|
|
|
|
|
It identifies project dependencies and checks if there are
|
|
|
|
any known, publicly disclosed, vulnerabilities.basically
|
|
|
|
scan applications (and their dependent libraries) so that
|
|
|
|
easily identify any known vulnerable components.
|
|
|
|
"""
|
2014-08-06 08:40:41 +02:00
|
|
|
if verbose:
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
|
|
|
has_all_dependencies = True
|
|
|
|
|
2018-05-24 10:53:07 +02:00
|
|
|
# Python 2.7.4 is the required minimum.
|
|
|
|
# (https://bitmessage.org/forum/index.php?topic=4081.0)
|
|
|
|
# Python 3+ is not supported, but it is still useful to provide
|
|
|
|
# information about our other requirements.
|
2014-08-06 08:40:41 +02:00
|
|
|
logger.info('Python version: %s', sys.version)
|
2018-05-24 10:53:07 +02:00
|
|
|
if sys.hexversion < 0x20704F0:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
2018-05-24 10:53:07 +02:00
|
|
|
'PyBitmessage requires Python 2.7.4 or greater'
|
2018-04-18 12:34:12 +02:00
|
|
|
' (but not Python 3+)')
|
2014-08-06 08:40:41 +02:00
|
|
|
has_all_dependencies = False
|
|
|
|
if sys.hexversion >= 0x3000000:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.error(
|
2018-05-24 10:53:07 +02:00
|
|
|
'PyBitmessage does not support Python 3+. Python 2.7.4'
|
2018-04-18 12:34:12 +02:00
|
|
|
' or greater is required.')
|
2014-08-06 08:40:41 +02:00
|
|
|
has_all_dependencies = False
|
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
check_functions = [check_hashlib, check_sqlite, check_openssl]
|
2014-08-06 08:40:41 +02:00
|
|
|
if optional:
|
2018-05-22 13:16:13 +02:00
|
|
|
check_functions.extend([check_msgpack, check_pyqt, check_curses])
|
2014-08-06 08:40:41 +02:00
|
|
|
|
2018-04-18 12:34:12 +02:00
|
|
|
# Unexpected exceptions are handled here
|
2014-08-06 08:40:41 +02:00
|
|
|
for check in check_functions:
|
|
|
|
try:
|
|
|
|
has_all_dependencies &= check()
|
|
|
|
except:
|
2018-04-18 12:34:12 +02:00
|
|
|
logger.exception('%s failed unexpectedly.', check.__name__)
|
2014-08-06 08:40:41 +02:00
|
|
|
has_all_dependencies = False
|
2018-05-26 14:43:21 +02:00
|
|
|
|
2014-08-06 08:40:41 +02:00
|
|
|
if not has_all_dependencies:
|
2018-04-18 12:34:12 +02:00
|
|
|
sys.exit(
|
|
|
|
'PyBitmessage cannot start. One or more dependencies are'
|
|
|
|
' unavailable.'
|
|
|
|
)
|
2018-07-21 11:16:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
logger.setLevel(0)
|