42
#!/bin/python3
import os
os.chdir("/sys/class/hwmon")
def ezrd(file):
with open(file,"r") as f:
s=f.read()
return s.strip()
battery=""
for i in os.listdir():
if "bat" in ezrd(i+"/name").lower():
battery=i
break
if len(battery)==0: exit(1)
try: os.chdir(battery+"/device/")
except: exit(1)
n=0
def maxtally(c):
global n
if len(c)>n: n = len(c)
return c
def notDirLink(i):
return os.st.S_ISREG(i)
#return not (os.st.S_ISDIR(i) or os.st.S_ISLNK(i))
l=[maxtally(i) for i in os.listdir() if notDirLink(os.stat(i).st_mode)]
l.sort()
n=n+2
for i in l:
cont = ezrd(i)
if "\n" in cont: continue
print(i.rjust(n),cont,sep=": ")