diff options
Diffstat (limited to '')
-rw-r--r-- | python/mozlint/mozlint/util/__init__.py | 0 | ||||
-rw-r--r-- | python/mozlint/mozlint/util/implementation.py | 35 | ||||
-rw-r--r-- | python/mozlint/mozlint/util/string.py | 9 |
3 files changed, 44 insertions, 0 deletions
diff --git a/python/mozlint/mozlint/util/__init__.py b/python/mozlint/mozlint/util/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/python/mozlint/mozlint/util/__init__.py diff --git a/python/mozlint/mozlint/util/implementation.py b/python/mozlint/mozlint/util/implementation.py new file mode 100644 index 0000000000..9c72c0ea0f --- /dev/null +++ b/python/mozlint/mozlint/util/implementation.py @@ -0,0 +1,35 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import signal +from abc import ABC, abstractmethod + +from mozprocess import ProcessHandlerMixin + + +class LintProcess(ProcessHandlerMixin, ABC): + def __init__(self, config, *args, **kwargs): + self.config = config + self.results = [] + + kwargs["universal_newlines"] = True + kwargs["processOutputLine"] = [self.process_line] + ProcessHandlerMixin.__init__(self, *args, **kwargs) + + @abstractmethod + def process_line(self, line): + """Process a single line of output. + + The implementation is responsible for creating one or more :class:`~mozlint.result.Issue` + and storing them somewhere accessible. + + Args: + line (str): The line of output to process. + """ + pass + + def run(self, *args, **kwargs): + orig = signal.signal(signal.SIGINT, signal.SIG_IGN) + ProcessHandlerMixin.run(self, *args, **kwargs) + signal.signal(signal.SIGINT, orig) diff --git a/python/mozlint/mozlint/util/string.py b/python/mozlint/mozlint/util/string.py new file mode 100644 index 0000000000..9c1c7c99c2 --- /dev/null +++ b/python/mozlint/mozlint/util/string.py @@ -0,0 +1,9 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +def pluralize(s, num): + if num != 1: + s += "s" + return str(num) + " " + s |