Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to check internet access before network calls #1672

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions retriever/lib/rdatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
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):
'''Updates the datasets_url.json from the github repo'''
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 = {}

Expand Down
3 changes: 3 additions & 0 deletions retriever/lib/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions retriever/lib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys

import xlrd
import socket
import pandas as pd

from retriever.lib.defaults import ENCODING
Expand Down Expand Up @@ -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)