lbry-sdk/lbrynet/core/system_info.py

56 lines
1.9 KiB
Python
Raw Normal View History

2018-07-05 05:16:52 +02:00
from __future__ import print_function
import platform
import json
2017-04-26 20:18:41 +02:00
import subprocess
import os
2018-07-05 05:16:52 +02:00
from six.moves.urllib import request
from six.moves.urllib.error import URLError
2017-06-27 23:52:58 +02:00
from lbryschema import __version__ as lbryschema_version
2017-04-26 20:18:41 +02:00
from lbrynet import build_type, __version__ as lbrynet_version
from lbrynet.conf import ROOT_DIR
2017-04-26 20:18:41 +02:00
def get_lbrynet_version():
if build_type.BUILD == "dev":
try:
with open(os.devnull, 'w') as devnull:
git_dir = ROOT_DIR + '/.git'
return subprocess.check_output(
['git', '--git-dir='+git_dir, 'describe', '--dirty', '--always'],
stderr=devnull
).decode().strip().lstrip('v')
2017-04-26 20:18:41 +02:00
except (subprocess.CalledProcessError, OSError):
print("failed to get version from git")
2017-04-26 20:18:41 +02:00
return lbrynet_version
def get_platform(get_ip=True):
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(),
"lbryschema_version": lbryschema_version,
2017-03-15 21:33:41 +01:00
"build": build_type.BUILD, # CI server sets this during build step
}
if p["os_system"] == "Linux":
import distro
p["distro"] = distro.info()
p["desktop"] = os.environ.get('XDG_CURRENT_DESKTOP', 'Unknown')
2018-05-05 07:20:21 +02:00
# TODO: remove this from get_platform and add a get_external_ip function using treq
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):
p['ip'] = "Could not determine IP"
return p