Skip to content

Commit

Permalink
Handling checking for OSs better
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Nov 26, 2024
1 parent dcef81a commit 1c13b4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
14 changes: 7 additions & 7 deletions armi/bookkeeping/report/reportingUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,28 +377,28 @@ def _getSystemInfoLinux():


def getSystemInfo():
"""Get system information, assuming the system is Windows or Linux.
"""Get system information, assuming the system is Linux, MacOS, and Windows.
Notes
-----
The format of the system information will be different on Windows vs Linux.
The format of the system information will be different on Linux, MacOS, and Windows.
Returns
-------
str
Basic system information: OS name, OS version, basic processor information
"""
# Get basic system information (on Windows and Linux)
if "win" in sys.platform:
# Get basic system information (on Linux, MacOS, and Windows)
if "darwin" in sys.platform:
return _getSystemInfoMac()
elif "win" in sys.platform:
return _getSystemInfoWindows()
elif "linux" in sys.platform:
return _getSystemInfoLinux()
elif "darwin" in sys.platform:
return _getSystemInfoMac()
else:
runLog.warning(
f"Cannot get system information for {sys.platform} because ARMI only "
+ "supports Linux, Windows, and MacOS."
+ "supports Linux, MacOS, and Windows."
)
return ""

Expand Down
3 changes: 2 additions & 1 deletion armi/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def setMode(cls, mode):
# Set batch mode if not a TTY, which means you're on a cluster writing to a stdout file. In this
# mode you cannot respond to prompts. (This does not work reliably for both Windows and Linux so an
# os-specific solution is applied.)
isatty = sys.stdout.isatty() if "win" in sys.platform else sys.stdin.isatty()
IS_WINDOWS = ("win" in sys.platform) and ("darwin" not in sys.platform)
isatty = sys.stdout.isatty() if IS_WINDOWS else sys.stdin.isatty()
CURRENT_MODE = Mode.INTERACTIVE if isatty else Mode.BATCH
Mode.setMode(CURRENT_MODE)

Expand Down
7 changes: 5 additions & 2 deletions armi/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,10 @@ def safeCopy(src: str, dst: str) -> None:
dst = os.path.abspath(dst)
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))

srcSize = os.path.getsize(src)
if "win" in sys.platform:
# this covers Windows ("win32") and MacOS ("darwin")
shutil.copyfile(src, dst)
shutil.copymode(src, dst)
elif "linux" in sys.platform:
Expand All @@ -816,8 +818,9 @@ def safeCopy(src: str, dst: str) -> None:
else:
raise OSError(
"Cannot perform ``safeCopy`` on files because ARMI only supports "
+ "Linux and Windows."
+ "Linux, MacOs, and Windows."
)

waitTime = 0.01 # 10 ms
maxWaitTime = 300 # 5 min
totalWaitTime = 0
Expand All @@ -832,7 +835,7 @@ def safeCopy(src: str, dst: str) -> None:
f"File copy from {dst} to {src} has failed due to exceeding "
+ f"a maximum wait time of {maxWaitTime/60} minutes."
)
break
Return

runLog.extra("Copied {} -> {}".format(src, dst))

Expand Down

0 comments on commit 1c13b4a

Please sign in to comment.