add attributes to lbry file base classes

This commit is contained in:
Jack Robison 2017-12-29 14:09:54 -05:00
parent bc58add6de
commit 2af61460a7
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
4 changed files with 34 additions and 32 deletions

View file

@ -37,8 +37,8 @@ class CryptStreamDownloader(object):
implements(IStreamDownloader)
def __init__(self, peer_finder, rate_limiter, blob_manager,
payment_rate_manager, wallet):
def __init__(self, peer_finder, rate_limiter, blob_manager, payment_rate_manager, wallet,
key, stream_name):
"""Initialize a CryptStreamDownloader
@param peer_finder: An object which implements the IPeerFinder
@ -61,8 +61,8 @@ class CryptStreamDownloader(object):
self.blob_manager = blob_manager
self.payment_rate_manager = payment_rate_manager
self.wallet = wallet
self.key = None
self.stream_name = None
self.key = key
self.stream_name = stream_name
self.completed = False
self.stopped = True
self.stopping = False

View file

@ -34,21 +34,18 @@ class ManagedEncryptedFileDownloader(EncryptedFileSaver):
STATUS_RUNNING = "running"
STATUS_STOPPED = "stopped"
STATUS_FINISHED = "finished"
"""
These are started by EncryptedFileManager, aka, file_manager
"""
def __init__(self, rowid, stream_hash, peer_finder, rate_limiter,
blob_manager, stream_info_manager, lbry_file_manager,
payment_rate_manager, wallet, download_directory,
file_name=None):
def __init__(self, rowid, stream_hash, peer_finder, rate_limiter, blob_manager,
stream_info_manager, lbry_file_manager, payment_rate_manager, wallet,
download_directory, file_name=None, sd_hash=None, key=None, stream_name=None,
suggested_file_name=None):
EncryptedFileSaver.__init__(self, stream_hash, peer_finder,
rate_limiter, blob_manager,
stream_info_manager,
payment_rate_manager, wallet,
download_directory,
file_name)
file_name, key, stream_name, suggested_file_name)
self.sd_hash = sd_hash
self.rowid = rowid
self.lbry_file_manager = lbry_file_manager
self._saving_status = False

View file

@ -22,12 +22,13 @@ class EncryptedFileDownloader(CryptStreamDownloader):
"""Classes which inherit from this class download LBRY files"""
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
stream_info_manager, payment_rate_manager, wallet):
stream_info_manager, payment_rate_manager, wallet, key, stream_name,
suggested_file_name=None):
CryptStreamDownloader.__init__(self, peer_finder, rate_limiter, blob_manager,
payment_rate_manager, wallet)
payment_rate_manager, wallet, key, stream_name)
self.stream_hash = stream_hash
self.stream_info_manager = stream_info_manager
self.suggested_file_name = None
self.suggested_file_name = suggested_file_name
self._calculated_total_bytes = None
self.sd_hash = None
@ -171,11 +172,11 @@ class EncryptedFileDownloaderFactory(object):
class EncryptedFileSaver(EncryptedFileDownloader):
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
payment_rate_manager, wallet, download_directory, file_name=None):
EncryptedFileDownloader.__init__(self, stream_hash,
peer_finder, rate_limiter,
blob_manager, stream_info_manager,
payment_rate_manager, wallet)
payment_rate_manager, wallet, download_directory, key, stream_name,
suggested_file_name, file_name):
EncryptedFileDownloader.__init__(self, stream_hash, peer_finder, rate_limiter,
blob_manager, stream_info_manager, payment_rate_manager,
wallet, key, stream_name, suggested_file_name)
self.download_directory = download_directory
self.file_name = file_name
self.file_written_to = None
@ -273,11 +274,15 @@ class EncryptedFileSaverFactory(EncryptedFileDownloaderFactory):
self.download_directory = download_directory
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info):
return EncryptedFileSaver(stream_hash, self.peer_finder,
self.rate_limiter, self.blob_manager,
self.stream_info_manager,
payment_rate_manager, self.wallet,
self.download_directory)
stream_name = binascii.unhexlify(stream_info.raw_info['stream_name'])
key = stream_info.raw_info['key']
suggested_file_name = binascii.unhexlify(stream_info.raw_info['suggested_file_name'])
file_name = os.path.join(self.download_directory, os.path.basename(suggested_file_name))
return EncryptedFileSaver(stream_hash, self.peer_finder, self.rate_limiter,
self.blob_manager, self.stream_info_manager,
payment_rate_manager, self.wallet, self.download_directory, key,
stream_name, suggested_file_name, file_name)
@staticmethod
def get_description():

View file

@ -21,13 +21,13 @@ class TestEncryptedFileSaver(unittest.TestCase):
payment_rate_manager = None
wallet = None
download_directory = '.'
upload_allowed = False
saver = EncryptedFileSaver(
stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
payment_rate_manager, wallet, download_directory, file_name)
key = ''
saver = EncryptedFileSaver(stream_hash, peer_finder, rate_limiter, blob_manager,
stream_info_manager, payment_rate_manager, wallet,
download_directory, key, file_name, file_name,
file_name)
yield saver._setup_output()
self.assertTrue(os.path.isfile(file_name))
saver._close_output()