show where the log file is, and log failure to open file better

This commit is contained in:
Jimmy Kiselak 2016-01-06 13:08:20 -05:00
parent 49869d071a
commit ec1ba02cca
2 changed files with 23 additions and 8 deletions

View file

@ -12,6 +12,11 @@ from lbrynet.lbryfile.client.LBRYFileMetadataHandler import LBRYFileMetadataHand
import os import os
from twisted.internet import defer, threads, reactor from twisted.internet import defer, threads, reactor
from twisted.python.procutils import which from twisted.python.procutils import which
import logging
import traceback
log = logging.getLogger(__name__)
class LBRYFileDownloader(CryptStreamDownloader): class LBRYFileDownloader(CryptStreamDownloader):
@ -178,7 +183,13 @@ class LBRYFileSaver(LBRYFileDownloader):
file_name + "_" + str(ext_num))): file_name + "_" + str(ext_num))):
ext_num += 1 ext_num += 1
file_name = file_name + "_" + str(ext_num) file_name = file_name + "_" + str(ext_num)
self.file_handle = open(os.path.join(self.download_directory, file_name), 'wb') try:
self.file_handle = open(os.path.join(self.download_directory, file_name), 'wb')
except IOError:
log.error(traceback.format_exc())
raise ValueError("Failed to open %s. Make sure you have permission to save files to that"
" location." % str(os.path.join(self.download_directory,
file_name)))
return threads.deferToThread(open_file) return threads.deferToThread(open_file)
def _close_output(self): def _close_output(self):

View file

@ -54,6 +54,14 @@ class InvalidValueError(Exception):
# prompt_description = None # prompt_description = None
def get_log_file():
log_file = "console.log"
logging_handlers = logging.getLogger().handlers
if len(logging_handlers):
log_file = logging_handlers[0].baseFilename
return log_file
class RoundedTime(object): class RoundedTime(object):
SECOND = 0 SECOND = 0
MINUTE = 1 MINUTE = 1
@ -611,9 +619,7 @@ class AddStream(CommandHandler):
def _handle_load_failed(self, err): def _handle_load_failed(self, err):
self.loading_failed = True self.loading_failed = True
log.error("An exception occurred attempting to load the stream descriptor: %s", err.getTraceback()) log.error("An exception occurred attempting to load the stream descriptor: %s", err.getTraceback())
log_file = "console.log" log_file = get_log_file()
if len(log.handlers):
log_file = log.handlers[0].baseFilename
self.console.sendLine("An unexpected error occurred attempting to load the stream's metadata.\n" self.console.sendLine("An unexpected error occurred attempting to load the stream's metadata.\n"
"See %s for further details.\n\n" % log_file) "See %s for further details.\n\n" % log_file)
self.finished_deferred.callback(None) self.finished_deferred.callback(None)
@ -771,10 +777,8 @@ class AddStream(CommandHandler):
d.addErrback(self._log_recent_blockchain_time_error_download) d.addErrback(self._log_recent_blockchain_time_error_download)
else: else:
log.error("An unexpected error has caused the download to stop: %s" % err.getTraceback()) log.error("An unexpected error has caused the download to stop: %s" % err.getTraceback())
log_file = "console.log" log_file = get_log_file()
if len(log.handlers): self.console.sendLine("An unexpected error has caused the download to stop:\n%s\n\nSee %s for further details." % (err.getErrorMessage(), log_file))
log_file = log.handlers[0].baseFilename
self.console.sendLine("An unexpected error has caused the download to stop. See %s for details." % log_file)
def _make_downloader(self): def _make_downloader(self):
return self.factory.make_downloader(self.metadata, self.options_chosen, return self.factory.make_downloader(self.metadata, self.options_chosen,