-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/local/autopkg/python | ||
# | ||
# James Stewart @JGStew - 2023 | ||
# | ||
"""See docstring for VariableToString class""" | ||
|
||
from autopkglib import ( # pylint: disable=import-error,wrong-import-position,unused-import | ||
Processor, | ||
ProcessorError, | ||
) | ||
|
||
__all__ = ["VariableToString"] | ||
|
||
|
||
class VariableToString(Processor): | ||
"""Reads a variable and returns it as a string.""" | ||
|
||
description = __doc__ | ||
|
||
input_variables = { | ||
"input_variable": { | ||
"required": True, | ||
"description": "The variable to read from.", | ||
}, | ||
"output_variable": { | ||
"required": False, | ||
"description": "Name of the output variable to store the value.", | ||
}, | ||
} | ||
output_variables = {} | ||
|
||
__doc__ = description | ||
|
||
def main(self): | ||
"""Execution starts here""" | ||
input_variable = self.env.get("input_variable", "") | ||
output_variable = self.env.get("output_variable", input_variable) | ||
|
||
value = str(self.env.get(input_variable)) | ||
|
||
if value is not None: | ||
self.env[output_variable] = value | ||
self.output_variables[output_variable] = { | ||
"description": "the custom output" | ||
} | ||
else: | ||
raise ProcessorError(f"Variable not found.") | ||
|
||
|
||
if __name__ == "__main__": | ||
PROCESSOR = VariableToString() | ||
PROCESSOR.execute_shell() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
Description: Test VariableToString Processor | ||
Identifier: com.github.jgstew.test.VariableToString | ||
Input: | ||
NAME: VariableToStringTest | ||
float: 1.2 | ||
int: 1 | ||
MinimumVersion: "2.3" | ||
Process: | ||
- Processor: com.github.jgstew.SharedProcessors/VariableToString | ||
Arguments: | ||
input_variable: float | ||
|
||
- Processor: com.github.jgstew.SharedProcessors/AssertInputContainsString | ||
Arguments: | ||
input_string: "%float%" | ||
assert_string: 1.2 | ||
|
||
- Processor: com.github.jgstew.SharedProcessors/VariableToString | ||
Arguments: | ||
input_variable: int | ||
|
||
- Processor: com.github.jgstew.SharedProcessors/AssertInputContainsString | ||
Arguments: | ||
input_string: "%int%" | ||
assert_string: 1 |