This is an automated email from the ASF dual-hosted git repository. dimuthuupe pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/airavata-mft.git
commit 3534959886e61b4c71518f0feac1630ed9b8621c Author: impiyush83 <[email protected]> AuthorDate: Sat Apr 15 07:02:58 2023 -0400 #94 Utility exception handler --- python-cli/mft_cli/airavata_mft_cli/base.py | 13 +++++------ .../mft_cli/airavata_mft_cli/storage/__init__.py | 12 +++++----- python-cli/mft_cli/airavata_mft_cli/util.py | 26 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/python-cli/mft_cli/airavata_mft_cli/base.py b/python-cli/mft_cli/airavata_mft_cli/base.py index 92d28bd..1d1e2d3 100644 --- a/python-cli/mft_cli/airavata_mft_cli/base.py +++ b/python-cli/mft_cli/airavata_mft_cli/base.py @@ -19,8 +19,7 @@ import typer import airavata_mft_cli.operations as operations import airavata_mft_cli.bootstrap as bootstrap -import grpc -from rich import print +from airavata_mft_cli.util import exception_handler app = typer.Typer() @@ -28,17 +27,15 @@ app = typer.Typer() def list(storage_path): try: operations.list(storage_path) - except grpc.RpcError as rpc_error: - if rpc_error.code() == grpc.StatusCode.UNAVAILABLE: - print(f'Could not list resources for your storage path {storage_path} due to MFT server unavailable') + except Exception as e: + exception_handler(e) @app.command("cp") def copy(source, destination): try: operations.copy(source, destination) - except grpc.RpcError as rpc_error: - if rpc_error.code() == grpc.StatusCode.UNAVAILABLE: - print(f'Could not copy resources from source = {source} to destination = {destination} due to MFT server unavailable') + except Exception as e: + exception_handler(e) @app.command("init") def init_mft(): diff --git a/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py b/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py index cb6b8b6..d461682 100644 --- a/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py +++ b/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py @@ -30,9 +30,9 @@ from rich.console import Console from rich.table import Table from rich import print import sys -import grpc sys.path.append('../airavata_mft_cli') from airavata_mft_cli import config as configcli +from airavata_mft_cli.util import exception_handler app = typer.Typer() @@ -54,9 +54,8 @@ def add_storage(): swift.handle_add_storage() elif option == "SCP": scp.handle_add_storage() - except grpc.RpcError as rpc_error: - if rpc_error.code() == grpc.StatusCode.UNAVAILABLE: - print(f'Could not add storage in {option} due to MFT server grpc unavailable error') + except Exception as e: + exception_handler(e) @app.command("list") def list_storage(): @@ -85,6 +84,5 @@ def list_storage(): storage.storageId) console.print(table) - except grpc.RpcError as rpc_error: - if rpc_error.code() == grpc.StatusCode.UNAVAILABLE: - print('Could not fetch storage list due to MFT server grpc unavailable error') + except Exception as e: + exception_handler(e) \ No newline at end of file diff --git a/python-cli/mft_cli/airavata_mft_cli/util.py b/python-cli/mft_cli/airavata_mft_cli/util.py new file mode 100644 index 0000000..186a6b5 --- /dev/null +++ b/python-cli/mft_cli/airavata_mft_cli/util.py @@ -0,0 +1,26 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from rich import print +import grpc + +def exception_handler(e): + if isinstance(e, grpc.RpcError): + if e.code() == grpc.StatusCode.UNAVAILABLE: + print(f"MFT server is unavailable")
