From 4c1a9b1dd7f0f8ebb08b9d719d4d1494a3f91362 Mon Sep 17 00:00:00 2001 From: Victor Grau Serrat Date: Mon, 5 Feb 2018 22:58:40 -0700 Subject: [PATCH] BLD: marketplace added listing of datasets --- catalyst/__main__.py | 1 - catalyst/marketplace/marketplace.py | 57 +++++++++--------------- catalyst/marketplace/utils/path_utils.py | 3 -- 3 files changed, 21 insertions(+), 40 deletions(-) diff --git a/catalyst/__main__.py b/catalyst/__main__.py index 3833f3e4..ecbe7c23 100644 --- a/catalyst/__main__.py +++ b/catalyst/__main__.py @@ -756,7 +756,6 @@ def ls(ctx): sys.stdout) marketplace = Marketplace() marketplace.list() - click.echo('Functionality not yet implemented.', sys.stdout) @marketplace.command() diff --git a/catalyst/marketplace/marketplace.py b/catalyst/marketplace/marketplace.py index 363171c1..a5e7d4f5 100644 --- a/catalyst/marketplace/marketplace.py +++ b/catalyst/marketplace/marketplace.py @@ -1,6 +1,4 @@ import glob -import hashlib -import hmac import json import os import re @@ -144,14 +142,14 @@ class Marketplace: 'Gas Limit:\t\t{gas}\n' 'Nonce:\t\t\t{nonce}\n' 'Data:\t\t\t{data}\n'.format( - _from=from_address, - to=tx['to'], - value=tx['value'], - gas=tx['gas'], - nonce=tx['nonce'], - data=tx['data'], - ) - ) + _from=from_address, + to=tx['to'], + value=tx['value'], + gas=tx['gas'], + nonce=tx['nonce'], + data=tx['data'], + ) + ) signed_tx = input('Copy and Paste the "Signed Transaction" ' 'field here:\n') @@ -182,35 +180,21 @@ class Marketplace: return ds def list(self): - subscribers = self.contract.call( - {'from': self.default_account} - ).getSubscribers() - subscribed = [] - for index, address in enumerate(subscribers): - if address == self.default_account: - subscribed.append(index) - - data_sources = self.get_data_sources_map() + data_sources = self.mkt_contract.functions.getAllProviders().call() data = [] for index, data_source in enumerate(data_sources): - data.append( - dict( - id=index, - subscribed=index in subscribed, - **data_source + if index > 0: + data.append( + dict( + dataset=data_source.decode('utf-8').rstrip('\0') + ) ) - ) df = pd.DataFrame(data) - df.set_index(['id', 'name', 'desc'], drop=True, inplace=True) set_print_settings() - - formatters = dict( - subscribed=lambda s: u'\u2713' if s else '', - ) - print(df.to_string(formatters=formatters)) + print(df) def subscribe(self, dataset): dataset = dataset.lower() @@ -258,7 +242,7 @@ class Marketplace: agree_pay = input('Please confirm that you agree to pay {} ENG ' 'for a monthly subscription to the dataset "{}" ' 'starting today. [default: Y] '.format( - price, dataset)) or 'y' + price, dataset)) or 'y' if agree_pay.lower() not in ('y', 'n'): print("Please answer Y or N.") else: @@ -366,7 +350,7 @@ class Marketplace: 'You can now ingest this dataset anytime during the ' 'next month by running the following command:\n' 'catalyst marketplace ingest --dataset={}'.format( - dataset, address, dataset)) + dataset, address, dataset)) def process_temp_bundle(self, ds_name, path): """ @@ -449,9 +433,10 @@ class Marketplace: filename = os.path.join(target_path, name) with open(filename, 'wb') as f: - # for chunk in part.content.iter_content(chunk_size=1024): - # if chunk: # filter out keep-alive new chunks - # f.write(chunk) + # for chunk in part.content.iter_content( + # chunk_size=1024): + # if chunk: # filter out keep-alive new chunks + # f.write(chunk) f.write(part.content) self.process_temp_bundle(ds_name, filename) diff --git a/catalyst/marketplace/utils/path_utils.py b/catalyst/marketplace/utils/path_utils.py index 4bbf2854..6565b49d 100644 --- a/catalyst/marketplace/utils/path_utils.py +++ b/catalyst/marketplace/utils/path_utils.py @@ -2,9 +2,6 @@ import os import json import tarfile -import shutil - -from catalyst.data.bundles.core import download_without_progress from catalyst.utils.deprecate import deprecated from catalyst.utils.paths import data_root, ensure_directory