-
Notifications
You must be signed in to change notification settings - Fork 114
/
FindAndReplace.py
62 lines (53 loc) · 1.95 KB
/
FindAndReplace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
#
# Copyright 2016-2020 Elliot Jordan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from autopkglib import Processor # noqa: F401
__all__ = ["FindAndReplace"]
class FindAndReplace(Processor):
"""This processor does one thing only: It searches the input variable you
specify and replaces instances of the "find" string with the "replace"
string."""
input_variables = {
"input_string": {
"required": True,
"description": "The string you want to perform find/replace on.",
},
"find": {
"required": True,
"description": "This string, if found, will be replaced with the "
'"replace" string.',
},
"replace": {
"required": True,
"description": 'The string that you want to replace the "find" '
"string with.",
},
}
output_variables = {
"output_string": {
"description": "The result of find/replace on the input string."
}
}
description = __doc__
def main(self):
"""Main process."""
input_string = self.env["input_string"]
find = self.env["find"]
replace = self.env["replace"]
self.output(f'Replacing "{find}" with "{replace}" in "{input_string}".')
self.env["output_string"] = self.env["input_string"].replace(find, replace)
if __name__ == "__main__":
PROCESSOR = FindAndReplace()
PROCESSOR.execute_shell()