File: data2hwdb

package info (click to toggle)
lirc 0.10.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 8,364 kB
  • sloc: ansic: 26,717; cpp: 9,066; sh: 5,521; python: 4,362; makefile: 1,034; xml: 63
file content (115 lines) | stat: -rw-r--r-- 3,220 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
''' Create the legacy hwdb table using data in config files '''

import glob
import os
import sys
import yaml

import database

HEADER = '''
# LIRC - Hardware DataBase
#
# THIS FILE IS DEPRECATED AND WILL BE REMOVED IN NEXT RELEASE.
#
# This is a generated file. Do not edit.
#
# The file lists all the remote controls supported by LIRC
# in a parseable form. It's legacy file kept for compatiblity.
# The current yaml files configs/*.conf should be a better
# source in most cases.
#
# The format is:
#
# [remote controls type]
# description;driver;lirc driver;HW_DEFAULT;lircd_conf;
#
# The HW_DEFAULT field is always empty.
#
#

'''

MENUS = {'home_brew': 'Home-brew serial and parallel devices',
         'irda': 'IRDA/Cir hardware',
         'other': 'Other (MIDI, Bluetooth, udp, etc.)',
         'other_serial': 'Other serial port devices',
         'pda': 'PDAs',
         'soundcard': 'Home-brew (soundcard input)',
         'tv_card': 'TV cards',
         'usb': 'USB devices'
}


def here(path):
    ' Return path added to current dir for __file__. '
    return os.path.join(os.path.dirname(os.path.abspath(__file__)), path)


def _add_submenu(menu, configs, db):
    ''' Return all entries for a submenu as a string of table rows. '''

    def getit(remote,  what, driver,  _default=''):
        ''' Get a value from a remote, use default if not existing. '''
        try:
            value = remote[what]
        except KeyError:
            if not driver:
                return _default
            try:
                value = driver[what]
            except KeyError:
                return _default
        if isinstance(value, list):
            return ' '.join(value)
        return value

    s = '[' + MENUS[menu] + ']\n'
    for remote in configs:
        try:
            driver = db.drivers[remote['driver']]
        except KeyError:
            driver = None
        if getit(remote, 'driver', driver)  == "none":
            continue
        s += getit(remote, 'label', driver) + ';'
        s += getit(remote, 'modinit', driver).replace(';', ',') + ';'
        s += getit(remote, 'driver', driver) + ';;'
        files = [getit(remote, 'lircd_conf', driver),
                 getit(remote, 'lircmd.conf', driver)]
        remotes = db.remotes_by_driver(driver)
        if remotes:
            files.extend(remotes)
        files = [f for f in files if f]
        s += ' '.join(files).replace('run_select_any_config', '') + ';\n'
    return s

def main():
    yamldir = None
    if len(sys.argv) == 3:
        configdir = sys.argv[1]
        yamldir = sys.argv[2]
    elif len(sys.argv) == 2:
        configdir = sys.argv[1]
    elif len(sys.argv) == 1:
        configdir = None
    else:
        print("Usage: data2hwd [configuration directory]")
        sys.exit(1)

    db = database.Database(configdir, yamldir)
    print(HEADER)
    for menu in MENUS.keys():
        try:
            menuconfigs = [cf for cf in db.configs.values()
                           if cf['menu'] == menu]
            print(_add_submenu(menu, menuconfigs, db))
        except KeyError:
            print("No menu in " + db.configs['id'])


if __name__ == '__main__':
    main()


# vim: set expandtab ts=4 sw=4: