kmisc 2.1.104__tar.gz → 2.1.106__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kmisc-2.1.106/PKG-INFO ADDED
@@ -0,0 +1,268 @@
1
+ Metadata-Version: 2.1
2
+ Name: kmisc
3
+ Version: 2.1.106
4
+ Summary: Enginering useful library
5
+ Home-page: https://github.com/kagepark/kmisc
6
+ Author: Kage Park
7
+ License: MIT
8
+ Description: Open Kage's useful tools and class to public.
9
+ (Long time used and upgraded)
10
+ But, this is develope version.
11
+ So, suddenly it will be big change when I got some more good idea.
12
+ I re-groupped to library.
13
+ and change name to klib
14
+
15
+ # Install
16
+ ```javascript
17
+ pip3 install kmisc
18
+ ```
19
+
20
+ # Import functions
21
+
22
+ # Custom Dictionary Class
23
+
24
+ Convert Dictionary to Object style Dictionary
25
+ ## Contents
26
+ 1. Create tree type items
27
+ 1. Added New commands
28
+ 1. Put() : Put value at a item
29
+ 1. Get() : Get value of item
30
+ 1. Del() : Delete item
31
+ 1. Update() : Update value at item
32
+ 1. Print() : Print dictionary
33
+ 1. Diff() : Compare two dictionary
34
+ 1. Check() : Check put the value is same as the item(key)'s value
35
+ 1. List() : Return list of keys value
36
+ 1. Proper() : Show/Set/Update property at the item.
37
+ 1. Find() : Find data in the dictionary
38
+ 1. Load() : Load saved data from file
39
+ 1. Save() : dictionary save to file
40
+ 1. Sort() : Sort dictionary
41
+ 1. FirstKey(): Get first Key
42
+ 1. FirstKey(): Get first Key
43
+ 1. Added property at each key
44
+
45
+ - Initialize dictionary
46
+
47
+
48
+ ```javascript
49
+ from kmisc import kDict
50
+ root=kDict.kDict()
51
+ ```
52
+
53
+ ```javascript
54
+ from kmisc import kDict
55
+ >>> test={
56
+ 'a':123,
57
+ 'b':{
58
+ 'c':{'ddd'},
59
+ 'e':{}
60
+ }
61
+ }
62
+ root=kDict.kDict(test)
63
+ ```
64
+
65
+ - Add new data
66
+
67
+ ```javascript
68
+ >>> root.tree.apple.color='red'
69
+ ```
70
+ or
71
+
72
+ ```javascript
73
+ >>> root.tree.apple.Put('color','red')
74
+ ```
75
+ or
76
+ ```javascript
77
+ >>> root.tree.apple['color']='red'
78
+ ```
79
+ - Get data
80
+ ```javascript
81
+ >>> root.tree.apple.color.Get()
82
+ ```
83
+ or
84
+ ```javascript
85
+ >>> root.tree.apple.Get('color')
86
+ ```
87
+ - Print dictionary
88
+ ```javascript
89
+ >>> root.Print()
90
+ >>> root.tree.Print()
91
+ ```
92
+ - Set property at Apple's color
93
+
94
+ - Set readonly
95
+ ```javascript
96
+ >>> root.tree.apple.color.Proper('readonly',True)
97
+ ```
98
+ - Try change data
99
+ ```javascript
100
+ >>> root.tree.apple.Put('color','white')
101
+ item is readonly
102
+
103
+ >>> root.tree.Print()
104
+ {'color': {'._d': 'red', '._p': {'readonly': True}}}
105
+ ```
106
+ - Unset readonly
107
+ ```javascript
108
+ >>> root.tree.apple.color.Proper('readonly',False)
109
+ ```
110
+ - Try change data
111
+ ```javascript
112
+ >>> root.tree.apple.Put('color','white')
113
+ >>> root.tree.Print()
114
+ {'color': {'._d': 'red', '._p': {'readonly': True}}}
115
+ ```
116
+ Sample Dictionary:
117
+ ```javascript
118
+ {'a': 123,
119
+ 'b': {'c': set(['ddd']), 'e': {}, 'z': 123},
120
+ 'tree': {'apple': {'color': {'._d': 'white', '._p': {'readonly': False}}},
121
+ 'banana': {'banana2': {'._d': 'white', '._p': {}},
122
+ 'banana3': {'._d': 'yellow', '._p': {}},
123
+ 'color': {'._d': 'yellow', '._p': {'readonly': True}}},
124
+ 'yellow': {'monkey': {'._d': 'white', '._p': {}}}}}
125
+ ```
126
+ - Find readonly property item path
127
+ ```javascript
128
+ >>> root.Find('readonly',property=True)
129
+ ['tree/banana/color']
130
+ ```
131
+ - Find apple key path
132
+ ```javascript
133
+ >>> root.Find('apple',mode='key')
134
+ ['tree/apple']
135
+ ```
136
+ - Find white color data path
137
+ ```javascript
138
+ >>> root.Find('white')
139
+ ['tree/apple/color', 'tree/yellow/monkey', 'tree/banana/banana2']
140
+ ```
141
+ - Find 123 data path
142
+ ```javascript
143
+ >>> root.Find('white')
144
+ ['a', 'b/z']
145
+ ```
146
+ - Find white color data path in key and value
147
+ ```javascript
148
+ >>> root.Find('yellow',mode='all')
149
+ ['tree/yellow', 'tree/banana/color', 'tree/banana/banana3']
150
+ ```
151
+ - Save Data (always use root if not then save partial data)
152
+ ```javascript
153
+ >>> from kmisc import kDict
154
+ >>> kDict.kDict._dfile_='<dict file name>'
155
+ >>> root.Save()
156
+ ```
157
+ - Load Data (always use root if not then load at key)
158
+ ```javascript
159
+ >>> from kmisc import kDict
160
+ >>> kDict.kDict._dfile_='<dict file name>'
161
+ >>> root.Load()
162
+ ```
163
+ # MISC functions
164
+ Useful commands
165
+
166
+ Type : Similar as isinstance(<obj>,(chk,type))
167
+ ```javascript
168
+ >>> import kmisc as km
169
+ >>> km.Type('abc','str')
170
+ >>> True
171
+ >>> km.Type('abc',str)
172
+ >>> True
173
+ ```
174
+
175
+ Copy: copy data for list,dict,str,int,tuple...
176
+
177
+ ```javascript
178
+ >>> new_data=Copy(<data>)
179
+ ```
180
+
181
+ Join : Similar as os.path().join()
182
+ Joining data of bytes,string,....
183
+
184
+ Next: Get data from list,tuple,dict,string
185
+
186
+ Delete : Delete data in list,tuple,dict,str
187
+
188
+ COLOR : class for console,html color string
189
+
190
+ FIND : find string or format data
191
+
192
+ DIFF : diff between data
193
+
194
+ LIST : handle list()
195
+
196
+ STR: handle string
197
+
198
+ TIME : handle time formats
199
+
200
+ SHELL : handle command run,progress,....
201
+
202
+ BYTES: handle byte data
203
+
204
+ CONVERT : data converter
205
+
206
+ MAC : handle mac address
207
+
208
+ VERSION : handle version
209
+
210
+ IP : handle IP address
211
+
212
+ GET: getting data from anywhere
213
+
214
+ IS: check the data
215
+
216
+ LOG: handle log data
217
+
218
+ HOST: handle Host Information
219
+
220
+ FILE: handle File (Read/Write)
221
+
222
+ WEB: handle web protocol data
223
+
224
+ EMAIL: handle email data
225
+
226
+ ANSI : handle hansi data
227
+
228
+ Multiprocessor : handle multi processing
229
+
230
+ FUNCTION: handle function information
231
+
232
+ SCREEN: handle ipmi SOL
233
+
234
+ CLI : handle Command Line Interface
235
+
236
+ Cut: cutting string to format
237
+
238
+ Get: Getting data from anywhere
239
+
240
+ Replace : replace string data
241
+
242
+ Insert : add data
243
+
244
+ Update: update data
245
+
246
+ printf : similar as printf in c
247
+
248
+ sprintf : similar as sprintf in c
249
+
250
+ Sort : sorting data
251
+
252
+ findXML : Get XML data
253
+
254
+ cat : similar as linux cat command
255
+
256
+ ls : similar as linux ls command
257
+
258
+ IsSame: check both data is same or not
259
+
260
+ etc...
261
+
262
+ Platform: UNKNOWN
263
+ Classifier: Programming Language :: Python :: 2
264
+ Classifier: Programming Language :: Python :: 3
265
+ Classifier: License :: OSI Approved :: MIT License
266
+ Classifier: Operating System :: OS Independent
267
+ Description-Content-Type: text/markdown
268
+ License-File: LICENSE
@@ -375,7 +375,7 @@ class FILE:
375
375
 
