1 ''' Read-only configuration database. '''    49 "Cannot import the yaml library. Please install the python3    50 yaml package, on many distributions known as python3-PyYAML. It is also    51 available as a pypi package at https://pypi.python.org/pypi/PyYAML.'''    59     ''' Return path added to current dir for __file__. '''    60     return os.path.join(os.path.dirname(os.path.abspath(__file__)), path)
    63 def _load_kerneldrivers(configdir):
    64     ''' Parse the kerneldrivers.yaml file, discard unavailable    68     with open(os.path.join(configdir, 
"kernel-drivers.yaml")) 
as f:
    69         cf = yaml.load(f.read())
    70     drivers = cf[
'drivers'].copy()
    71     for driver 
in cf[
'drivers']:
    72         if driver == 
'default':
    74         with open(
'/dev/null', 
'w') 
as f:
    76                 subprocess.check_output([config.MODINFO, driver],
    78             except subprocess.CalledProcessError:
    83 class ItemLookupError(Exception):
    84     """A lookup failed, either too namy or no matches found. """    89     ''' The configuration selected, and it's sources. '''    92     def __init__(self, cf=None):
   102             for key, value 
in cf.items():
   103                 setattr(self, key, value)
   107         ''' The possible note to display when selected. '''   109             return self.
config[
'note']
   115     ''' Reflects the *.yaml files in the configs/ directory. '''   117     def __init__(self, path=None, yamlpath=None):
   119         devel_path = _here(
'../../configs')
   120         installed_path = os.path.join(config.DATADIR, 
'lirc',
'configs')
   121         if path 
and os.path.exists(path):
   124             raise FileNotFoundError(path)
   125         elif os.path.exists(devel_path):
   126             configdir = devel_path
   127         elif os.path.exists(installed_path):
   128             configdir = installed_path
   130             raise FileNotFoundError(devel_path + 
':' + installed_path)
   134         with open(os.path.join(yamlpath, 
"confs_by_driver.yaml")) 
as f:
   135             cf = yaml.load(f.read())
   136         db[
'lircd_by_driver'] = cf[
'lircd_by_driver'].copy()
   137         db[
'lircmd_by_driver'] = cf[
'lircmd_by_driver'].copy()
   139         db[
'kernel-drivers'] = _load_kerneldrivers(configdir)
   140         db[
'drivers'] = db[
'kernel-drivers'].copy()
   141         with open(os.path.join(yamlpath, 
"drivers.yaml")) 
as f:
   142             cf = yaml.load(f.read())
   143         db[
'drivers'].update(cf[
'drivers'].copy())
   144         for key, d 
in db[
'drivers'].items():
   146             hint = d[
'device_hint']
   150             if hint.startswith(
'"') 
and hint.endswith(
'"'):
   152                 hint = hint.replace(
r'\"', 
"@$#!")
   153                 hint = hint.replace(
'"', 
'')
   154                 hint = hint.replace(
"@$#!", 
'"')
   155                 hint = hint.replace(
"\\\\", 
"\\")
   156             d[
'device_hint'] = hint
   159         for path 
in glob.glob(configdir + 
'/*.conf'):
   160             with open(path) 
as f:
   161                 cf = yaml.load(f.read())
   162             configs[cf[
'config'][
'id']] = cf[
'config']
   163         db[
'configs'] = configs
   168         ''' The kernel-drivers dictionary, drivers.yaml + kernel-drivers.yaml.   170         return self.
db[
'kernel-drivers']
   174         ''' The drivers dictionary, drivers.yaml + kernel-drivers.yaml. '''   175         return self.
db[
'drivers']
   179         ''' Return dict of parsed config/*.conf files, keyd by id. '''   180         return self.
db[
'configs']
   183         ''' Return the list of remotes suggested for a given driver. '''   184         if isinstance(driver, dict):
   185             driver = driver[
'id']
   187             return self.
db[
'lircd_by_driver'][driver]
   192         ''' Return list of lircmd.conf file for given driver or None. '''   193         if isinstance(driver, dict):
   194             driver = driver[
'id']
   196             return self.
db[
'lircmd_by_driver'][driver]
   201         ''' Return the driver (possibly None) suggested for a remote. '''   202         for driver, files 
in self.
db[
'lircd_by_driver'].items():
   204                 return self.
db[
'drivers'][driver]
   208         ''' Return item (a config) in configs where config[key] == value. '''   209         found = [c 
for c 
in self.
db[
'configs'].values()
   210                  if key 
in c 
and c[key] == value]
   213                 "find_config: Too many matches for %s, %s): " % (key, value)
   214                 + 
', '.join([c[
'id'] 
for c 
in found]))
   217                 "find_config: Nothing  found for %s, %s): " % (key, value))
   218         found = dict(found[0])
   219         if 'device_hint' not in found:
   221                 found[
'device_hint'] = \
   222                     self.
db[
'drivers'][found[
'driver']][
'device_hint']
   224                 found[
'device_hint'] = \
   225                     self.
db[
'kernel-drivers'][found[
'driver']][
'device_hint']
 lircd_conf
Substituted data from driver. 
def driver_by_remote(self, remote)
Return the driver (possibly None) suggested for a remote. 
def kernel_drivers(self)
The kernel-drivers dictionary, drivers.yaml + kernel-drivers.yaml. 
def drivers(self)
The drivers dictionary, drivers.yaml + kernel-drivers.yaml. 
A lookup failed, either too namy or no matches found. 
modprobe
Substituted data from driver. 
def find_config(self, key, value)
Return item (a config) in configs where config[key] == value. 
label
Name of lircmd.conf file. 
def note(self)
The possible note to display when selected. 
Reflects the *.yaml files in the configs/ directory. 
lircmd_conf
Name of lircd.conf file. 
def remotes_by_driver(self, driver)
Return the list of remotes suggested for a given driver. 
def configs(self)
Return dict of parsed config/*.conf files, keyd by id. 
def lircmd_by_driver(self, driver)
Return list of lircmd.conf file for given driver or None. 
modinit
Read-only config dict in db. 
config
Read-only driver dict in db.