Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit 5662c4e

Browse files
committed
Add shell script handlers
1 parent b1d35d4 commit 5662c4e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

handlers/shell.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)