376
376
  def FileType(self,filename,default=False):
377
377
  if not isinstance(filename,str) or not os.path.isfile(filename): return default
378
- Import('import magic')
378
+ Import('import magic',install_name='python-magic')
379
379
  aa=magic.from_buffer(open(filename,'rb').read(2048))
380
380
  if aa: return aa.split()[0].lower()
381
381
  return 'unknown'
@@ -1260,176 +1260,176 @@ class LOG:
1260
1260
  else:
1261
1261
  self.log_file(log_str)
1262
1262
 
1263
- class HOST:
1264
- def __init__(self):
1265
- pass
1266
-
1267
- def Name(self):
1268
- return socket.gethostname()
1269
-
1270
- def DefaultRouteDev(self,default=None,gw=None):
1271
- for ii in Split(cat('/proc/net/route',no_edge=True),'\n',default=[]):
1272
- ii_a=ii.split()
1273
- #if len(ii_a) > 8 and '00000000' == ii_a[1] and '00000000' == ii_a[7]: return ii_a[0]
1274
- if len(ii_a) < 4 or ii_a[1] != '00000000' or not int(ii_a[3], 16) & 2:
1275
- #If not default route or not RTF_GATEWAY, skip it
1276
- continue
1277
- if gw:
1278
- if IsSame(socket.inet_ntoa(struct.pack("<L", int(ii_a[2], 16))),gw):
1279
- return ii_a[0]
1280
- else:
1281
- return ii_a[0]
1282
- return default
1283
-
1284
- def DefaultRouteIp(self,default=None):
1285
- for ii in Split(cat('/proc/net/route',no_edge=True),'\n'):
1286
- ii_a=ii.split()
1287
- if len(ii_a) < 4 or ii_a[1] != '00000000' or not int(ii_a[3], 16) & 2:
1288
- #If not default route or not RTF_GATEWAY, skip it
1289
- continue
1290
- return socket.inet_ntoa(struct.pack("<L", int(ii_a[2], 16)))
1291
- return default
1292
-
1293
- def Ip(self,ifname=None,mac=None,default=None):
1294
- if IsNone(ifname):
1295
- if IsNone(mac) : mac=self.Mac()
1296
- ifname=self.DevName(mac)
1297
-
1298
- if ifname:
1299
- if not os.path.isdir('/sys/class/net/{}'.format(ifname)):
1300
- return default
1301
- try:
1302
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1303
- return socket.inet_ntoa(fcntl.ioctl(
1304
- s.fileno(),
1305
- 0x8915, # SIOCGIFADDR
1306
- struct.pack('256s', ifname[:15])
1307
- )[20:24])
1308
- except:
1309
- try:
1310
- return os.popen('ip addr show {}'.format(ifname)).read().split("inet ")[1].split("/")[0]
1311
- except:
1312
- return default
1313
- return socket.gethostbyname(socket.gethostname())
1314
-
1315
- def IpmiIp(self,default=None):
1316
- rt=rshell('''ipmitool lan print 2>/dev/null| grep "IP Address" | grep -v Source | awk '{print $4}' ''')
1317
- if rt[0]:return rt[1]
1318
- return default
1319
-
1320
- def IpmiMac(self,default=None):
1321
- rt=rshell(""" ipmitool lan print 2>/dev/null | grep "MAC Address" | awk """ + """ '{print $4}' """)
1322
- if rt[0]:return rt[1]
1323
- return default
1324
-
1325
- def Mac(self,ip=None,dev=None,default=None,ifname=None):
1326
- #if dev is None and ifname: dev=ifname
1327
- if IsNone(dev) and ifname: dev=ifname
1328
- if IpV4(ip):
1329
- dev_info=self.NetDevice()
1330
- for dev in dev_info.keys():
1331
- if self.Ip(ifname=dev) == ip:
1332
- return dev_info[dev]['mac']
1333
- #ip or anyother input of device then getting default gw's dev
1334
- if IsNone(dev): dev=self.DefaultRouteDev()
1335
- if dev:
1336
- try:
1337
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1338
- info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', Bytes(dev[:15])))
1339
- return Join(['%02x' % ord(char) for char in Str(info[18:24])],symbol=':')
1340
- except:
1341
- return default
1342
- #return ':'.join(['{:02x}'.format((uuid.getnode() >> ele) & 0xff) for ele in range(0,8*6,8)][::-1])
1343
- return MacV4('%012x' % uuid.getnode())
1344
-
1345
- def DevName(self,mac=None,default=None):
1346
- if IsNone(mac):
1347
- mac=self.Mac()
1348
- net_dir='/sys/class/net'
1349
- if isinstance(mac,str) and os.path.isdir(net_dir):
1350
- dirpath,dirnames,filenames = list(os.walk(net_dir))[0]
1351
- for dev in dirnames:
1352
- fmac=cat('{}/{}/address'.format(dirpath,dev),no_edge=True)
1353
- if isinstance(fmac,str) and fmac.strip().lower() == mac.lower():
1354
- return dev
1355
- return default
1356
-
1357
- def Info(self):
1358
- return {
1359
- 'host_name':self.Name(),
1360
- 'host_ip':self.Ip(),
1361
- 'host_mac':self.Mac(),
1362
- 'ipmi_ip':self.IpmiIp(),
1363
- 'ipmi_mac':self.IpmiMac(),
1364
- }
1365
-
1366
- def NetDevice(self,name=None,default=False):
1367
- def _dev_info_(path,name):
1368
- drv=ls('{}/{}/device/driver/module/drivers'.format(path,name))
1369
- if drv is False:
1370
- drv='unknown'
1371
- else:
1372
- drv=drv[0].split(':')[1]
1373
- return {
1374
- 'mac':cat('{}/{}/address'.format(path,name),no_end_newline=True),
1375
- 'duplex':cat('{}/{}/duplex'.format(path,name),no_end_newline=True,file_only=False),
1376
- 'mtu':cat('{}/{}/mtu'.format(path,name),no_end_newline=True),
1377
- 'state':cat('{}/{}/operstate'.format(path,name),no_end_newline=True),
1378
- 'speed':cat('{}/{}/speed'.format(path,name),no_end_newline=True,file_only=False),
1379
- 'id':cat('{}/{}/ifindex'.format(path,name),no_end_newline=True),
1380
- 'driver':drv,
1381
- 'drv_ver':cat('{}/{}/device/driver/module/version'.format(path,name),no_end_newline=True,file_only=False,default=''),
1382
- }
1383
-
1384
-
1385
- net_dev={}
1386
- net_dir='/sys/class/net'
1387
- if os.path.isdir(net_dir):
1388
- dirpath,dirnames,filenames = list(os.walk(net_dir))[0]
1389
- if name:
1390
- if name in dirnames:
1391
- net_dev[name]=_dev_info_(dirpath,name)
1392
- else:
1393
- for dev in dirnames:
1394
- net_dev[dev]=_dev_info_(dirpath,dev)
1395
- return net_dev
1396
- return default
1397
-
1398
- def Alive(self,ip,keep=20,interval=3,timeout=1800,default=False,log=None,cancel_func=None):
1399
- time=TIME()
1400
- run_time=time.Int()
1401
- if IpV4(ip):
1402
- if log:
1403
- log('[',direct=True,log_level=1)
1404
- while True:
1405
- if time.Out(timeout_sec):
1406
- if log:
1407
- log(']\n',direct=True,log_level=1)
1408
- return False,'Timeout monitor'
1409
- if IsBreak(cancel_func):
1410
- if log:
1411
- log(']\n',direct=True,log_level=1)
1412
- return True,'Stopped monitor by Custom'
1413
- if ping(ip,cancel_func=cancel_func):
1414
- if (time.Int() - run_time) > keep:
1415
- if log:
1416
- log(']\n',direct=True,log_level=1)
1417
- return True,'OK'
1418
- if log:
1419
- log('-',direct=True,log_level=1)
1420
- else:
1421
- run_time=time.Int()
1422
- if log:
1423
- log('.',direct=True,log_level=1)
1424
- time.Sleep(interval)
1425
- if log:
1426
- log(']\n',direct=True,log_level=1)
1427
- return False,'Timeout/Unknown issue'
1428
- return default,'IP format error'
1429
-
1430
- def Ping(self,ip,keep_good=10,timeout=3600):
1431
- if IpV4(ip):
1432
- return ping(ip,keep_good=keep_good,timeout=timeout)
1263
+ #class HOST:
1264
+ # def __init__(self):
1265
+ # pass
1266
+ #
1267
+ # def Name(self):
1268
+ # return socket.gethostname()
1269
+ #
1270
+ # def DefaultRouteDev(self,default=None,gw=None):
1271
+ # for ii in Split(cat('/proc/net/route',no_edge=True),'\n',default=[]):
1272
+ # ii_a=ii.split()
1273
+ # #if len(ii_a) > 8 and '00000000' == ii_a[1] and '00000000' == ii_a[7]: return ii_a[0]
1274
+ # if len(ii_a) < 4 or ii_a[1] != '00000000' or not int(ii_a[3], 16) & 2:
1275
+ # #If not default route or not RTF_GATEWAY, skip it
1276
+ # continue
1277
+ # if gw:
1278
+ # if IsSame(socket.inet_ntoa(struct.pack("<L", int(ii_a[2], 16))),gw):
1279
+ # return ii_a[0]
1280
+ # else:
1281
+ # return ii_a[0]
1282
+ # return default
1283
+ #
1284
+ # def DefaultRouteIp(self,default=None):
1285
+ # for ii in Split(cat('/proc/net/route',no_edge=True),'\n'):
1286
+ # ii_a=ii.split()
1287
+ # if len(ii_a) < 4 or ii_a[1] != '00000000' or not int(ii_a[3], 16) & 2:
1288
+ # #If not default route or not RTF_GATEWAY, skip it
1289
+ # continue
1290
+ # return socket.inet_ntoa(struct.pack("<L", int(ii_a[2], 16)))
1291
+ # return default
1292
+ #
1293
+ # def Ip(self,ifname=None,mac=None,default=None):
1294
+ # if IsNone(ifname):
1295
+ # if IsNone(mac) : mac=self.Mac()
1296
+ # ifname=self.DevName(mac)
1297
+ #
1298
+ # if ifname:
1299
+ # if not os.path.isdir('/sys/class/net/{}'.format(ifname)):
1300
+ # return default
1301
+ # try:
1302
+ # s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1303
+ # return socket.inet_ntoa(fcntl.ioctl(
1304
+ # s.fileno(),
1305
+ # 0x8915, # SIOCGIFADDR
1306
+ # struct.pack('256s', ifname[:15])
1307
+ # )[20:24])
1308
+ # except:
1309
+ # try:
1310
+ # return os.popen('ip addr show {}'.format(ifname)).read().split("inet ")[1].split("/")[0]
1311
+ # except:
1312
+ # return default
1313
+ # return socket.gethostbyname(socket.gethostname())
1314
+ #
1315
+ # def IpmiIp(self,default=None):
1316
+ # rt=rshell('''ipmitool lan print 2>/dev/null| grep "IP Address" | grep -v Source | awk '{print $4}' ''')
1317
+ # if rt[0]:return rt[1]
1318
+ # return default
1319
+ #
1320
+ # def IpmiMac(self,default=None):
1321
+ # rt=rshell(""" ipmitool lan print 2>/dev/null | grep "MAC Address" | awk """ + """ '{print $4}' """)
1322
+ # if rt[0]:return rt[1]
1323
+ # return default
1324
+ #
1325
+ # def Mac(self,ip=None,dev=None,default=None,ifname=None):
1326
+ # #if dev is None and ifname: dev=ifname
1327
+ # if IsNone(dev) and ifname: dev=ifname
1328
+ # if IpV4(ip):
1329
+ # dev_info=self.NetDevice()
1330
+ # for dev in dev_info.keys():
1331
+ # if self.Ip(ifname=dev) == ip:
1332
+ # return dev_info[dev]['mac']
1333
+ # #ip or anyother input of device then getting default gw's dev
1334
+ # if IsNone(dev): dev=self.DefaultRouteDev()
1335
+ # if dev:
1336
+ # try:
1337
+ # s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1338
+ # info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', Bytes(dev[:15])))
1339
+ # return Join(['%02x' % ord(char) for char in Str(info[18:24])],symbol=':')
1340
+ # except:
1341
+ # return default
1342
+ # #return ':'.join(['{:02x}'.format((uuid.getnode() >> ele) & 0xff) for ele in range(0,8*6,8)][::-1])
1343
+ # return MacV4('%012x' % uuid.getnode())
1344
+ #
1345
+ # def DevName(self,mac=None,default=None):
1346
+ # if IsNone(mac):
1347
+ # mac=self.Mac()
1348
+ # net_dir='/sys/class/net'
1349
+ # if isinstance(mac,str) and os.path.isdir(net_dir):
1350
+ # dirpath,dirnames,filenames = list(os.walk(net_dir))[0]
1351
+ # for dev in dirnames:
1352
+ # fmac=cat('{}/{}/address'.format(dirpath,dev),no_edge=True)
1353
+ # if isinstance(fmac,str) and fmac.strip().lower() == mac.lower():
1354
+ # return dev
1355
+ # return default
1356
+ #
1357
+ # def Info(self):
1358
+ # return {
1359
+ # 'host_name':self.Name(),
1360
+ # 'host_ip':self.Ip(),
1361
+ # 'host_mac':self.Mac(),
1362
+ # 'ipmi_ip':self.IpmiIp(),
1363
+ # 'ipmi_mac':self.IpmiMac(),
1364
+ # }
1365
+ #
1366
+ # def NetDevice(self,name=None,default=False):
1367
+ # def _dev_info_(path,name):
1368
+ # drv=ls('{}/{}/device/driver/module/drivers'.format(path,name))
1369
+ # if drv is False:
1370
+ # drv='unknown'
1371
+ # else:
1372
+ # drv=drv[0].split(':')[1]
1373
+ # return {
1374
+ # 'mac':cat('{}/{}/address'.format(path,name),no_end_newline=True),
1375
+ # 'duplex':cat('{}/{}/duplex'.format(path,name),no_end_newline=True,file_only=False),
1376
+ # 'mtu':cat('{}/{}/mtu'.format(path,name),no_end_newline=True),
1377
+ # 'state':cat('{}/{}/operstate'.format(path,name),no_end_newline=True),
1378
+ # 'speed':cat('{}/{}/speed'.format(path,name),no_end_newline=True,file_only=False),
1379
+ # 'id':cat('{}/{}/ifindex'.format(path,name),no_end_newline=True),
1380
+ # 'driver':drv,
1381
+ # 'drv_ver':cat('{}/{}/device/driver/module/version'.format(path,name),no_end_newline=True,file_only=False,default=''),
1382
+ # }
1383
+ #
1384
+ #
1385
+ # net_dev={}
1386
+ # net_dir='/sys/class/net'
1387
+ # if os.path.isdir(net_dir):
1388
+ # dirpath,dirnames,filenames = list(os.walk(net_dir))[0]
1389
+ # if name:
1390
+ # if name in dirnames:
1391
+ # net_dev[name]=_dev_info_(dirpath,name)
1392
+ # else:
1393
+ # for dev in dirnames:
1394
+ # net_dev[dev]=_dev_info_(dirpath,dev)
1395
+ # return net_dev
1396
+ # return default
1397
+ #
1398
+ # def Alive(self,ip,keep=20,interval=3,timeout=1800,default=False,log=None,cancel_func=None):
1399
+ # time=TIME()
1400
+ # run_time=time.Int()
1401
+ # if IpV4(ip):
1402
+ # if log:
1403
+ # log('[',direct=True,log_level=1)
1404
+ # while True:
1405
+ # if time.Out(timeout_sec):
1406
+ # if log:
1407
+ # log(']\n',direct=True,log_level=1)
1408
+ # return False,'Timeout monitor'
1409
+ # if IsBreak(cancel_func):
1410
+ # if log:
1411
+ # log(']\n',direct=True,log_level=1)
1412
+ # return True,'Stopped monitor by Custom'
1413
+ # if ping(ip,cancel_func=cancel_func):
1414
+ # if (time.Int() - run_time) > keep:
1415
+ # if log:
1416
+ # log(']\n',direct=True,log_level=1)
1417
+ # return True,'OK'
1418
+ # if log:
1419
+ # log('-',direct=True,log_level=1)
1420
+ # else:
1421
+ # run_time=time.Int()
1422
+ # if log:
1423
+ # log('.',direct=True,log_level=1)
1424
+ # time.Sleep(interval)
1425
+ # if log:
1426
+ # log(']\n',direct=True,log_level=1)
1427
+ # return False,'Timeout/Unknown issue'
1428
+ # return default,'IP format error'
1429
+ #
1430
+ # def Ping(self,ip,keep_good=10,timeout=3600):
1431
+ # if IpV4(ip):
1432
+ # return ping(ip,keep_good=keep_good,timeout=timeout)
1433
1433
 
