Show download progress in terms of percent, console startup errors now cause the application to abort, and a friendlier error is shown when no lbrycrd server is running

This commit is contained in:
Jimmy Kiselak 2015-08-31 22:05:50 -04:00
parent c14efc843c
commit 1bf0065d9d
6 changed files with 79 additions and 42 deletions

View file

@ -52,8 +52,7 @@ class LBRYcrdWallet(object):
def make_connection(): def make_connection():
if self.start_lbrycrdd is True: if self.start_lbrycrdd is True:
self._start_daemon() self._start_daemon()
logging.info("Trying to connect to %s", self.rpc_conn_string) self._get_info()
self.rpc_conn = AuthServiceProxy(self.rpc_conn_string)
logging.info("Connected!") logging.info("Connected!")
def start_manage(): def start_manage():
@ -66,6 +65,10 @@ class LBRYcrdWallet(object):
return d return d
def stop(self): def stop(self):
def log_stop_error(err):
logging.error("An error occurred stopping the wallet. %s", err.getTraceback())
self.stopped = True self.stopped = True
# If self.next_manage_call is None, then manage is currently running or else # If self.next_manage_call is None, then manage is currently running or else
# start has not been called, so set stopped and do nothing else. # start has not been called, so set stopped and do nothing else.
@ -74,8 +77,10 @@ class LBRYcrdWallet(object):
self.next_manage_call = None self.next_manage_call = None
d = self.manage() d = self.manage()
d.addErrback(log_stop_error)
if self.start_lbrycrdd is True: if self.start_lbrycrdd is True:
d.addBoth(lambda _: self._stop_daemon()) d.addCallback(lambda _: self._stop_daemon())
d.addErrback(log_stop_error)
return d return d
def manage(self): def manage(self):
@ -248,6 +253,18 @@ class LBRYcrdWallet(object):
def get_new_address(self): def get_new_address(self):
return threads.deferToThread(self._get_new_address) return threads.deferToThread(self._get_new_address)
def _get_rpc_conn(self):
return AuthServiceProxy(self.rpc_conn_string)
def _catch_connection_error(f):
def w(*args):
try:
return f(*args)
except socket.error:
raise ValueError("Unable to connect to an lbrycrd server. Make sure an lbrycrd server " +
"is running and that this application can connect to it.")
return w
def _start_daemon(self): def _start_daemon(self):
if os.name == "nt": if os.name == "nt":
@ -264,7 +281,7 @@ class LBRYcrdWallet(object):
tries = 0 tries = 0
while tries < 5: while tries < 5:
try: try:
rpc_conn = AuthServiceProxy(self.rpc_conn_string) rpc_conn = self._get_rpc_conn()
rpc_conn.getinfo() rpc_conn.getinfo()
break break
except (socket.error, JSONRPCException): except (socket.error, JSONRPCException):
@ -329,8 +346,9 @@ class LBRYcrdWallet(object):
dl.addCallback(handle_checks) dl.addCallback(handle_checks)
return dl return dl
@_catch_connection_error
def _check_expected_balance(self, expected_balance): def _check_expected_balance(self, expected_balance):
rpc_conn = AuthServiceProxy(self.rpc_conn_string) rpc_conn = self._get_rpc_conn()
logging.info("Checking balance of address %s", str(expected_balance[1])) logging.info("Checking balance of address %s", str(expected_balance[1]))
balance = rpc_conn.getreceivedbyaddress(expected_balance[1]) balance = rpc_conn.getreceivedbyaddress(expected_balance[1])
logging.debug("received balance: %s", str(balance)) logging.debug("received balance: %s", str(balance))
@ -341,7 +359,7 @@ class LBRYcrdWallet(object):
logging.info("Trying to send payments, if there are any to be sent") logging.info("Trying to send payments, if there are any to be sent")
def do_send(payments): def do_send(payments):
rpc_conn = AuthServiceProxy(self.rpc_conn_string) rpc_conn = self._get_rpc_conn()
rpc_conn.sendmany("", payments) rpc_conn.sendmany("", payments)
payments_to_send = {} payments_to_send = {}
@ -357,24 +375,34 @@ class LBRYcrdWallet(object):
logging.info("There were no payments to send") logging.info("There were no payments to send")
return defer.succeed(True) return defer.succeed(True)
@_catch_connection_error
def _get_info(self):
rpc_conn = self._get_rpc_conn()
return rpc_conn.getinfo()
@_catch_connection_error
def _get_wallet_balance(self): def _get_wallet_balance(self):
rpc_conn = AuthServiceProxy(self.rpc_conn_string) rpc_conn = self._get_rpc_conn()
return rpc_conn.getbalance("") return rpc_conn.getbalance("")
@_catch_connection_error
def _get_new_address(self): def _get_new_address(self):
rpc_conn = AuthServiceProxy(self.rpc_conn_string) rpc_conn = self._get_rpc_conn()
return rpc_conn.getnewaddress() return rpc_conn.getnewaddress()
@_catch_connection_error
def _get_value_for_name(self, name): def _get_value_for_name(self, name):
rpc_conn = AuthServiceProxy(self.rpc_conn_string) rpc_conn = self._get_rpc_conn()
return rpc_conn.getvalueforname(name) return rpc_conn.getvalueforname(name)
@_catch_connection_error
def _claim_name(self, name, value, amount): def _claim_name(self, name, value, amount):
rpc_conn = AuthServiceProxy(self.rpc_conn_string) rpc_conn = self._get_rpc_conn()
return str(rpc_conn.claimname(name, value, amount)) return str(rpc_conn.claimname(name, value, amount))
@_catch_connection_error
def _rpc_stop(self): def _rpc_stop(self):
rpc_conn = AuthServiceProxy(self.rpc_conn_string) rpc_conn = self._get_rpc_conn()
rpc_conn.stop() rpc_conn.stop()
self.lbrycrdd.wait() self.lbrycrdd.wait()

