From e91450e95214412ce915014da27a2d230ebf1f27 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Sat, 17 Feb 2024 16:03:19 +0000 Subject: [PATCH] Fix download actions --- src/sos/actions.py | 17 ++++++++++++++--- src/sos/functions.py | 17 +---------------- test/test_task.py | 2 -- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/sos/actions.py b/src/sos/actions.py index cc1ee2abe..21507e50c 100644 --- a/src/sos/actions.py +++ b/src/sos/actions.py @@ -2,29 +2,38 @@ # # Copyright (c) Bo Peng and the University of Texas MD Anderson Cancer Center # Distributed under the terms of the 3-clause BSD License. - import copy +import gzip import os import shlex import shutil import subprocess import sys +import tarfile import tempfile import textwrap import time +import urllib +import urllib.error +import urllib.parse +import urllib.request import uuid +import zipfile from collections.abc import Sequence +from concurrent.futures import ProcessPoolExecutor from functools import wraps from typing import Any, Callable, Dict, List, Tuple, Union +from tqdm import tqdm as ProgressBar + from .controller import send_message_to_controller from .eval import interpolate from .messages import decode_msg, encode_msg from .parser import SoS_Script from .syntax import SOS_ACTION_OPTIONS from .targets import executable, file_target, path, paths, sos_targets -from .utils import (TimeoutInterProcessLock, env, load_config_files, - short_repr, textMD5, transcribe) +from .utils import (TimeoutInterProcessLock, env, fileMD5, get_traceback, + load_config_files, short_repr, textMD5, transcribe) __all__ = [ "SoS_Action", @@ -758,6 +767,7 @@ def script(script, interpreter="", suffix="", args="", entrypoint="", **kwargs): # download file with progress bar # + def downloadURL(URL, dest, decompress=False, index=None): dest = os.path.abspath(os.path.expanduser(dest)) dest_dir, filename = os.path.split(dest) @@ -953,6 +963,7 @@ def downloadURL(URL, dest, decompress=False, index=None): os.remove(dest_tmp) return os.path.isfile(dest) + @SoS_Action(acceptable_args=["URLs", "workdir", "dest_dir", "dest_file", "decompress", "max_jobs"]) def download(URLs, dest_dir=".", dest_file=None, decompress=False, max_jobs=5): """Download files from specified URL, which should be space, tab or diff --git a/src/sos/functions.py b/src/sos/functions.py index 8fb328861..6eba89bd9 100644 --- a/src/sos/functions.py +++ b/src/sos/functions.py @@ -1,21 +1,7 @@ -import gzip -import tarfile -import urllib -import urllib.error -import urllib.parse -import urllib.request -import zipfile -from concurrent.futures import ProcessPoolExecutor - -import pkg_resources -from tqdm import tqdm as ProgressBar - -from .utils import (StopInputGroup, TerminateExecution, env, fileMD5, - get_traceback) +from .utils import (StopInputGroup, TerminateExecution, env) # g_action_map = {} - # def _load_actions(): # global g_action_map # pylint: disable=global-variable-not-assigned # for _entrypoint in pkg_resources.iter_entry_points(group="sos_actions"): @@ -31,7 +17,6 @@ # # look for sos version requirement # get_logger().warning(f"Failed to load script running action {_entrypoint.name}: {e}") - # def sos_run_script(action, script, *args, **kwargs): # '''Call script-execution actions.''' # if not g_action_map: diff --git a/test/test_task.py b/test/test_task.py index 3a147ca21..0a69396ca 100644 --- a/test/test_task.py +++ b/test/test_task.py @@ -2,7 +2,6 @@ # # Copyright (c) Bo Peng and the University of Texas MD Anderson Cancer Center # Distributed under the terms of the 3-clause BSD License. - import os import shutil import subprocess @@ -841,7 +840,6 @@ def test_remote_output(clear_now_and_after): assert res.read() == "100" - def test_runtime_max_walltime(): """Test server max_walltime option""" # only warning messages will be yielded