1434
1434
  class COLOR:
1435
1435
  def __init__(self,**opts):
@@ -2065,7 +2065,7 @@ def Decompress(data,mode='lz4',work_path='/tmp',del_org_file=False,file_info={})
2065
2065
 
2066
2066
  def FileType(filename,default=False):
2067
2067
  if not isinstance(filename,str) or not os.path.isfile(filename): return default
2068
- Import('import magic')
2068
+ Import('import magic',install_name='python-magic')
2069
2069
  aa=magic.from_buffer(open(filename,'rb').read(2048))
2070
2070
  if aa: return aa.split()[0].lower()
2071
2071
  return 'unknown'
@@ -2452,7 +2452,7 @@ def find_cdrom_dev(size=None):
2452
2452
  if os.path.isfile('{0}/device/model'.format(rrr)):
2453
2453
  with open('{0}/device/model'.format(rrr),'r') as fpp:
2454
2454
  model=fpp.read()
2455
- for ii in ['CDROM','DVD-ROM','DVD-RW']:
2455
+ for ii in ['CDROM','DVD-ROM','DVD-RW','File-Stor Gadget']: #File-Stor Gadget for OpenBMC's cdrom
2456
2456
  if ii in model:
2457
2457
  if IsNone(size):
2458
2458
  return '/dev/{0}'.format(dd)