Merge pull request #105 from lbryio/bug-fixes

misc bug fixes and code cleanup
This commit is contained in:
Job Evers‐Meltzer 2016-07-26 14:56:50 -05:00 committed by GitHub
commit 04d766aba7
4 changed files with 25 additions and 14 deletions

View file

@ -56,7 +56,6 @@ class LBRYWallet(object):
_FIRST_RUN_NO = 2
def __init__(self, db_dir):
self.db_dir = db_dir
self.db = None
self.next_manage_call = None
@ -631,7 +630,7 @@ class LBRYcrdWallet(LBRYWallet):
settings = {"username": "rpcuser",
"password": "rpcpassword",
"rpc_port": 9245}
if os.path.exists(self.wallet_conf):
if self.wallet_conf and os.path.exists(self.wallet_conf):
conf = open(self.wallet_conf)
for l in conf:
if l.startswith("rpcuser="):

View file

@ -198,7 +198,7 @@ class StreamDescriptorIdentifier(object):
return self._stream_downloader_factories[stream_type]
def _get_validator(self, stream_type):
if not stream_type in self._stream_downloader_factories:
if not stream_type in self._sd_info_validators:
raise UnknownStreamTypeError(stream_type)
return self._sd_info_validators[stream_type]
@ -238,4 +238,4 @@ def download_sd_blob(session, blob_hash, payment_rate_manager):
"""
downloader = StandaloneBlobDownloader(blob_hash, session.blob_manager, session.peer_finder,
session.rate_limiter, payment_rate_manager, session.wallet)
return downloader.download()
return downloader.download()

View file

@ -66,7 +66,7 @@ class DownloadManager(object):
def add_blobs_to_download(self, blob_infos):
log.debug("Adding %s to blobs", str(blob_infos))
log.debug("Adding %s blobs to blobs", len(blob_infos))
def add_blob_to_list(blob, blob_num):
self.blobs[blob_num] = blob

View file

@ -73,6 +73,7 @@ class GetStream(object):
def check_status(self):
self.timeout_counter += 1
# TODO: Why is this the stopping condition for the finished callback?
if self.download_path:
self.checker.stop()
self.finished.callback((self.stream_hash, self.download_path))
@ -108,7 +109,9 @@ class GetStream(object):
else:
pass
def _cause_timeout():
def _cause_timeout(err):
log.error(err)
log.debug('Forcing a timeout')
self.timeout_counter = self.timeout * 2
def _set_status(x, status):
@ -116,20 +119,29 @@ class GetStream(object):
self.code = next(s for s in STREAM_STAGES if s[0] == status)
return x
def get_downloader_factory(metadata):
for factory in metadata.factories:
if isinstance(factory, ManagedLBRYFileDownloaderFactory):
return factory, metadata
raise Exception('No suitable factory was found in {}'.format(metadata.factories))
def make_downloader(args):
factory, metadata = args
return factory.make_downloader(metadata,
[self.data_rate, True],
self.payment_rate_manager,
download_directory=self.download_directory,
file_name=self.file_name)
self.checker.start(1)
self.d.addCallback(lambda _: _set_status(None, DOWNLOAD_METADATA_CODE))
self.d.addCallback(lambda _: download_sd_blob(self.session, self.stream_hash, self.payment_rate_manager))
self.d.addCallback(self.sd_identifier.get_metadata_for_sd_blob)
self.d.addCallback(lambda r: _set_status(r, DOWNLOAD_RUNNING_CODE))
self.d.addCallback(lambda metadata: (next(factory for factory in metadata.factories if isinstance(factory, ManagedLBRYFileDownloaderFactory)),
metadata))
self.d.addCallback(lambda (factory, metadata): factory.make_downloader(metadata,
[self.data_rate, True],
self.payment_rate_manager,
download_directory=self.download_directory,
file_name=self.file_name))
self.d.addCallbacks(self._start_download, lambda _: _cause_timeout())
self.d.addCallback(get_downloader_factory)
self.d.addCallback(make_downloader)
self.d.addCallbacks(self._start_download, _cause_timeout)
self.d.callback(None)
return self.finished