Skip to content

Commit

Permalink
move output_capture to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
rfbgo committed Jul 26, 2024
1 parent 840fe12 commit 8cc6cd1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/ramble/ramble/appkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@

from ramble.util.file_util import get_file_path

from ramble.schema.types import OUTPUT_CAPTURE
from ramble.util.output_capture import OUTPUT_CAPTURE
2 changes: 1 addition & 1 deletion lib/ramble/ramble/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from ramble.language.application_language import ApplicationMeta
from ramble.language.shared_language import SharedMeta, register_builtin, register_phase
from ramble.error import RambleError
from ramble.schema.types import output_mapper
from ramble.util.output_capture import output_mapper

from enum import Enum

Expand Down
2 changes: 1 addition & 1 deletion lib/ramble/ramble/modkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
import ramble.language.modifier_language
from ramble.language.modifier_language import *
from ramble.language.shared_language import *
from ramble.schema.types import OUTPUT_CAPTURE
from ramble.util.output_capture import OUTPUT_CAPTURE

from ramble.util.file_util import get_file_path
2 changes: 1 addition & 1 deletion lib/ramble/ramble/pkgmankit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
import ramble.language.package_manager_language
from ramble.language.package_manager_language import *
from ramble.language.shared_language import *
from ramble.schema.types import OUTPUT_CAPTURE
from ramble.util.output_capture import OUTPUT_CAPTURE

from ramble.software_environments import ExternalEnvironment
3 changes: 2 additions & 1 deletion lib/ramble/ramble/schema/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import ramble.schema.types
import ramble.schema.variables
from ramble.util.output_capture import OUTPUT_CAPTURE


custom_executables_def = {
Expand All @@ -28,7 +29,7 @@
"use_mpi": False,
"redirect": "{log_file}",
"variables": {},
"output_capture": ramble.schema.types.OUTPUT_CAPTURE.DEFAULT,
"output_capture": OUTPUT_CAPTURE.DEFAULT,
},
"properties": union_dicts(
{
Expand Down
27 changes: 0 additions & 27 deletions lib/ramble/ramble/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,6 @@

"""Base types for building schema files from"""

from enum import Enum


class OUTPUT_CAPTURE(Enum):
STDOUT = 0
STDERR = 1
ALL = 2
DEFAULT = 2


class output_mapper:
def __init__(self):
self.map = {
OUTPUT_CAPTURE.STDOUT: ">>",
OUTPUT_CAPTURE.STDERR: "2>>",
OUTPUT_CAPTURE.ALL: ">>",
}
self.SUFFIX = "2>&1"

def generate_out_string(self, out_log, output_operator):
redirect_str = f' {self.map.get(output_operator, output_operator)} "{out_log}"'
if output_operator is OUTPUT_CAPTURE.ALL:
redirect_str += f" {self.SUFFIX}"

return redirect_str


string_or_num_list = [{"type": "string"}, {"type": "number"}]

string_or_num = {"anyOf": string_or_num_list}
Expand Down
2 changes: 1 addition & 1 deletion lib/ramble/ramble/util/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import ramble.error

from ramble.schema.types import OUTPUT_CAPTURE
from ramble.util.output_capture import OUTPUT_CAPTURE

import spack.util.executable
from spack.util.path import system_path_filter
Expand Down
33 changes: 33 additions & 0 deletions lib/ramble/ramble/util/output_capture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022-2024 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

from enum import Enum


class OUTPUT_CAPTURE(Enum):
STDOUT = 0
STDERR = 1
ALL = 2
DEFAULT = 2


class output_mapper:
def __init__(self):
self.map = {
OUTPUT_CAPTURE.STDOUT: ">>",
OUTPUT_CAPTURE.STDERR: "2>>",
OUTPUT_CAPTURE.ALL: ">>",
}
self.SUFFIX = "2>&1"

def generate_out_string(self, out_log, output_operator):
redirect_str = f' {self.map.get(output_operator, output_operator)} "{out_log}"'
if output_operator is OUTPUT_CAPTURE.ALL:
redirect_str += f" {self.SUFFIX}"

return redirect_str

0 comments on commit 8cc6cd1

Please sign in to comment.