Skip to content
Draft
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
14 changes: 8 additions & 6 deletions CIME/BuildTools/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
COMPILER, MPILIB, and DEBUG, respectively.
"""

from CIME.XML.standard_module_setup import *
import glob
import logging
import os
import shutil

from CIME.build import CmakeTmpBuildDir
from CIME.utils import (
copy_local_macros_to_dir,
expect,
safe_copy,
get_model,
get_src_root,
safe_copy,
stringify_bool,
copy_local_macros_to_dir,
)
from CIME.XML.env_mach_specific import EnvMachSpecific
from CIME.XML.files import Files
from CIME.build import CmakeTmpBuildDir

import shutil, glob

logger = logging.getLogger(__name__)

Expand Down
89 changes: 72 additions & 17 deletions CIME/Servers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,74 @@
# pylint: disable=import-error
"""
CIME Server implementations for data transfer.

Server availability is detected lazily on first access to avoid
running executables at import time.
"""

from functools import lru_cache
from shutil import which

has_gftp = which("globus-url-copy")
has_svn = which("svn")
has_wget = which("wget")
has_ftp = True
try:
from ftplib import FTP
except ImportError:
has_ftp = False
if has_ftp:
from CIME.Servers.ftp import FTP
if has_svn:
from CIME.Servers.svn import SVN
if has_wget:
from CIME.Servers.wget import WGET
if has_gftp:
from CIME.Servers.gftp import GridFTP

@lru_cache(maxsize=None)
def is_protocol_available(protocol: str) -> bool:
"""
Check if a protocol is available.

Args:
protocol: One of 'ftp', 'svn', 'wget', 'gftp'

Returns:
True if the protocol is available, False otherwise.
"""
protocol = protocol.lower()
if protocol == "ftp":
try:
from ftplib import FTP # noqa: F401 pylint: disable=unused-import

return True
except ImportError:
return False
elif protocol == "svn":
return which("svn") is not None
elif protocol == "wget":
return which("wget") is not None
elif protocol == "gftp":
return which("globus-url-copy") is not None
return False


def __getattr__(name: str):
"""Lazy loading of server classes and has_* attributes."""
if name == "FTP":
if is_protocol_available("ftp"):
from CIME.Servers.ftp import FTP

return FTP
raise AttributeError("FTP server not available")
elif name == "SVN":
if is_protocol_available("svn"):
from CIME.Servers.svn import SVN

return SVN
raise AttributeError("SVN server not available (svn not found)")
elif name == "WGET":
if is_protocol_available("wget"):
from CIME.Servers.wget import WGET

return WGET
raise AttributeError("WGET server not available (wget not found)")
elif name == "GridFTP":
if is_protocol_available("gftp"):
from CIME.Servers.gftp import GridFTP

return GridFTP
raise AttributeError("GridFTP server not available (globus-url-copy not found)")
elif name == "has_ftp":
return is_protocol_available("ftp")
elif name == "has_svn":
return is_protocol_available("svn")
elif name == "has_wget":
return is_protocol_available("wget")
elif name == "has_gftp":
return is_protocol_available("gftp")
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
13 changes: 9 additions & 4 deletions CIME/Servers/ftp.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
"""
FTP Server class. Interact with a server using FTP protocol
"""

# pylint: disable=super-init-not-called
from CIME.XML.standard_module_setup import *
from CIME.Servers.generic_server import GenericServer
from CIME.utils import Timeout
import logging
import os
import socket
from ftplib import FTP as FTPpy
from ftplib import all_errors as all_ftp_errors
import socket

from CIME.Servers.generic_server import GenericServer
from CIME.utils import Timeout, expect

logger = logging.getLogger(__name__)


# I think that multiple inheritence would be useful here, but I couldnt make it work
# in a py2/3 compatible way.
class FTP(GenericServer):
Expand Down
3 changes: 2 additions & 1 deletion CIME/Servers/generic_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
to make sure that specific server classes maintain a consistant argument list and functionality
so that they are interchangable objects
"""

# pylint: disable=unused-argument

from CIME.XML.standard_module_setup import *
import logging
from socket import _GLOBAL_DEFAULT_TIMEOUT

logger = logging.getLogger(__name__)
Expand Down
5 changes: 4 additions & 1 deletion CIME/Servers/gftp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""
GridFTP Server class. Interact with a server using GridFTP protocol
"""

# pylint: disable=super-init-not-called
from CIME.XML.standard_module_setup import *
import logging
import os

from CIME.Servers.generic_server import GenericServer
from CIME.utils import run_cmd

Expand Down
6 changes: 5 additions & 1 deletion CIME/Servers/svn.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""
SVN Server class. Interact with a server using SVN protocol
"""

# pylint: disable=super-init-not-called
from CIME.XML.standard_module_setup import *
import logging
import os

from CIME.Servers.generic_server import GenericServer
from CIME.utils import run_cmd

logger = logging.getLogger(__name__)

Expand Down
6 changes: 5 additions & 1 deletion CIME/Servers/wget.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""
WGET Server class. Interact with a server using WGET protocol
"""

# pylint: disable=super-init-not-called
from CIME.XML.standard_module_setup import *
import logging
import os

from CIME.Servers.generic_server import GenericServer
from CIME.utils import run_cmd

logger = logging.getLogger(__name__)

Expand Down
5 changes: 3 additions & 2 deletions CIME/SystemTests/dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

"""

