Skip to content

Commit

Permalink
device type added and fix service debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed May 9, 2024
1 parent dc23d08 commit ba4ba03
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def usage():
elif sys.argv[1] == "get":
ppm = "/run/user/{}/ppm".format(os.getuid())
if not os.path.exists(ppm):
os.mkdir(ppm)
os.makedirs(ppm)
ppm = ppm+"/"+str(os.getpid())
if not os.path.exists(ppm):
os.mkfifo(ppm)
Expand All @@ -55,6 +55,7 @@ def usage():
print("[info]")
print("acpi-supported={}".format(data["info"]["acpi-supported"]))
print("laptop={}".format(data["info"]["laptop"]))
print("type={}".format(data["info"]["type"]))
print("virtual-machine={}".format(data["info"]["virtual-machine"]))
print("live={}".format(data["info"]["live"]))
print("oem={}".format(data["info"]["oem"]))
Expand Down
48 changes: 46 additions & 2 deletions src/common/detect.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
import os
from file import readfile

def get_device_type():
chassis_names = [
"Other",
"Unknown",
"Desktop",
"Low Profile Desktop",
"Pizza Box",
"Mini Tower",
"Tower",
"Portable",
"Laptop",
"Notebook",
"Hand Held",
"Docking Station",
"All in One",
"Sub Notebook",
"Space-saving",
"Lunch Box",
"Main Server Chassis",
"Expansion Chassis",
"SubChassis",
"Bus Expansion Chassis",
"Peripheral Chassis",
"RAID Chassis",
"Rack Mount Chassis",
"Sealed-case PC",
"Multi-system chassis",
"Compact PCI",
"Advanced TCA",
"Blade",
"Tablet",
"Convertible",
"Detachable",
"IoT Gateway",
"Embedded PC",
"Mini PC",
"Stick PC"
]
type = int(readfile("/sys/devices/virtual/dmi/id/chassis_type"))
print(chassis_names[type])
if type < len(chassis_names):
return chassis_names[type]
return chassis_names[1]

def is_laptop():
if os.path.isdir("/proc/pmu"):
return "Battery" in open("/proc/pmu/info","r").read()
if os.path.exists("/sys/devices/virtual/dmi/id/chassis_type"):
type = open("/sys/devices/virtual/dmi/id/chassis_type","r").read().strip()
type = readfile("/sys/devices/virtual/dmi/id/chassis_type")
return type in ["8", "9", "10", "11"]
for dev in os.listdir("/sys/class/power_supply"):
if "BAT" in dev:
Expand Down Expand Up @@ -61,4 +105,4 @@ def is_acpi_supported():
return acpi_support

def is_oem_available():
return os.path.exists("/sys/firmware/acpi/MSDM")
return os.path.exists("/sys/firmware/acpi/MSDM")
3 changes: 2 additions & 1 deletion src/service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
try:
listen(main)
except Exception as e:
log(traceback.format_exc())
print("aaa")
log(traceback.format_exc(e))
1 change: 1 addition & 0 deletions src/service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def main(data):
udata["info"]["acpi-supported"] = is_acpi_supported()
udata["info"]["laptop"] = is_laptop()
udata["info"]["virtual-machine"] = is_virtual_machine()
udata["info"]["type"] = get_device_type()
udata["info"]["live"] = is_live()
udata["info"]["oem"] = is_oem_available()
if "show" in data:
Expand Down

0 comments on commit ba4ba03

Please sign in to comment.