1

I would like to get group of directory. I tried answers from this question, but neither work for me.

If I list file trough terminal I get correct group gpio.

$ ls -l /sys/class/gpio/
total 0
--w--w---- 1 root gpio 4096 Feb 26 15:07 export
lrwxrwxrwx 1 root gpio    0 Feb 26 15:07 gpio248 -> ../../devices/6000d000.gpio/gpiochip0/gpio/gpio248
lrwxrwxrwx 1 root gpio    0 Feb 26 14:19 gpio250 -> ../../devices/6000d000.gpio/gpiochip0/gpio/gpio250
lrwxrwxrwx 1 root gpio    0 Feb 26 14:35 gpio252 -> ../../devices/6000d000.gpio/gpiochip0/gpio/gpio252
lrwxrwxrwx 1 root gpio    0 Feb 26 13:45 gpiochip0 -> ../../devices/6000d000.gpio/gpio/gpiochip0
lrwxrwxrwx 1 root gpio    0 Feb 26 13:45 gpiochip504 -> ../../devices/7000d000.i2c/i2c-4/4-003c/max77620-gpio/gpio/gpiochip504
--w--w---- 1 root gpio 4096 Feb 26 13:58 unexport

If I do a same with a python, I get correct user and wrong group.

>>> import pathlib
>>> src = "/sys/class/gpio/gpio252"
>>> 
>>> pth = pathlib.Path(src)
>>> 
>>> pth.group()
'root'
>>> pth.owner()
'root'
>>> 

I tried it on Python version 3.6.9 and 3.9.2, both with and without virtual environment.

I have a UDEV rule that corrects a group of newly created gpio's with chown command. But it takes some time, so I want to wait for it in my code, but I do not want use a fixed timer.

Thank You any advice

Tony762
  • 15
  • 1
  • 6

1 Answers1

0

/sys/class/gpio/gpio252 is a symlink to a different file and python returns the information from the file and not the symlink.

check the group of:

ls -ld /sys/devices/6000d000.gpio/gpiochip0/gpio/gpio252
DerMaddi
  • 649
  • 2
  • 12
  • Thank You, this saved my day. Udev rule also change group of file 'value' inside gpio252 so I check it instead. – Tony762 Mar 02 '21 at 09:41