[+] update status
1. add repeat_interval;
This commit is contained in:
parent
904c77fc29
commit
6410df3326
@ -1,5 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import datetime
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -17,7 +20,48 @@ from typing import (
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def get_info(
|
||||||
|
sh: list[str],
|
||||||
|
timeout: int | float,
|
||||||
|
):
|
||||||
|
t1: list[str] = []
|
||||||
|
|
||||||
|
for sh_index, o in enumerate(
|
||||||
|
[
|
||||||
|
*sh,
|
||||||
|
*[
|
||||||
|
r"""
|
||||||
|
A=$(free -h | grep -P Mem: | grep -Po '[\w\.\d]+');
|
||||||
|
echo -n $A | awk '{print $2, $7}';
|
||||||
|
""",
|
||||||
|
r"""
|
||||||
|
date +'%Y-%m-%d %l:%M:%S %p';
|
||||||
|
""",
|
||||||
|
],
|
||||||
|
]
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
t1.append(
|
||||||
|
subprocess.check_output(
|
||||||
|
o,
|
||||||
|
shell=True,
|
||||||
|
timeout=timeout,
|
||||||
|
)
|
||||||
|
.decode('utf-8')
|
||||||
|
.strip()
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
t1.append('fail %d' % sh_index)
|
||||||
|
|
||||||
|
t3 = ' | '.join(t1).replace('\n\r', '')
|
||||||
|
|
||||||
|
sys.stdout.write(t3)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
def run(argv: list[str]):
|
def run(argv: list[str]):
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
assert isinstance(argv, list) and all([isinstance(o, str) for o in argv])
|
assert isinstance(argv, list) and all([isinstance(o, str) for o in argv])
|
||||||
|
|
||||||
class c1(optparse.IndentedHelpFormatter):
|
class c1(optparse.IndentedHelpFormatter):
|
||||||
@ -81,6 +125,13 @@ def run(argv: list[str]):
|
|||||||
default=None,
|
default=None,
|
||||||
type=float,
|
type=float,
|
||||||
)
|
)
|
||||||
|
add_option(
|
||||||
|
parser,
|
||||||
|
'--repeat_interval',
|
||||||
|
dest='repeat_interval',
|
||||||
|
default=None,
|
||||||
|
type=float,
|
||||||
|
)
|
||||||
add_option(
|
add_option(
|
||||||
parser,
|
parser,
|
||||||
'--config',
|
'--config',
|
||||||
@ -122,39 +173,37 @@ printf '% 3.0f%%' $(upower -d | grep -Po 'percentage:\\s+\\d+(\\.\\d+)?%' | grep
|
|||||||
|
|
||||||
options.sh.extend(config.get('sh', []))
|
options.sh.extend(config.get('sh', []))
|
||||||
|
|
||||||
t1: list[str] = []
|
last_ts = datetime.datetime.now()
|
||||||
|
|
||||||
for sh_index, o in enumerate(
|
shutdown: bool = False
|
||||||
[
|
|
||||||
*options.sh,
|
|
||||||
*[
|
|
||||||
r"""
|
|
||||||
A=$(free -h | grep -P Mem: | grep -Po '[\w\.\d]+');
|
|
||||||
echo -n $A | awk '{print $2, $7}';
|
|
||||||
""",
|
|
||||||
r"""
|
|
||||||
date +'%Y-%m-%d %l:%M:%S %p';
|
|
||||||
""",
|
|
||||||
],
|
|
||||||
]
|
|
||||||
):
|
|
||||||
try:
|
|
||||||
t1.append(
|
|
||||||
subprocess.check_output(
|
|
||||||
o,
|
|
||||||
shell=True,
|
|
||||||
timeout=timeout2,
|
|
||||||
)
|
|
||||||
.decode('utf-8')
|
|
||||||
.strip()
|
|
||||||
)
|
|
||||||
except Exception:
|
|
||||||
t1.append('fail %d' % sh_index)
|
|
||||||
|
|
||||||
t3 = ' | '.join(t1).replace('\n\r', '')
|
def on_signal(*args: Any, **kwargs: Any):
|
||||||
|
nonlocal shutdown
|
||||||
|
|
||||||
sys.stdout.write(t3)
|
shutdown = True
|
||||||
sys.stdout.flush()
|
|
||||||
|
signal.signal(signal.SIGINT, on_signal)
|
||||||
|
signal.signal(signal.SIGTERM, on_signal)
|
||||||
|
|
||||||
|
while not shutdown:
|
||||||
|
get_info(
|
||||||
|
timeout=timeout2,
|
||||||
|
sh=options.sh,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not options.repeat_interval:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
sys.stdout.write('\n')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
now_ts = datetime.datetime.now()
|
||||||
|
spent = (now_ts - last_ts).total_seconds()
|
||||||
|
|
||||||
|
last_ts = last_ts + datetime.timedelta(seconds=options.repeat_interval)
|
||||||
|
|
||||||
|
if spent < options.repeat_interval:
|
||||||
|
time.sleep(options.repeat_interval - spent)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
BIN
releases/whl/online_fxreader_pr34-0.1.5.43-py3-none-any.whl
(Stored with Git LFS)
Normal file
BIN
releases/whl/online_fxreader_pr34-0.1.5.43-py3-none-any.whl
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user