import os.path
import logging
import glob
import gzip
import logging
import os.path

from CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo
from CIME.utils import expect


###############################################################################
class DAE(SystemTestsCompareTwo):
###############################################################################
Expand Down
11 changes: 7 additions & 4 deletions CIME/SystemTests/eri.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
CIME ERI test This class inherits from SystemTestsCommon
"""

from CIME.XML.standard_module_setup import *
from CIME.utils import safe_copy
from CIME.SystemTests.system_tests_common import SystemTestsCommon
import glob
import logging
import os
import shutil
from stat import S_ISDIR, ST_CTIME, ST_MODE
import shutil, glob, os

from CIME.SystemTests.system_tests_common import SystemTestsCommon
from CIME.utils import expect, safe_copy

logger = logging.getLogger(__name__)

Expand Down
5 changes: 4 additions & 1 deletion CIME/SystemTests/erio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

This class inherits from SystemTestsCommon
"""
from CIME.XML.standard_module_setup import *

import logging

from CIME.SystemTests.system_tests_common import SystemTestsCommon
from CIME.utils import expect

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion CIME/SystemTests/erp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
(2) Do a restart test with half the number of tasks and threads (suffix rest)
"""

from CIME.XML.standard_module_setup import *
import logging

from CIME.SystemTests.restart_tests import RestartTest

logger = logging.getLogger(__name__)
Expand Down
8 changes: 5 additions & 3 deletions CIME/SystemTests/err.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
ERR tests short term archiving and restart capabilities
"""

import glob, os
from CIME.XML.standard_module_setup import *
import glob
import logging
import os

from CIME.SystemTests.restart_tests import RestartTest
from CIME.utils import safe_copy, ls_sorted_by_fname
from CIME.utils import expect, ls_sorted_by_fname, safe_copy

logger = logging.getLogger(__name__)

Expand Down
9 changes: 6 additions & 3 deletions CIME/SystemTests/erri.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
ERRI tests short term archiving and restart capabilities with "incomplete" (unzipped) log files
"""

from CIME.XML.standard_module_setup import *
from CIME.SystemTests.err import ERR
import glob
import gzip
import logging
import os
import shutil

import shutil, glob, gzip
from CIME.SystemTests.err import ERR

logger = logging.getLogger(__name__)

Expand Down
8 changes: 6 additions & 2 deletions CIME/SystemTests/ers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""
CIME restart test This class inherits from SystemTestsCommon
"""
from CIME.XML.standard_module_setup import *
from CIME.SystemTests.system_tests_common import SystemTestsCommon

import glob
import logging
import os

from CIME.SystemTests.system_tests_common import SystemTestsCommon
from CIME.utils import expect

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion CIME/SystemTests/ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Exact restart from startup, default 2 month + 1 month
"""

from CIME.XML.standard_module_setup import *
import logging

from CIME.SystemTests.system_tests_common import SystemTestsCommon

logger = logging.getLogger(__name__)
Expand Down
11 changes: 7 additions & 4 deletions CIME/SystemTests/funit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
CIME FUNIT test. This class inherits from SystemTestsCommon. It runs
the fortran unit tests; grid and compset are ignored.
"""
from CIME.XML.standard_module_setup import *
from CIME.SystemTests.system_tests_common import SystemTestsCommon

import logging
import os

from CIME.build import post_build
from CIME.status import append_testlog
from CIME.utils import get_cime_root
from CIME.test_status import *
from CIME.SystemTests.system_tests_common import SystemTestsCommon
from CIME.test_status import BASELINE_PHASE, GENERATE_PHASE, TEST_PASS_STATUS
from CIME.utils import expect, get_cime_root, run_cmd

logger = logging.getLogger(__name__)

Expand Down
20 changes: 14 additions & 6 deletions CIME/SystemTests/hommebaseclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
CIME HOMME test. This class inherits from SystemTestsCommon
"""

from CIME.XML.standard_module_setup import *
from CIME.SystemTests.system_tests_common import SystemTestsCommon
import logging
import os
import shutil

from CIME.build import post_build
from CIME.status import append_testlog
from CIME.utils import SharedArea, new_lid, gzip_existing_file
from CIME.test_status import *

import shutil
from CIME.SystemTests.system_tests_common import SystemTestsCommon
from CIME.test_status import BASELINE_PHASE, GENERATE_PHASE, TEST_PASS_STATUS
from CIME.utils import (
SharedArea,
expect,
gzip_existing_file,
new_lid,
run_cmd,
run_cmd_no_fail,
)

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion CIME/SystemTests/icp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
CIME ICP test This class inherits from SystemTestsCommon
"""
from CIME.XML.standard_module_setup import *

from CIME.SystemTests.system_tests_common import SystemTestsCommon


Expand Down
6 changes: 4 additions & 2 deletions CIME/SystemTests/irt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

"""

import logging
import os

from CIME.SystemTests.restart_tests import RestartTest
from CIME.XML.standard_module_setup import *
from CIME.utils import ls_sorted_by_fname
from CIME.utils import expect, ls_sorted_by_fname

logger = logging.getLogger(__name__)

Expand Down
Loading
Loading