aboutsummaryrefslogtreecommitdiff
path: root/kawaii-term.py
blob: 3c81e9ed1e3b3e44378d765a67a092836a3196bb (plain)
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
import sys
import os
import re
if '--mem' in sys.argv:
  for line in os.popen('cat /proc/meminfo').read().split('\n'):
    if 'MemFree' in line:
      line = line.strip()
      # デフォルトではKB表現だから、メガバイトで表現する
      mem  = re.split(r'\s{1,}', line)[-2]
      mem  = 'Mem=%d MB'%(int(mem)//1000)
      print( mem )
      break

if '--vmstat' in sys.argv:
  buff = os.popen('vmstat').read().split('\n')
  keys = re.split(r'\s{1,}', buff[1])
  vals = re.split(r'\s{1,}', buff[2])
  obj  = dict( zip(keys, vals) )
  ucpu = '💻 ={0:03d}%'.format( int(obj['us']) )
  print( ucpu )

if '--disk' in sys.argv:
  buff =os.popen('df -hT').read().split('\n')
  # 末尾が/で終わるのが、ルートディレクトリ表示
  keys = re.split(r'\s{1,}', buff[0])
  vals = re.split(r'\s{1,}', list( filter(lambda x:len(x) != 0 and x[-1] == '/', buff[1:]) )[0] )
  obj  = dict(zip( keys, vals) )
  try:
    use  = obj['Use%']
  except KeyError:
    try:
      use = obj['使用']
    except KeyError:
      use = 'NaN'

    
  try:
    free = obj['Avail']
  except KeyError:
    try:
      free = obj['残り']
    except KeyError:
      free = 'NaN'

  result = 'DiskUse%={}, DiskAvail={}'.format(use, free)
  print(result)