add --version flag, remove simplejson dependency

This commit is contained in:
Alex Grintsvayg 2017-03-15 16:19:11 -04:00
parent 1c2290dc8e
commit 29dea4901e
9 changed files with 60 additions and 48 deletions

View file

@ -32,7 +32,7 @@ Tell us what happens instead
<!-- For the daemon, run:
curl 'http://localhost:5279/lbryapi' --data '{"method":"version"}'
and include the output -->
and include the full output -->
- LBRY Daemon version:
- LBRY App version:

View file

@ -9,12 +9,12 @@ at anytime.
## [Unreleased]
### Added
*
* Added `--version` flag
*
*
### Changed
*
* Removed `simplejson` dependency in favor of bulitin `json`
*
*

View file

@ -1,5 +1,5 @@
import platform
import simplejson as json
import json
from urllib2 import urlopen
@ -8,7 +8,7 @@ from lbrynet import build_type
from lbryum.version import LBRYUM_VERSION as lbryum_version
def get_platform():
def get_platform(get_ip=True):
p = {
"processor": platform.processor(),
"python_version": platform.python_version(),
@ -17,13 +17,13 @@ def get_platform():
"os_system": platform.system(),
"lbrynet_version": lbrynet_version,
"lbryum_version": lbryum_version,
"ui_version": "not loaded yet",
"build": build_type.BUILD, # travis sets this during build step
}
try:
p['ip'] = json.load(urlopen('http://jsonip.com'))['ip']
except:
p['ip'] = "Could not determine IP"
if get_ip:
try:
p['ip'] = json.load(urlopen('http://jsonip.com'))['ip']
except:
p['ip'] = "Could not determine IP"
return p

View file

@ -4,16 +4,15 @@ import logging
import random
import socket
import string
import json
import pkg_resources
from lbrynet.core.cryptoutils import get_lbry_hash_obj
# digest_size is in bytes, and blob hashes are hex encoded
blobhash_length = get_lbry_hash_obj().digest_size * 2
log = logging.getLogger(__name__)
@ -114,3 +113,7 @@ def get_sd_hash(stream_info):
if not stream_info:
return None
return stream_info['sources']['lbry_sd_hash']
def json_dumps_pretty(obj, **kwargs):
return json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': '), **kwargs)

View file

