|
| 1 | +from subprocess import run |
| 2 | +from sys import exit |
| 3 | + |
| 4 | +from .abc import BaseHandler |
| 5 | + |
| 6 | + |
| 7 | +class ShellHandler(BaseHandler): |
| 8 | + """Run a shell script.""" |
| 9 | + |
| 10 | + def run(self, code_file): |
| 11 | + exit(run(["sh", code_file]).returncode) |
| 12 | + |
| 13 | + def build(self, code, directory=None): |
| 14 | + with self.file("sh", directory=directory) as f: |
| 15 | + f.write("#!/bin/sh\n") |
| 16 | + f.write(code) |
| 17 | + self.run(f.name) |
| 18 | + |
| 19 | + |
| 20 | +class ZshShellHandler(BaseHandler): |
| 21 | + """Run a Z shell script.""" |
| 22 | + |
| 23 | + def run(self, code_file): |
| 24 | + exit(run(["zsh", code_file]).returncode) |
| 25 | + |
| 26 | + def build(self, code, directory=None): |
| 27 | + with self.file("zsh", directory=directory) as f: |
| 28 | + f.write("#!/bin/zsh\n") |
| 29 | + f.write(code) |
| 30 | + self.run(f.name) |
| 31 | + |
| 32 | + |
| 33 | +class BashShellHandler(BaseHandler): |
| 34 | + """Run a Bash shell script.""" |
| 35 | + |
| 36 | + def run(self, code_file): |
| 37 | + exit(run(["bash", code_file]).returncode) |
| 38 | + |
| 39 | + def build(self, code, directory=None): |
| 40 | + with self.file("sh", directory=directory) as f: |
| 41 | + f.write("#!/bin/bash\n") |
| 42 | + f.write(code) |
| 43 | + self.run(f.name) |
0 commit comments