11from argparse import ArgumentParser
22from shlex import join
3- from sys import stderr , stdout
4- from shutil import copyfileobj
3+ from sys import stderr , stdout , platform
54from subprocess import Popen , PIPE , run
6- import sys
7- from typing import Dict , Any
8- from .utils import check_pid , filesizepu , kill_pid , tail_bytes , tail_file
5+ from typing import Any
6+ from .utils import check_pid , filesizepu , kill_pid , tail_bytes
97from .main import Main , flag , arg
108from .procdb import ProcessDB as Manager
119
@@ -25,13 +23,13 @@ def __missing__(self, key: str) -> str:
2523 return self ["cmd" ]
2624 return join (self ["cmd" ])
2725 elif key == "pid_status" :
28- return "Running " if check_pid (self ["pid" ]) else "Stopped "
26+ return "Live " if check_pid (self ["pid" ]) else "Done "
2927 raise KeyError (f"No { key !r} " )
3028
3129
3230def format_prep (f : str ):
3331
34- def fn (x : Dict [str , Any ]) -> str :
32+ def fn (x : "dict [str, Any]" ) -> str :
3533 return f .format_map (FormatDict (x ))
3634
3735 return fn
@@ -56,7 +54,7 @@ def ambiguous(name):
5654class Clean (Main ):
5755 """Clean up dead processes."""
5856
59- ids : list [str ] = arg ("ID" , "run ids" , nargs = "*" )
57+ ids : " list[str]" = arg ("ID" , "run ids" , nargs = "*" )
6058
6159 def add_arguments (self , argp : ArgumentParser ) -> None :
6260 argp .description = "Clean up entries for non-existing processes"
@@ -78,7 +76,7 @@ def start(self) -> None:
7876class Status (Main ):
7977 """Check process status."""
8078
81- ids : list [str ] = arg ("ID" , "run ids" , nargs = "*" )
79+ ids : " list[str]" = arg ("ID" , "run ids" , nargs = "*" )
8280 format : str = flag (
8381 "f" ,
8482 "format of entry line" ,
@@ -99,7 +97,7 @@ def start(self) -> None:
9997class Kill (Main ):
10098 """Kill running processes."""
10199
102- ids : list [str ] = arg ("ID" , "run ids" , nargs = "+" )
100+ ids : " list[str]" = arg ("ID" , "run ids" , nargs = "+" )
103101 dry_run : bool = flag ("dry-run" , "dry run (don't actually kill)" , default = False )
104102 remove : bool = flag ("remove" , "remove entry after killing" , default = False )
105103 group : bool = flag ("group" , "kill process group" , default = False )
@@ -139,7 +137,7 @@ def _tail(n: float, u="", out="", tab=None):
139137 if u :
140138 stdout .buffer .write (tail_bytes (out , int (n )))
141139 elif n > 0 :
142- if sys . platform .startswith ("win" ):
140+ if platform .startswith ("win" ):
143141 cmd = [
144142 "powershell" ,
145143 "-c" ,
@@ -158,19 +156,16 @@ def _tail(n: float, u="", out="", tab=None):
158156class Tail (Main ):
159157 """Tail process output."""
160158
161- ids : list [str ] = arg ("ID" , "run ids" , nargs = "*" )
159+ ids : " list[str]" = arg ("ID" , "run ids" , nargs = "*" )
162160 format : str = flag ("header" , "header format" )
163161 lines : str = flag ("n" , "lines" , "how many lines or bytes" )
164- existing : bool = flag (
165- "x" , "only-existing" , "only show existing processes" , default = False
166- )
162+ existing : bool = flag ("x" , "only-existing" , "only show existing processes" , default = False )
167163 tab : bool = flag ("t" , "tab" , "prefix tab space" , default = False )
168164 err : bool = flag ("e" , "err" , "output stderr" , default = False )
169165 p_open : str = "=== "
170166 p_close : str = " ==="
171167
172168 def start (self ) -> None :
173- import sys
174169
175170 if self .format == "no" :
176171 hf = None
@@ -194,7 +189,7 @@ def start(self) -> None:
194189class Run (Main ):
195190 """Run a new singleton process."""
196191
197- args : list [str ] = arg ("ARG" , nargs = "*" , metavar = "arg" )
192+ args : " list[str]" = arg ("ARG" , nargs = "*" , metavar = "arg" )
198193 tail : int = flag ("t" , "tail" , "tail the output with n lines" , default = 0 )
199194 run_id : str = flag ("id" , "Unique run identifier" , default = "" )
200195 cwd : str = flag ("Working directory for the command" )
@@ -219,9 +214,7 @@ def start(self) -> None:
219214 s = ["🚨" , r"Found: PID={pid} ({pid_status}) {name}" ]
220215 else :
221216 # Start new process
222- e = sp .spawn (
223- args , name , overwrite = self .overwrite , cwd = self .cwd , split = self .split
224- )
217+ e = sp .spawn (args , name , overwrite = self .overwrite , cwd = self .cwd , split = self .split )
225218 s = ["🚀" , r"Started: PID={pid} ({pid_status}) {name}" ]
226219 assert e
227220 try :
@@ -271,7 +264,7 @@ def start(self) -> None:
271264class Restart (Main ):
272265 """Restart a process."""
273266
274- ids : list [str ] = arg ("ID" , "run ids" , nargs = "+" )
267+ ids : " list[str]" = arg ("ID" , "run ids" , nargs = "+" )
275268 tail : int = flag ("t" , "tail" , "tail the output with n lines" , default = 0 )
276269
277270 def init_argparse (self , argp : ArgumentParser ) -> None :
@@ -294,8 +287,7 @@ class App(Main):
294287 def init_argparse (self , argp : ArgumentParser ) -> None :
295288 argp .prog = "runce"
296289 argp .description = (
297- "Runce (Run Once) - Ensures commands run exactly once.\n "
298- "Guarantees singleton execution per unique ID."
290+ "Runce (Run Once) - Ensures commands run exactly once.\n " "Guarantees singleton execution per unique ID."
299291 )
300292 return super ().init_argparse (argp )
301293
0 commit comments