From 7fb353a7799ba2a50efbea61db8573c4c03aa1ae Mon Sep 17 00:00:00 2001 From: iipeace Date: Tue, 17 Sep 2024 23:31:06 +0900 Subject: [PATCH] top: Add dynamic options Signed-off-by: iipeace --- guider/guider.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/guider/guider.py b/guider/guider.py index f331b082..56c35f17 100755 --- a/guider/guider.py +++ b/guider/guider.py @@ -7,7 +7,7 @@ __credits__ = "Peace Lee" __license__ = "GPLv2" __version__ = "3.9.8" -__revision__ = "240916" +__revision__ = "240917" __maintainer__ = "Peace Lee" __email__ = "iipeace5@gmail.com" __repository__ = "https://github.com/iipeace/guider" @@ -27549,6 +27549,8 @@ class SysMgr(object): overlayfsCache = {} vmflagList = [] requestQueue = [] + runtimeOption = [] + uptimeOption = [] # threshold # thrData = {} @@ -38136,6 +38138,10 @@ def printHelp(force=False, isExit=True): - {3:1} {2:1} and execute special commands # {0:1} {1:1} -w AFTER:/tmp/touched:1, AFTER:ls + - {3:1} {2:1} and update options with specific conditions + # {0:1} {1:1} -q DYNUPTIMEOPT:1m:"-i 3 -a" + # {0:1} {1:1} -q DYNRUNTIMEOPT:2m:"-i 3 -a" + - {3:1} {2:1} through the local server having 5555 port # {0:1} {1:1} -X 5555 # {0:1} {1:1} -X PRINT@5555 @@ -54120,6 +54126,7 @@ def _setLogger(options): "limit the size of '%s' to [%s]" % (path, convSize2Unit(size)) ) + # get limited report dir info # if "LIMITREPDIR" in SysMgr.environList: try: @@ -54176,6 +54183,7 @@ def _setLogger(options): "limit the count of files in '%s' to [%s]" % (path, convSize2Unit(cnt)) ) + # register exit commands # if "EXITCMD" in SysMgr.environList: SysMgr.addExitFunc( @@ -54187,6 +54195,26 @@ def _setLogger(options): % ", ".join(SysMgr.environList["EXITCMD"]) ) + # register dynamic option # + for name, env, optList in ( + ("runtime", "DYNRUNTIMEOPT", SysMgr.runtimeOption), + ("uptime", "DYNUPTIMEOPT", SysMgr.uptimeOption), + ): + for opt in SysMgr.environList.get(env, []): + items = opt.split(":", 1) + errStr = "failed to recognize dynamic %s option '%s'" % ( + name, + opt, + ) + if len(items) == 1: + SysMgr.printErr(errStr) + sys.exit(-1) + when, opt = items + when = UtilMgr.convUnit2Time(when) + if not when: + SysMgr.printErr(errStr) + optList.append([when, opt]) + # ignore signals # SysMgr.applyIgnoreSignals() @@ -57126,6 +57154,26 @@ def updateUptime(): if SysMgr.dltTimeEnable: SysMgr.dltTime = UtilMgr.getClockTime(dlt=True) + # check dynamic options # + for optList in ("uptimeOption", "runtimeOption"): + targetList = getattr(SysMgr, optList) + if not targetList: + continue + + if optList == "uptimeOption": + stand = SysMgr.uptime + else: + stand = SysMgr.getRuntime(sec=True) + + newList = [] + for cond, opts in targetList: + if cond < stand: + SysMgr.printInfo("apply '%s' option" % opts) + SysMgr.parseAnalOption(opts) + else: + newList.append([cond, opts]) + setattr(SysMgr, optList, newList) + return SysMgr.uptime @staticmethod