View file

@ -230,7 +230,11 @@ class LBRYSession(object):
self.rate_limiter.tick() self.rate_limiter.tick()
d1 = self.blob_manager.setup() d1 = self.blob_manager.setup()
d2 = self.wallet.start() d2 = self.wallet.start()
return defer.DeferredList([d1, d2], fireOnOneErrback=True)
dl = defer.DeferredList([d1, d2], fireOnOneErrback=True, consumeErrors=True)
dl.addErrback(lambda err: err.value.subFailure)
return dl
def _unset_upnp(self): def _unset_upnp(self):

View file

@ -27,7 +27,7 @@ class ConsoleControl(basic.LineReceiver):
self.sendLine(response) self.sendLine(response)
def show_error(err): def show_error(err):
self.sendLine(err.getTraceback()) self.sendLine(err.getErrorMessage())
if self.current_handler is None: if self.current_handler is None:
try: try:

View file

@ -86,8 +86,13 @@ class LBRYConsole():
d.addCallback(lambda _: self._load_plugins()) d.addCallback(lambda _: self._load_plugins())
d.addCallback(lambda _: self._setup_server()) d.addCallback(lambda _: self._setup_server())
d.addCallback(lambda _: self._start_controller()) d.addCallback(lambda _: self._start_controller())
d.addErrback(self._show_start_error)
return d return d
def _show_start_error(self, error):
print error.getErrorMessage()
return error
def shut_down(self): def shut_down(self):
"""Stop the session, all currently running streams, and stop the server""" """Stop the session, all currently running streams, and stop the server"""
d = self.session.shut_down() d = self.session.shut_down()
@ -348,10 +353,13 @@ class LBRYConsole():
def _shut_down(self): def _shut_down(self):
self.plugin_manager = None self.plugin_manager = None
d1 = self.lbry_file_metadata_manager.stop() ds = []
d1.addCallback(lambda _: self.lbry_file_manager.stop()) if self.lbry_file_metadata_manager is not None:
d2 = self.stop_server() d = self.lbry_file_metadata_manager.stop()
dl = defer.DeferredList([d1, d2]) d.addCallback(lambda _: self.lbry_file_manager.stop())
ds.append(d)
ds.append(self.stop_server())
dl = defer.DeferredList(ds)
return dl return dl
@ -451,5 +459,8 @@ def launch_lbry_console():
conf_dir=conf_dir, data_dir=data_dir) conf_dir=conf_dir, data_dir=data_dir)
d = task.deferLater(reactor, 0, console.start) d = task.deferLater(reactor, 0, console.start)
d.addErrback(lambda _: reactor.stop())
reactor.addSystemEventTrigger('before', 'shutdown', console.shut_down) reactor.addSystemEventTrigger('before', 'shutdown', console.shut_down)
reactor.run() reactor.run()

View file

@ -381,11 +381,10 @@ class LBRYDownloader(object):
def show_stream_status(downloader): def show_stream_status(downloader):
total_bytes = downloader.get_total_bytes() total_bytes = downloader.get_total_bytes()
bytes_left_to_download = downloader.get_bytes_left_to_download() bytes_left_to_download = downloader.get_bytes_left_to_download()
bytes_left_to_output = downloader.get_bytes_left_to_output()
points_paid = payment_rate_manager.points_paid points_paid = payment_rate_manager.points_paid
payment_rate = payment_rate_manager.get_effective_min_blob_data_payment_rate() payment_rate = payment_rate_manager.get_effective_min_blob_data_payment_rate()
points_remaining = 1.0 * bytes_left_to_download * payment_rate / 2**20 points_remaining = 1.0 * bytes_left_to_download * payment_rate / 2**20
stream_frame.show_progress(total_bytes, bytes_left_to_download, bytes_left_to_output, stream_frame.show_progress(total_bytes, bytes_left_to_download,
points_paid, points_remaining) points_paid, points_remaining)
def show_finished(arg, downloader): def show_finished(arg, downloader):

