summaryrefslogtreecommitdiffstats
path: root/python/mozlint/mozlint/util/implementation.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--python/mozlint/mozlint/util/implementation.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/python/mozlint/mozlint/util/implementation.py b/python/mozlint/mozlint/util/implementation.py
new file mode 100644
index 0000000000..72e160a9b0
--- /dev/null
+++ b/python/mozlint/mozlint/util/implementation.py
@@ -0,0 +1,36 @@
+# 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
+import subprocess
+from abc import ABC, abstractmethod
+
+
+class LintProcess(subprocess.Popen, ABC):
+ def __init__(self, config, *args, **kwargs):
+ self.config = config
+ self.results = []
+
+ kwargs["text"] = True
+ kwargs["stdout"] = subprocess.PIPE
+ kwargs["stderr"] = subprocess.STDOUT
+ orig = signal.signal(signal.SIGINT, signal.SIG_IGN)
+ subprocess.Popen.__init__(self, *args, **kwargs)
+ signal.signal(signal.SIGINT, orig)
+
+ @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):
+ for line in self.stdout:
+ self.process_line(line)