2016-11-10 21:49:51 +01:00
|
|
|
import platform
|
2018-07-21 20:12:29 +02:00
|
|
|
import json
|
2017-04-26 20:18:41 +02:00
|
|
|
import os
|
2016-11-10 21:49:51 +01:00
|
|
|
|
2018-07-05 05:16:52 +02:00
|
|
|
from six.moves.urllib import request
|
2018-07-03 06:51:25 +02:00
|
|
|
from six.moves.urllib.error import URLError
|
2018-09-17 22:31:44 +02:00
|
|
|
from lbrynet.schema import __version__ as schema_version
|
2017-04-26 20:18:41 +02:00
|
|
|
from lbrynet import build_type, __version__ as lbrynet_version
|
2018-09-19 18:42:12 +02:00
|
|
|
import logging.handlers
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
2016-11-10 21:49:51 +01:00
|
|
|
|
|
|
|
|
2018-10-05 16:20:32 +02:00
|
|
|
def get_lbrynet_version() -> str:
|
2017-04-26 20:18:41 +02:00
|
|
|
return lbrynet_version
|
|
|
|
|
|
|
|
|
2018-10-05 16:20:32 +02:00
|
|
|
def get_platform(get_ip: bool = True) -> dict:
|
2016-11-10 21:49:51 +01:00
|
|
|
p = {
|
|
|
|
"processor": platform.processor(),
|
|
|
|
"python_version": platform.python_version(),
|
|
|
|
"platform": platform.platform(),
|
|
|
|
"os_release": platform.release(),
|
|
|
|
"os_system": platform.system(),
|
2017-04-26 20:18:41 +02:00
|
|
|
"lbrynet_version": get_lbrynet_version(),
|
2018-09-17 22:31:44 +02:00
|
|
|
"lbryschema_version": schema_version,
|
2017-03-15 21:33:41 +01:00
|
|
|
"build": build_type.BUILD, # CI server sets this during build step
|
2016-11-10 21:49:51 +01:00
|
|
|
}
|
2018-05-29 00:07:23 +02:00
|
|
|
if p["os_system"] == "Linux":
|
2018-08-17 16:28:47 +02:00
|
|
|
try:
|
|
|
|
import distro
|
|
|
|
p["distro"] = distro.info()
|
|
|
|
p["desktop"] = os.environ.get('XDG_CURRENT_DESKTOP', 'Unknown')
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
pass
|
2016-11-10 21:49:51 +01:00
|
|
|
|
2018-05-05 07:20:21 +02:00
|
|
|
# TODO: remove this from get_platform and add a get_external_ip function using treq
|
2017-03-15 21:19:11 +01:00
|
|
|
if get_ip:
|
|
|
|
try:
|
2018-07-05 05:16:52 +02:00
|
|
|
response = json.loads(request.urlopen("https://api.lbry.io/ip").read())
|
2018-01-22 21:47:14 +01:00
|
|
|
if not response['success']:
|
|
|
|
raise URLError("failed to get external ip")
|
|
|
|
p['ip'] = response['data']['ip']
|
|
|
|
except (URLError, AssertionError):
|
2017-03-15 21:19:11 +01:00
|
|
|
p['ip'] = "Could not determine IP"
|
2016-11-10 21:49:51 +01:00
|
|
|
|
|
|
|
return p
|