View file

@ -99,7 +99,6 @@ class StreamFrame(object):
self.status_label = None self.status_label = None
self.name_label = None self.name_label = None
self.bytes_downloaded_label = None self.bytes_downloaded_label = None
self.bytes_outputted_label = None
self.button_frame = None self.button_frame = None
self.download_buttons = [] self.download_buttons = []
self.option_frames = [] self.option_frames = []
@ -111,6 +110,7 @@ class StreamFrame(object):
self.remaining_cost_description = None self.remaining_cost_description = None
self.cost_label = None self.cost_label = None
self.remaining_cost_label = None self.remaining_cost_label = None
self.progress_frame = None
def cancel(self): def cancel(self):
if self.cancel_func is not None: if self.cancel_func is not None:
@ -344,9 +344,9 @@ class StreamFrame(object):
self.show_options_button.config(image=self.hide_options_picture) self.show_options_button.config(image=self.hide_options_picture)
self.options_frame.grid(sticky=tk.W + tk.E, row=3) self.options_frame.grid(sticky=tk.W + tk.E, row=3)
def show_progress(self, total_bytes, bytes_left_to_download, bytes_left_to_output, points_paid, def show_progress(self, total_bytes, bytes_left_to_download, points_paid,
points_remaining): points_remaining):
if self.bytes_outputted_label is None: if self.bytes_downloaded_label is None:
self.remove_download_buttons() self.remove_download_buttons()
self.button_frame.destroy() self.button_frame.destroy()
for option, frame in self.option_frames: for option, frame in self.option_frames:
@ -354,8 +354,17 @@ class StreamFrame(object):
self.options_frame.destroy() self.options_frame.destroy()
self.show_options_button.destroy() self.show_options_button.destroy()
self.progress_frame = ttk.Frame(self.outer_button_frame, style="F.TFrame")
self.progress_frame.grid(row=0, column=0, sticky=tk.W, pady=(0, 8))
self.bytes_downloaded_label = ttk.Label(
self.progress_frame,
text=""
)
self.bytes_downloaded_label.grid(row=0, column=0)
self.cost_frame = ttk.Frame(self.outer_button_frame, style="F.TFrame") self.cost_frame = ttk.Frame(self.outer_button_frame, style="F.TFrame")
self.cost_frame.grid(row=0, column=0, sticky=tk.W+tk.N, pady=(0, 12)) self.cost_frame.grid(row=1, column=0, sticky=tk.W, pady=(0, 7))
self.cost_label = ttk.Label( self.cost_label = ttk.Label(
self.cost_frame, self.cost_frame,
@ -365,25 +374,13 @@ class StreamFrame(object):
self.cost_label.grid(row=0, column=1, padx=(1, 0)) self.cost_label.grid(row=0, column=1, padx=(1, 0))
self.outer_button_frame.grid_columnconfigure(2, weight=0, uniform="") self.outer_button_frame.grid_columnconfigure(2, weight=0, uniform="")
self.bytes_outputted_label = ttk.Label(
self.file_name_frame,
text=""
)
self.bytes_outputted_label.grid(row=0, column=0)
self.bytes_downloaded_label = ttk.Label(
self.file_name_frame,
text=""
)
self.bytes_downloaded_label.grid(row=0, column=1)
if self.bytes_outputted_label.winfo_exists():
self.bytes_outputted_label.config(
text=self.get_formatted_stream_size(total_bytes - bytes_left_to_output) + " / "
)
if self.bytes_downloaded_label.winfo_exists(): if self.bytes_downloaded_label.winfo_exists():
percent_done = 0
if total_bytes > 0:
percent_done = 100.0 * (total_bytes - bytes_left_to_download) / total_bytes
percent_done_string = locale.format_string(" (%.2f%%)", percent_done)
self.bytes_downloaded_label.config( self.bytes_downloaded_label.config(
text=self.get_formatted_stream_size(total_bytes - bytes_left_to_download) + " / " text=self.get_formatted_stream_size(total_bytes - bytes_left_to_download) + percent_done_string
) )
if self.cost_label.winfo_exists(): if self.cost_label.winfo_exists():
total_points = points_remaining + points_paid total_points = points_remaining + points_paid
@ -392,8 +389,6 @@ class StreamFrame(object):
grouping=True)) grouping=True))
def show_download_done(self, total_points_paid): def show_download_done(self, total_points_paid):
if self.bytes_outputted_label is not None and self.bytes_outputted_label.winfo_exists():
self.bytes_outputted_label.destroy()
if self.bytes_downloaded_label is not None and self.bytes_downloaded_label.winfo_exists(): if self.bytes_downloaded_label is not None and self.bytes_downloaded_label.winfo_exists():
self.bytes_downloaded_label.destroy() self.bytes_downloaded_label.destroy()
if self.cost_label is not None and self.cost_label.winfo_exists(): if self.cost_label is not None and self.cost_label.winfo_exists():