|
| 1 | +#!/usr/bin/python |
| 2 | +# |
| 3 | +# Copyright 2019 Greg Neagle |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +"""Processor that outputs a warning message. Intended to alert recipe users of |
| 17 | +upcoming removal of a recipe.""" |
| 18 | + |
| 19 | +from __future__ import absolute_import |
| 20 | + |
| 21 | +import os |
| 22 | + |
| 23 | +from autopkglib import Processor |
| 24 | + |
| 25 | +__all__ = ["DeprecationWarning"] |
| 26 | + |
| 27 | + |
| 28 | +class DeprecationWarning(Processor): |
| 29 | + """This processor outputs a warning that the recipe has been deprecated.""" |
| 30 | + |
| 31 | + input_variables = { |
| 32 | + "warning_message": { |
| 33 | + "required": False, |
| 34 | + "description": "Warning message to output.", |
| 35 | + } |
| 36 | + } |
| 37 | + output_variables = { |
| 38 | + "deprecation_summary_result": { |
| 39 | + "description": "Description of interesting results." |
| 40 | + } |
| 41 | + } |
| 42 | + description = __doc__ |
| 43 | + |
| 44 | + def main(self): |
| 45 | + warning_message = self.env.get( |
| 46 | + "warning_message", |
| 47 | + "### This recipe has been deprecated. It may be removed soon. ###", |
| 48 | + ) |
| 49 | + self.output(warning_message) |
| 50 | + recipe_name = os.path.basename(self.env["RECIPE_PATH"]) |
| 51 | + if recipe_name.endswith(".recipe"): |
| 52 | + recipe_name = os.path.splitext(recipe_name)[0] |
| 53 | + self.env["deprecation_summary_result"] = { |
| 54 | + "summary_text": "The following recipes have deprecation warnings:", |
| 55 | + "report_fields": ["name", "warning"], |
| 56 | + "data": {"name": recipe_name, "warning": warning_message}, |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + PROCESSOR = DeprecationWarning() |
| 62 | + PROCESSOR.execute_shell() |
0 commit comments