Skip to content

Commit deaec57

Browse files
jet-logicjet-logic
authored andcommitted
v0.4.2
1 parent 72bc436 commit deaec57

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

runce/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
Ensures each command runs exactly once per unique ID.
66
"""
77

8-
__version__ = "0.4.1"
8+
__version__ = "0.4.2"

runce/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class Run(Main):
202202
overwrite: bool = flag("overwrite", "Overwrite existing entry", default=False)
203203
cmd_after: str = flag("run-after", "Run command after", metavar="command")
204204
split: bool = flag("split", "Dont merge stdout and stderr", default=False)
205+
input: str = flag("i", "input", "pass FILE to stdin", metavar="FILE", default="")
205206

206207
def start(self) -> None:
207208
args = self.args
@@ -213,8 +214,9 @@ def start(self) -> None:
213214
if e:
214215
s = ["🚨", r"Found: PID={pid} ({pid_status}) {name}"]
215216
else:
217+
216218
# Start new process
217-
e = sp.spawn(args, name, overwrite=self.overwrite, cwd=self.cwd, split=self.split)
219+
e = sp.spawn(args, name, overwrite=self.overwrite, cwd=self.cwd, split=self.split, in_file=self.input)
218220
s = ["🚀", r"Started: PID={pid} ({pid_status}) {name}"]
219221
assert e
220222
try:
@@ -254,8 +256,8 @@ def start(self) -> None:
254256
pass
255257
else:
256258
f = "{pid_status} {elapsed} {pid}\t{name}, {command}"
257-
print("Status Elapsed PID\tName, Command")
258-
print("------- -------- ------ ------------")
259+
print("Stat Elapsed PID\tName, Command")
260+
print("---- -------- ------ ------------")
259261
fp = format_prep(f)
260262
for d in Manager().all():
261263
print(fp(d))

runce/spawn.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ def spawn(
5757
mode = "w" if overwrite else "x"
5858

5959
if in_file:
60-
po_kwa["stdin"] = Path(in_file).open("rb")
60+
if in_file == "-":
61+
from sys import stdin
62+
63+
po_kwa["stdin"] = stdin.buffer
64+
else:
65+
po_kwa["stdin"] = Path(in_file).open("rb")
6166

6267
if not cmd:
6368
cmd = ["sh"]
@@ -75,15 +80,6 @@ def spawn(
7580
so = se = Path(out_file) if out_file else data_dir / f"{base_name}.log"
7681
po_kwa["stdout"] = so.open(f"{mode}b")
7782
po_kwa["stderr"] = STDOUT
78-
if po_kwa.get("stdin") is None:
79-
from sys import stdin
80-
81-
try:
82-
no = stdin.buffer.fileno()
83-
except Exception as ex:
84-
pass
85-
else:
86-
po_kwa["stdin"] = stdin.buffer
8783

8884
po_kwa.setdefault("start_new_session", True)
8985
po_kwa.setdefault("close_fds", True)

runce/utils.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,14 @@ def check_pid(pid: int) -> bool:
3737
finally:
3838
kernel32.CloseHandle(handle)
3939

40-
def kill_pid(
41-
pid: int, sig: Optional[int] = None, process_group: Optional[bool] = None
42-
) -> bool:
40+
def kill_pid(pid: int, sig: Optional[int] = None, process_group: Optional[bool] = None) -> bool:
4341
try:
4442
os.kill(pid, signal.SIGTERM if sig is None else sig)
4543
except PermissionError as e:
4644
if check_pid(pid) is False:
4745
return False
4846
except OSError as e:
49-
if 87 == getattr(
50-
e, "winerror", 0
51-
): # ERROR_INVALID_PARAMETER (no such process)
47+
if 87 == getattr(e, "winerror", 0): # ERROR_INVALID_PARAMETER (no such process)
5248
return False
5349
raise
5450
return True
@@ -183,7 +179,7 @@ def tail_file(filename="", n=10):
183179

184180
def filesizepu(s: str) -> tuple[int, str]:
185181
u = ""
186-
if s[0].isnumeric():
182+
if s[0].isnumeric() or s[0].startswith("."):
187183
q = s.lower()
188184
if q.endswith("b"):
189185
q, u = q[0:-1], q[-1]

0 commit comments

Comments
 (0)