예제 #1
0
파일: i3bar.py 프로젝트: eXenon/dotfiles
def blockify_cpu():
  """ Print the CPU load average and temperature """
  
  block = Powerblock("cpu")

  cpuload = executor.run("uptime | awk -F'[a-z]:' '{ print $2}'")[0]
  oneminload = float(cpuload.split(",")[0] + "." + cpuload.split(",")[1])
  cputemp = executor.run("cat /sys/class/thermal/thermal_zone7/temp")[0]
  temp = int(cputemp) / 1000
  
  if oneminload > 3 or temp > 80:
    block.set_urgent()

  block.set_text(str(oneminload) + "/" + str(temp))
  return block
예제 #2
0
파일: i3bar.py 프로젝트: eXenon/dotfiles
def blockify_battery():
  """ Print the current battery level. """

  block = Powerblock('battery')

  acpi = executor.run('acpi -b')[0]
  battery = re.search('\d*%', acpi).group(0)
  battery_int = int(battery[:-1])
  is_charging = bool(re.search('Charging|Unknown', acpi))

  block.set_text(battery)
  if battery_int < 40 and not is_charging:
    block.set_hl()
  elif battery_int < 20 and not is_charging:
    block.set_urgent()


  return block
예제 #3
0
파일: i3bar.py 프로젝트: eXenon/dotfiles
def blockify_internet():
  """ Prints primary IP and ping time to 8.8.8.8.
      Alerts when ping is high or IP not found.
  """
  block = Powerblock("internet")

  pingtime = executor.run("fping -C 1 -t 200 8.8.8.8")[0]
  ip = executor.run("ip a | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'")[0]
  if len(ip) < 4:
    block.set_urgent()
    block.set_text("NO IP")
  else:
    if len(pingtime) < 4:
      block.set_text(ip + " >200 ms")
      block.set_hl()
    else:
      pingtime = float(pingtime.split(" ")[5])
      if pingtime > 500:
        block.set_hl()
      elif pingtime > 1000:
        block.set_urgent()
      block.set_text(ip + " " + str(pingtime) + " ms")
  
  return block