There are still two problems right now.
First
snap connect energy-tools:hardware-observe :hardware-observe
can fix the problem of dmidecode
with root permission, i.e. sudo energy-tools
.
(Solved) I need make a store-request post for the auto connection of hardware-observe.
Second
If I execute the command by sudo energy-tools
, the root can not access the normal user’s X environment.
But if I execute energy-tools
with normal, it can access the normal user’s X environment without any problem.
This program will need both information from dmidecode
and xrandr
. I made the following code snippet to demonstrate the problem.
import os
import subprocess
if os.geteuid() == 0:
slot = subprocess.check_output("dmidecode -t 16 | grep 'Devices:' | awk -F': ' '{print $2}'", shell=True, encoding='utf8').split('\n')
print(slot)
for size in subprocess.check_output("dmidecode -t 17 | grep 'Size:.*MB' | awk '{print $2}'", shell=True, encoding='utf8').split('\n'):
print(size)
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
screen = Gdk.Screen.get_default()
major = screen.get_primary_monitor()
width_mm = screen.get_monitor_width_mm(major)
height_mm = screen.get_monitor_height_mm(major)
print(width_mm)
print(height_mm)
(width, height) = subprocess.check_output("xrandr | grep 'connected primary' | sed 's/.*connected primary \\([0-9]*\\)x\\([0-9]*\\).*/\\1 \\2/'", shell=True, encoding='utf8').strip().split(' ')
print(width)
print(height)
else:
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
screen = Gdk.Screen.get_default()
major = screen.get_primary_monitor()
width_mm = screen.get_monitor_width_mm(major)
height_mm = screen.get_monitor_height_mm(major)
print(width_mm)
print(height_mm)
(width, height) = subprocess.check_output("xrandr | grep 'connected primary' | sed 's/.*connected primary \\([0-9]*\\)x\\([0-9]*\\).*/\\1 \\2/'", shell=True, encoding='utf8').strip().split(' ')
print(width)
print(height)
slot = subprocess.check_output("dmidecode -t 16 | grep 'Devices:' | awk -F': ' '{print $2}'", shell=True, encoding='utf8').split('\n')
print(slot)
for size in subprocess.check_output("dmidecode -t 17 | grep 'Size:.*MB' | awk '{print $2}'", shell=True, encoding='utf8').split('\n'):
print(size)
$ energy-tools
527
296
1920
1080
/sys/firmware/dmi/tables/smbios_entry_point: Permission denied
/dev/mem: Permission denied
[’’]
/sys/firmware/dmi/tables/smbios_entry_point: Permission denied
/dev/mem: Permission denied
$ sudo energy-tools
mkdir: cannot create directory ‘/run/user/0’: Permission denied
[‘2’, ‘’]
8192
8192
No protocol specified
Unable to init server: Could not connect: Connection refused
Traceback (most recent call last):
File “/snap/energy-tools/x16/bin/energy-tools”, line 42, in
major = screen.get_primary_monitor()
AttributeError: ‘NoneType’ object has no attribute ‘get_primary_monitor’