async def start(self): blob_manager = self.component_manager.get_component(BLOB_COMPONENT) storage = self.component_manager.get_component(DATABASE_COMPONENT) wallet = self.component_manager.get_component(WALLET_COMPONENT) node = self.component_manager.get_component(DHT_COMPONENT) \ if self.component_manager.has_component(DHT_COMPONENT) else None try: torrent = self.component_manager.get_component( LIBTORRENT_COMPONENT) if TorrentSession else None except NameError: torrent = None log.info('Starting the file manager') loop = asyncio.get_event_loop() self.file_manager = FileManager( loop, self.conf, wallet, storage, self.component_manager.analytics_manager) self.file_manager.source_managers['stream'] = StreamManager( loop, self.conf, blob_manager, wallet, storage, node, ) if TorrentSession and LIBTORRENT_COMPONENT not in self.conf.components_to_skip: self.file_manager.source_managers['torrent'] = TorrentManager( loop, self.conf, torrent, storage, self.component_manager.analytics_manager) await self.file_manager.start() log.info('Done setting up file manager')
class FileManagerComponent(Component): component_name = FILE_MANAGER_COMPONENT depends_on = [BLOB_COMPONENT, DATABASE_COMPONENT, WALLET_COMPONENT] def __init__(self, component_manager): super().__init__(component_manager) self.file_manager: typing.Optional[FileManager] = None @property def component(self) -> typing.Optional[FileManager]: return self.file_manager async def get_status(self): if not self.file_manager: return return { 'managed_files': len(self.file_manager.get_filtered()), } async def start(self): blob_manager = self.component_manager.get_component(BLOB_COMPONENT) storage = self.component_manager.get_component(DATABASE_COMPONENT) wallet = self.component_manager.get_component(WALLET_COMPONENT) node = self.component_manager.get_component(DHT_COMPONENT) \ if self.component_manager.has_component(DHT_COMPONENT) else None try: torrent = self.component_manager.get_component( LIBTORRENT_COMPONENT) if TorrentSession else None except NameError: torrent = None log.info('Starting the file manager') loop = asyncio.get_event_loop() self.file_manager = FileManager( loop, self.conf, wallet, storage, self.component_manager.analytics_manager) self.file_manager.source_managers['stream'] = StreamManager( loop, self.conf, blob_manager, wallet, storage, node, ) if TorrentSession and LIBTORRENT_COMPONENT not in self.conf.components_to_skip: self.file_manager.source_managers['torrent'] = TorrentManager( loop, self.conf, torrent, storage, self.component_manager.analytics_manager) await self.file_manager.start() log.info('Done setting up file manager') async def stop(self): self.file_manager.stop()
async def setup_stream_manager(self, balance=10.0, fee=None, old_sort=False): file_path = os.path.join(self.server_dir, "test_file") with open(file_path, 'wb') as f: f.write(os.urandom(20000000)) descriptor = await StreamDescriptor.create_stream( self.loop, self.server_blob_manager.blob_dir, file_path, old_sort=old_sort) self.sd_hash = descriptor.sd_hash self.mock_wallet, self.uri = await get_mock_wallet( self.sd_hash, self.client_storage, self.client_wallet_dir, balance, fee) analytics_manager = AnalyticsManager( self.client_config, binascii.hexlify(generate_id()).decode(), binascii.hexlify(generate_id()).decode()) self.stream_manager = StreamManager( self.loop, self.client_config, self.client_blob_manager, self.mock_wallet, self.client_storage, get_mock_node(self.server_from_client), analytics_manager) self.file_manager = FileManager(self.loop, self.client_config, self.mock_wallet, self.client_storage, analytics_manager) self.file_manager.source_managers['stream'] = self.stream_manager self.exchange_rate_manager = get_fake_exchange_rate_manager()