From a31c82a8787d01ab2108d28e5d2e58bad6caaa7e Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Tue, 31 Oct 2023 11:17:56 +0530 Subject: [PATCH] added network check utility --- retriever/lib/rdatasets.py | 3 +++ retriever/lib/scripts.py | 3 +++ retriever/lib/tools.py | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/retriever/lib/rdatasets.py b/retriever/lib/rdatasets.py index 1f0002316..8aba29dff 100644 --- a/retriever/lib/rdatasets.py +++ b/retriever/lib/rdatasets.py @@ -7,6 +7,7 @@ from retriever.lib.defaults import RDATASETS_URL, RDATASET_PATH, RDATASET_SCRIPT_WRITE_PATH from retriever.lib.create_scripts import create_package from retriever.lib.scripts import reload_scripts +from retriever.lib.tools import check_network def update_rdataset_catalog(test=False): @@ -14,6 +15,8 @@ def update_rdataset_catalog(test=False): if not os.path.exists(RDATASET_SCRIPT_WRITE_PATH): os.makedirs(RDATASET_SCRIPT_WRITE_PATH) + check_network() + df = pd.read_csv(RDATASETS_URL) dataset_url = {} diff --git a/retriever/lib/scripts.py b/retriever/lib/scripts.py index 5367eb5ab..55938e240 100644 --- a/retriever/lib/scripts.py +++ b/retriever/lib/scripts.py @@ -18,6 +18,8 @@ RETRIEVER_DATASETS) from retriever.lib.load_json import read_json from retriever.lib.provenance_tools import get_script_provenance +from retriever.lib.tools import check_network + global_script_list = None @@ -322,6 +324,7 @@ def get_dataset_names_upstream(keywords=None, licenses=None, repo=REPOSITORY): in the repositories. Else, the version.txt file is read and the script names are then returned. """ + check_network() if not keywords and not licenses: version_file_request = get_data_upstream(repo + "version.txt") if not version_file_request: diff --git a/retriever/lib/tools.py b/retriever/lib/tools.py index 5d95294d6..dc6df3022 100644 --- a/retriever/lib/tools.py +++ b/retriever/lib/tools.py @@ -4,6 +4,7 @@ import sys import xlrd +import socket import pandas as pd from retriever.lib.defaults import ENCODING @@ -78,3 +79,10 @@ def walk_relative_path(dir_name): for dir_, _, files in os.walk(dir_name, topdown=False) for file_name in files ] + +def check_network(): + try: + socket.create_connection(("1.1.1.1", 53)) + except OSError: + print("Network Error.") + sys.exit(1) \ No newline at end of file