From e7cf9b6532f1d4b877180e7a9165b50a5a1fd565 Mon Sep 17 00:00:00 2001 From: Mark Voschezang Date: Sun, 18 Jun 2023 11:13:51 +0200 Subject: [PATCH] minor --- src/examples/rest_client_implicit.py | 6 +++++- src/mash/filesystem/discoverable.py | 1 - src/mash/filesystem/filesystem.py | 3 +++ src/mash/shell/grammer/parse_functions.py | 7 +++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/examples/rest_client_implicit.py b/src/examples/rest_client_implicit.py index 499e5f4..5baa52d 100755 --- a/src/examples/rest_client_implicit.py +++ b/src/examples/rest_client_implicit.py @@ -7,6 +7,7 @@ from json import JSONDecodeError, loads from urllib.parse import quote_plus, urlparse from examples.rest_client_explicit import init_client +from mash.io_util import log from mash.shell import ShellWithFileSystem from mash.shell.shell import main @@ -52,11 +53,14 @@ def get(url): # query a mock server data = init_client().get(urlparse(url).path) + if data.status_code != 200: + return f'{data._status} ({data.status_code})' try: data = loads(data.data) except JSONDecodeError as e: - print(e) + log('JSONDecodeError:', e, data.data) + return f'"{data.data.decode()}"' if isinstance(data, list): return {k: http_resource for k in data} diff --git a/src/mash/filesystem/discoverable.py b/src/mash/filesystem/discoverable.py index 658928e..b91e145 100644 --- a/src/mash/filesystem/discoverable.py +++ b/src/mash/filesystem/discoverable.py @@ -60,7 +60,6 @@ def snapshot(self, filename=default_snapshot_filename) -> bytes: f.write(dumps((self.root, self.initial_values, self.home))) def load(self, filename=default_snapshot_filename): - print('load', filename) with open(filename, 'rb') as f: root, self.initial_values, home = loads(f.read()) diff --git a/src/mash/filesystem/filesystem.py b/src/mash/filesystem/filesystem.py index 81f158b..53b6fce 100644 --- a/src/mash/filesystem/filesystem.py +++ b/src/mash/filesystem/filesystem.py @@ -219,6 +219,9 @@ def set(self, k, value: Data, cwd: View = None): self.cd('-') self.cd(*path) + def show(self, *path: str): + return self.get(path) + def append(self, k, v): """Associate key k with value v and then change the working directory to k """ diff --git a/src/mash/shell/grammer/parse_functions.py b/src/mash/shell/grammer/parse_functions.py index 41cc6f3..60afdf4 100644 --- a/src/mash/shell/grammer/parse_functions.py +++ b/src/mash/shell/grammer/parse_functions.py @@ -96,6 +96,13 @@ def to_string(value: Any) -> str: elif isinstance(value, dict): result = {} + if isinstance(next(iter(value.values())), dict): + try: + table = pd.DataFrame(value) + return table.T.to_markdown() + except ValueError: + pass + for k, v in value.items(): if isinstance(v, dict): result[k] = dict_to_string(v)