From 39275682d90fd246971f75e2693e767852dfc90f Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Wed, 6 Jan 2016 00:50:50 -0500 Subject: [PATCH] show the estimated cost of a download and format the download size better --- lbrynet/lbryfilemanager/LBRYFileManager.py | 1 + lbrynet/lbrynet_console/ConsoleControl.py | 3 +- lbrynet/lbrynet_console/ControlHandlers.py | 47 ++++++++++++++++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/lbrynet/lbryfilemanager/LBRYFileManager.py b/lbrynet/lbryfilemanager/LBRYFileManager.py index f89f09793..fb4cb5b80 100644 --- a/lbrynet/lbryfilemanager/LBRYFileManager.py +++ b/lbrynet/lbryfilemanager/LBRYFileManager.py @@ -36,6 +36,7 @@ class LBRYFileManager(object): self.download_directory = os.path.join(os.path.expanduser("~"), 'Downloads') else: self.download_directory = os.getcwd() + log.debug("Download directory for LBRYFileManager: %s", str(self.download_directory)) def setup(self): d = self._open_db() diff --git a/lbrynet/lbrynet_console/ConsoleControl.py b/lbrynet/lbrynet_console/ConsoleControl.py index 0477154bd..8b6552e6e 100644 --- a/lbrynet/lbrynet_console/ConsoleControl.py +++ b/lbrynet/lbrynet_console/ConsoleControl.py @@ -37,7 +37,8 @@ class ConsoleControl(basic.LineReceiver): "your balance is showing 0 when you know it shouldn't be, it\n" "is likely that the culprit is the blockchain.\n\n" "You should have received 1000 LBC the first time you ran\n" - "this program. If you did not, let us know!\n\n" + "this program. If you did not, let us know! But first give\n" + "them a couple of minutes to show up.\n\n" "Welcome to lbrynet-console!") self.sendLine("") self.sendLine("Enter a command. Try 'get wonderfullife' or 'help' to see more options.") diff --git a/lbrynet/lbrynet_console/ControlHandlers.py b/lbrynet/lbrynet_console/ControlHandlers.py index 7099cae89..2856ae135 100644 --- a/lbrynet/lbrynet_console/ControlHandlers.py +++ b/lbrynet/lbrynet_console/ControlHandlers.py @@ -554,7 +554,8 @@ class AddStream(CommandHandler): if command in self.factory_choices: self.factory = self.factory_choices[command] self._start_download() - self.console.sendLine("Downloading in the background") + self.console.sendLine("Downloading in the background. Use the command 'status'\n" + "to check the status of the download.") self.finished_deferred.callback(None) else: self._show_factory_choices() @@ -639,8 +640,26 @@ class AddStream(CommandHandler): self._show_info_and_options() return self._show_factory_choices() + def _get_estimated_cost_string(self): + estimated_cost_string = "unknown LBC" + for option, option_value in zip(self.download_options, self.options_chosen): + if option.short_description == "data payment rate": + if option_value == None: + rate = self.payment_rate_manager.get_effective_min_blob_data_payment_rate() + else: + rate = option_value + stream_size = None + for field, val in self.metadata.validator.info_to_show(): + if field == "stream_size": + stream_size = int(val) + if stream_size is not None and rate is not None: + estimated_cost_string = str(stream_size * 1.0 / 2**20 * rate) + " LBC" + return estimated_cost_string + def _show_factory_choices(self): prompt = "\n" + prompt += "Estimated cost: " + self._get_estimated_cost_string() + prompt += "\n\n" for factory_choice_string in self.factory_choice_strings: prompt += factory_choice_string[1] + '\n' self.console.sendLine(str(prompt)) @@ -649,13 +668,35 @@ class AddStream(CommandHandler): #self.download_options = self.metadata.options.get_downloader_options(self.metadata.validator, # self.payment_rate_manager) prompt = "Stream info:\n" - for info_line in self._get_info_to_show(): - prompt += info_line[0] + ": " + info_line[1] + "\n" + for field_name, value in self._get_info_to_show(): + if field_name == "stream_size": + value = str(self._get_formatted_stream_size(int(value))) + prompt += field_name + ": " + value + "\n" prompt += "\nOptions:\n" for option in self.download_options: prompt += option.long_description + ": " + str(option.default_value_description) + "\n" self.console.sendLine(str(prompt)) + @staticmethod + def _get_formatted_stream_size(stream_size): + if isinstance(stream_size, (int, long)): + if stream_size >= 2**40: + units = "TB" + factor = 2**40 + elif stream_size >= 2**30: + units = "GB" + factor = 2**30 + elif stream_size >= 2**20: + units = "MB" + factor = 2**20 + elif stream_size >= 2**10: + units = "KB" + factor = 2**10 + else: + return str(stream_size) + " B" + return "%.1f %s" % (round((stream_size * 1.0 / factor), 1), units) + return stream_size + def _get_info_to_show(self): return self.metadata.validator.info_to_show()