-
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.
add new processor to append input values
- Loading branch information
Showing
2 changed files
with
89 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,78 @@ | ||
#!/usr/local/autopkg/python | ||
# | ||
# James Stewart @JGStew - 2021 | ||
# | ||
# Related: | ||
# - https://github.com/jgstew/bigfix_prefetch/blob/master/prefetch_from_dictionary.py | ||
# | ||
"""See docstring for TemplateDictionaryAppendInput class""" | ||
|
||
|
||
from autopkglib import ( # pylint: disable=import-error,wrong-import-position,unused-import | ||
Processor, | ||
ProcessorError, | ||
) | ||
|
||
__all__ = ["TemplateDictionaryAppendInput"] | ||
|
||
|
||
class TemplateDictionaryAppendInput(Processor): # pylint: disable=invalid-name | ||
"""Adds Input ENV Vars to Template Dictionary""" | ||
|
||
description = __doc__ | ||
input_variables = { | ||
"dictionary_name": { | ||
"required": False, | ||
"default": "template_dictionary", | ||
"description": "python dictionary to append to", | ||
}, | ||
"input_keys_array": { | ||
"required": False, | ||
"default": ["DisplayName", "64BitOnly", "32BitOnly", "VendorFolder"], | ||
"description": "the input env keys to append", | ||
}, | ||
"input_keys_prefix": { | ||
"required": False, | ||
"default": "Template_", | ||
"description": "the prefix of input env keys to append", | ||
}, | ||
} | ||
output_variables = { | ||
"dictionary_name": {"description": ("The appended dictionary name")}, | ||
"dictionary_appended": {"description": ("The appended dictionary")}, | ||
} | ||
__doc__ = description | ||
|
||
def main(self): | ||
"""Execution starts here""" | ||
|
||
# get the current dictionary | ||
dictionary_name = self.env.get("dictionary_name", "template_dictionary") | ||
dictionary_to_append = self.env.get(dictionary_name, {}) | ||
input_keys_array = self.env.get("input_keys_array", []) | ||
input_keys_prefix = str(self.env.get("input_keys_prefix", "Template_")) | ||
|
||
self.output(f"dictionary_to_append: {dictionary_to_append}", 2) | ||
|
||
# ensure it is a dict | ||
dictionary_to_append = dict(dictionary_to_append) | ||
|
||
# TODO: append matching ENV items to dictionary | ||
for item in self.env: | ||
if input_keys_prefix in str(item): | ||
# print(f"{item} starts with {input_keys_prefix}") | ||
# get key without prefix: | ||
append_key = str(item).partition(input_keys_prefix)[2] | ||
dictionary_to_append[append_key] = self.env[item] | ||
if item in input_keys_array: | ||
print(f"{item} in array") | ||
dictionary_to_append[str(item)] = self.env[item] | ||
|
||
# write back the dict to itself | ||
self.env[dictionary_name] = dictionary_to_append | ||
self.env["dictionary_appended"] = dictionary_to_append | ||
|
||
|
||
if __name__ == "__main__": | ||
PROCESSOR = TemplateDictionaryAppendInput() | ||
PROCESSOR.execute_shell() |
11 changes: 11 additions & 0 deletions
11
Test-Recipes/TemplateDictionaryAppendInput.test.recipe.yaml
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,11 @@ | ||
--- | ||
Description: Test TemplateDictionaryAppendInput Processor | ||
Identifier: com.github.jgstew.test.TemplateDictionaryAppendInput | ||
Input: | ||
NAME: TemplateDictionaryAppendInputTest | ||
DisplayName: TemplateDictionaryAppendInput | ||
Template_version: "0.0.0" | ||
Template_example: "example value" | ||
MinimumVersion: "2.3" | ||
Process: | ||
- Processor: com.github.jgstew.SharedProcessors/TemplateDictionaryAppendInput |