kmisc 2.1.105__py3-none-any.whl → 2.1.107__py3-none-any.whl

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/__init__.py CHANGED
@@ -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'
@@ -2091,21 +2091,6 @@ def Decompress(data,mode='lz4',work_path='/tmp',del_org_file=False,file_info={})
2091
2091
  if del_org_file: os.unline(data)
2092
2092
  return True
2093
2093
 
2094
- def ls(dirname,opt=''):
2095
- if not IsNone(dirname) and os.path.isdir(dirname):
2096
- dirlist=[]
2097
- dirinfo_a=list(os.walk(dirname))
2098
- if not IsNone(dirinfo_a):
2099
- dirinfo=dirinfo_a[0]
2100
- if opt == 'd':
2101
- dirlist=Get(dirinfo,1)
2102
- elif opt == 'f':
2103
- dirlist=Get(dirinfo,2)
2104
- else:
2105
- dirlist=Get(dirinfo,1)+Get(dirinfo,2)
2106
- return dirlist
2107
- return False
2108
-
2109
2094
  def append(src,addendum):
2110
2095
  type_src=type(src)
2111
2096
  type_data=type(addendum)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kmisc
3
- Version: 2.1.105
3
+ Version: 2.1.107
4
4
  Summary: Enginering useful library
5
5
  Home-page: https://github.com/kagepark/kmisc
6
6
  Author: Kage Park
@@ -0,0 +1,6 @@
1
+ kmisc/__init__.py,sha256=0xSnnXyiYlmXCKPh5J7NDzoL1NhMKCoqCo70qAtNOr4,134964
2
+ kmisc-2.1.107.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
3
+ kmisc-2.1.107.dist-info/METADATA,sha256=0ej8gYUbnqQbePcRMkk0DmONo6cOM69XTViFuTENo54,5523
4
+ kmisc-2.1.107.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
5
+ kmisc-2.1.107.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
6
+ kmisc-2.1.107.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- kmisc/__init__.py,sha256=3gWFv6ocpxSAvoKhEtlRrRi-2OuEoqJGWwsD1tjlKbE,135180
2
- kmisc-2.1.105.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
3
- kmisc-2.1.105.dist-info/METADATA,sha256=HgKzOervsGcaNI_nLgSwdNnpNGQShNJ_6pVimjBI8mg,5523
4
- kmisc-2.1.105.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
5
- kmisc-2.1.105.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
6
- kmisc-2.1.105.dist-info/RECORD,,