@ -6,7 +6,7 @@ import re
import base58
import requests
import urllib
import simplejson as json
import json
from requests import exceptions as requests_exceptions
import random
@ -36,8 +36,7 @@ from lbrynet.lbrynet_daemon.Publisher import Publisher
from lbrynet.lbrynet_daemon.ExchangeRateManager import ExchangeRateManager
from lbrynet.lbrynet_daemon.auth.server import AuthJSONRPCServer
from lbrynet.core.PaymentRateManager import OnlyFreePaymentsManager
from lbrynet.core import log_support, utils
from lbrynet.core import system_info
from lbrynet.core import log_support, utils, system_info
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob
from lbrynet.core.Session import Session
from lbrynet.core.Wallet import LBRYumWallet, SqliteStorage, ClaimOutpoint
@ -142,14 +141,14 @@ class CheckInternetConnection(object):
class CheckRemoteVersion(object):
URL = 'https://api.github.com/repos/lbryio/lbry-electron/releases/latest'
URL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest'
def __init__(self):
self.version = None
def __call__(self):
d = threads.deferToThread(self._get_lbry_electron_client_version)
d.addErrback(self._trap_and_log_error, 'lbry-electron')
d.addErrback(self._trap_and_log_error, 'lbry-app')
d.addErrback(log.fail(), 'Failure checking versions on github')
def _trap_and_log_error(self, err, module_checked):
@ -159,8 +158,7 @@ class CheckRemoteVersion(object):
log.warning("Failed to check latest %s version from github", module_checked)
def _get_lbry_electron_client_version(self):
# We'll need to ensure the lbry-electron version is in sync
# with the lbrynet-daemon version
# We'll need to ensure the lbry-app version is in sync with the lbrynet-daemon version
self._set_data_from_github()
log.info(
"remote lbrynet %s > local lbrynet %s = %s",
@ -180,7 +178,8 @@ class CheckRemoteVersion(object):
release = response.json()
return release
def _get_version_from_release(self, release):
@staticmethod
def _get_version_from_release(release):
"""Return the latest released version from github."""
tag = release['tag_name']
return get_version_from_tag(tag)
@ -1228,19 +1227,10 @@ class Daemon(AuthJSONRPCServer):
"""
platform_info = self._get_platform()
msg = {
'platform': platform_info['platform'],
'os_release': platform_info['os_release'],
'os_system': platform_info['os_system'],
'lbrynet_version': LBRYNET_VERSION,
'lbryum_version': LBRYUM_VERSION,
'ui_version': platform_info['ui_version'],
'remote_lbrynet': self._remote_version.version,
'lbrynet_update_available': self._remote_version.is_update_available(),
}
log.info("Get version info: " + json.dumps(msg))
return self._render_response(msg)
platform_info['remote_lbrynet'] = self._remote_version.version
platform_info['lbrynet_update_available'] = self._remote_version.is_update_available()
log.info("Get version info: " + json.dumps(platform_info))
return self._render_response(platform_info)
def jsonrpc_report_bug(self, message=None):
"""

View file

@ -4,6 +4,7 @@ import os
import sys
from lbrynet import conf
from lbrynet.core import utils
from lbrynet.lbrynet_daemon.auth.client import JSONRPCException, LBRYAPIClient
from lbrynet.lbrynet_daemon.Daemon import LOADING_WALLET_CODE
from jsonrpc.common import RPCError
@ -75,7 +76,7 @@ def main():
# printing the undumped string is prettier
print result
else:
print json.dumps(result, sort_keys=True, indent=2, separators=(',', ': '))
print utils.json_dumps_pretty(result)
except (RPCError, KeyError, JSONRPCException) as err:
# TODO: The api should return proper error codes
# and messages so that they can be passed along to the user

View file

@ -8,7 +8,7 @@ from jsonrpc.proxy import JSONRPCProxy
from lbrynet import analytics
from lbrynet import conf
from lbrynet.core import utils
from lbrynet.core import utils, system_info
from lbrynet.lbrynet_daemon.auth.client import LBRYAPIClient
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
@ -34,29 +34,49 @@ def start():
conf.initialize_settings()
parser = argparse.ArgumentParser(description="Launch lbrynet-daemon")
parser.add_argument("--wallet",
help="lbryum or ptc for testing, default lbryum",
type=str,
default=conf.settings['wallet'])
parser.add_argument("--ui", help="path to custom UI folder", default=None)
parser.add_argument(
"--wallet",
help="lbryum or ptc for testing, default lbryum",
type=str,
default=conf.settings['wallet']
)
parser.add_argument(
"--ui", help="path to custom UI folder", default=None
)
parser.add_argument(
"--branch",
help='Branch of lbry-web-ui repo to use, defaults to {}'.format(conf.settings['ui_branch']),
default=conf.settings['ui_branch'])
parser.add_argument('--launch-ui', dest='launchui', action="store_true")
parser.add_argument("--http-auth", dest="useauth", action="store_true",
default=conf.settings['use_auth_http'])
default=conf.settings['ui_branch']
)
parser.add_argument(
'--launch-ui', dest='launchui', action="store_true"
)
parser.add_argument(
"--http-auth", dest="useauth", action="store_true", default=conf.settings['use_auth_http']
)
parser.add_argument(
'--quiet', dest='quiet', action="store_true",
help='Disable all console output.')
help='Disable all console output.'
)
parser.add_argument(
'--verbose', nargs="*",
help=('Enable debug output. Optionally specify loggers for which debug output '
'should selectively be applied.'))
'should selectively be applied.')
)
parser.add_argument(
'--version', action="store_true",
help='Show daemon version and quit'
)
args = parser.parse_args()
update_settings_from_args(args)
if args.version:
version = system_info.get_platform(get_ip=False)
version['installation_id'] = conf.settings.installation_id
print utils.json_dumps_pretty(version)
return
lbrynet_log = conf.settings.get_log_filename()
log_support.configure_logging(lbrynet_log, not args.quiet, args.verbose)
log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())

View file

@ -21,7 +21,6 @@ requests==2.9.1
requests_futures==0.9.7
seccure==0.3.1.3
service_identity==16.0.0
simplejson==3.8.2
six>=1.9.0
slowaes==0.1a1
txJSON-RPC==0.5

View file

@ -26,7 +26,6 @@ requires = [
'requests',
'requests_futures',
'seccure',
'simplejson',
'txJSON-RPC',
'zope.interface',
]