def main(args=None): conf.initialize_settings() parser = argparse.ArgumentParser() parser.add_argument('--limit', type=int) parser.add_argument('--download', action='store_true', help='Set flag to also download each sd_blob and report on success') args = parser.parse_args(args) log_support.configure_console() log_support.configure_twisted() # make a fresh dir or else we will include blobs that we've # already downloaded but might not otherwise be available. db_dir = tempfile.mkdtemp() try: blob_dir = os.path.join(db_dir, 'blobfiles') os.makedirs(blob_dir) storage = Wallet.InMemoryStorage() wallet = Wallet.LBRYumWallet(storage) session = Session.Session( 0, db_dir=db_dir, lbryid=utils.generate_id(), blob_dir=blob_dir, dht_node_port=4444, known_dht_nodes=conf.settings['known_dht_nodes'], peer_port=3333, use_upnp=False, wallet=wallet ) api = analytics.Api.new_instance() run(args, session, api) reactor.run() finally: shutil.rmtree(db_dir)
def setUp(self): def noop(): return None mock_conf_settings(self) util.resetTime(self) self.test_daemon = get_test_daemon() self.test_daemon.session.wallet = Wallet.LBRYumWallet(storage=Wallet.InMemoryStorage()) self.test_daemon.session.wallet.network = FakeNetwork() self.test_daemon.session.wallet.get_best_blockhash = noop
def download_it(peer, timeout, blob_hash): tmp_dir = yield threads.deferToThread(tempfile.mkdtemp) announcer = DummyHashAnnouncer() tmp_blob_manager = DiskBlobManager(announcer, tmp_dir, tmp_dir) config = {'auto_connect': True} if conf.settings['lbryum_wallet_dir']: config['lbryum_path'] = conf.settings['lbryum_wallet_dir'] storage = Wallet.InMemoryStorage() wallet = Wallet.LBRYumWallet(storage, config) downloader = SinglePeerDownloader() downloader.setup(wallet) try: blob_downloaded = yield downloader.download_blob_from_peer( peer, timeout, blob_hash, tmp_blob_manager) if blob_downloaded: log.info("SUCCESS!") blob = yield tmp_blob_manager.get_blob(blob_hash) pprint(blob) if not blob.verified: log.error("except that its not verified....") else: reader = BlobStreamDescriptorReader(blob) info = None for x in range(0, 3): try: info = yield reader.get_info() except ValueError: pass if info: break time.sleep( 0.1 ) # there's some kind of race condition where it sometimes doesnt write the blob to disk in time if info is not None: pprint(info) for content_blob in info['blobs']: if 'blob_hash' in content_blob: yield download_it(peer, timeout, content_blob['blob_hash']) else: log.error("Download failed") finally: yield tmp_blob_manager.stop() yield threads.deferToThread(shutil.rmtree, tmp_dir) defer.returnValue(True)
def main(args=None): conf.initialize_settings() parser = argparse.ArgumentParser() parser.add_argument('destination', type=conf.server_port, nargs='+') parser.add_argument('--names', nargs='*') parser.add_argument('--limit', type=int) args = parser.parse_args(args) log_support.configure_console(level='INFO') db_dir = appdirs.user_data_dir('lighthouse-uploader') safe_makedirs(db_dir) # no need to persist metadata info storage = Wallet.InMemoryStorage() wallet = Wallet.LBRYumWallet(storage) blob_dir = os.path.join(db_dir, 'blobfiles') safe_makedirs(blob_dir) # Don't set a hash_announcer, we have no need to tell anyone we # have these blobs blob_manager = BlobManager.DiskBlobManager(None, blob_dir, db_dir) # TODO: make it so that I can disable the BlobAvailabilityTracker # or, in general, make the session more reusable for users # that only want part of the functionality session = Session.Session( blob_data_payment_rate=0, db_dir=db_dir, node_id=utils.generate_id(), blob_dir=blob_dir, dht_node_port=4444, known_dht_nodes=conf.settings['known_dht_nodes'], peer_port=3333, use_upnp=False, wallet=wallet, blob_manager=blob_manager, ) assert session.wallet run(session, args.destination, args.names, args.limit) reactor.run()
def getWallet(): config = {'auto_connect': True} if conf.settings['lbryum_wallet_dir']: config['lbryum_path'] = conf.settings['lbryum_wallet_dir'] storage = Wallet.InMemoryStorage() return Wallet.LBRYumWallet(storage, config)
def setUp(self): mock_conf_settings(self) util.resetTime(self) self.test_daemon = get_test_daemon() self.test_daemon.session.wallet = Wallet.LBRYumWallet( storage=Wallet.InMemoryStorage())