power: add gpiod support for Arch Linux

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-09-15 18:09:20 -04:00
parent 776e0d6c90
commit e92da4c82c
1 changed files with 11 additions and 9 deletions

View File

@ -5,8 +5,8 @@
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
from __future__ import annotations from __future__ import annotations
import os
import sys import sys
import glob
import logging import logging
import json import json
import struct import struct
@ -30,17 +30,19 @@ from typing import (
) )
# Special handling for gpiod import # Special handling for gpiod import
HAS_GPIOD = True HAS_GPIOD = False
DIST_PATH = "/usr/lib/python3/dist-packages" PKG_PATHS = glob.glob("/usr/lib/python3*/dist-packages")
if os.path.exists(DIST_PATH): PKG_PATHS += glob.glob("/usr/lib/python3*/site-packages")
sys.path.insert(0, DIST_PATH) for pkg_path in PKG_PATHS:
sys.path.insert(0, pkg_path)
try: try:
import gpiod import gpiod
except ImportError: except ImportError:
HAS_GPIOD = False sys.path.pop(0)
sys.path.pop(0) else:
else: HAS_GPIOD = True
HAS_GPIOD = False sys.path.pop(0)
break
if TYPE_CHECKING: if TYPE_CHECKING:
from confighelper import ConfigHelper from confighelper import ConfigHelper