-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysinfo_123.py
More file actions
executable file
·145 lines (117 loc) · 3.23 KB
/
sysinfo_123.py
File metadata and controls
executable file
·145 lines (117 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
***************************************************************************
* Copyright (C) 2023, Lanka Hsu, <lankahsu@gmail.com>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************
"""
#import os, sys, errno, getopt, signal, time, io
#from time import sleep
from sysinfo_api import *
appX_list = []
is_quit = 0
is_release = 0
argsX = {
"keyboard": 1
,"interval": 5
}
def argsX_set(name, val):
global argsX
argsX[name]=val
def argsX_get(name):
return argsX[name]
def argsX_dump():
#dbg_lvl_set(DBG_LVL_TRACE)
DBG_IF_LN("{}".format( argsX ) )
def app_quit_get():
return is_quit
def app_quit_set(mode):
global is_quit
is_quit=mode
def app_start():
argsX_dump()
sysinfo_mgr = sysinfo_ctx(dbg_lvl=DBG_LVL_TRACE)
app_watch(sysinfo_mgr)
sysinfo_mgr.start(args=argsX)
#sysinfo_mgr.keyboard_recv()
sysinfo_mgr.release()
def app_watch(app_ctx):
global appX_list
appX_list.append( app_ctx )
def app_release():
global appX_list
global is_release
if ( is_release == 0 ):
is_release = 1
DBG_DB_LN("{}".format(DBG_TXT_ENTER))
for x in appX_list:
try:
objname = DBG_NAME(x)
if not x.release is None:
DBG_DB_LN("call {}.release ...".format( objname ) )
x.release() # No handlers could be found for logger "google.api_core.bidi"
except Exception:
pass
DBG_DB_LN("{}".format(DBG_TXT_DONE))
def app_stop():
# dont block this function or print, signal_handler->app_stop
if ( app_quit_get() == 0 ):
app_quit_set(1)
app_release()
def app_exit():
app_stop()
DBG_DB_LN("{}".format(DBG_TXT_DONE))
def show_usage(argv):
print("Usage: {} <options...>".format(argv[0]) )
print(" -h, --help")
print(" -d, --debug level")
print(" -k, --key")
print(" 0: critical, 1: errror, 2: warning, 3: info, 4: debug, 5: trace")
app_exit()
sys.exit(0)
def parse_arg(argv):
try:
opts,args = getopt.getopt(argv[1:], "hkd:", ["help", "key", "debug"])
except getopt.GetoptError:
show_usage(argv)
#print (opts)
#print (args)
if (len(opts) > 0):
for opt, arg in opts:
#DBG_IF_LN("opt:{}, arg:{}".format(opt, arg))
if opt in ("-h", "--help"):
show_usage(argv)
elif opt in ("-k", "--key"):
argsX_set("keyboard", 1)
elif opt in ("-d", "--debug"):
dbg_debug_helper( int(arg) )
#DBG_IF_LN("arg:{}".format(arg))
else:
print ("(opt: {})".format(opt))
else:
show_usage(argv)
def signal_handler(sig, frame):
if sig in (signal.SIGINT, signal.SIGTERM):
app_stop()
return
sys.exit(0)
def main(argv):
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
parse_arg(argv)
app_start()
app_exit()
DBG_WN_LN("{} (app_quit_get: {})".format(DBG_TXT_BYE_BYE, app_quit_get()) )
if __name__ == "__main__":
main(sys.argv[0:])