hi,
the lircd.conf that comes with the ubuntu package, does not contain any
key code, but only an include statement to the conf suitable for the
remote control selected during the package setup. the makelircrc helper
of freevo 1.x does not follow such an include.
attached is a diff to revision 10553 that fixes that.
while reading and partially rewriting the code i changed some variable
names for imo better understanding, sorry if this is not welcome. i need
that :)
also from what i understand about the code, that "select the one best
matching" begin codes section feature seems to be "in there", but there
is no way of using it since the commandline argument is never parsed and
use_pos always stays None... or did i miss something?
anyway, it is definetly not working after my changes. there is however a
nice warning message now telling the user what happens...
hope someone finds this useful, br
Florian
Index: freevo/src/helpers/makelircrc.py
===================================================================
--- freevo/src/helpers/makelircrc.py (revision 10553)
+++ freevo/src/helpers/makelircrc.py (working copy)
@@ -36,25 +36,11 @@
import sys
import os
-if len(sys.argv)>1 and sys.argv[1] in ('-h', '--help'):
- print 'script to write the freevo lircrc file'
- print 'usage: makelircrc [-w] [section_index] [button=comand]'
- print
- print 'The -w will write the settings to %s' % config.LIRCRC
- print 'If this is not the file the information should be written to, set'
- print 'LIRCRC in your local_conf.py to the correct filename. If the file'
- print 'exists, it will be overwritten.'
- print
- print 'If started with no options, this script will print the suggested
mapping'
- print 'and a list of buttons not used right now and a list of events in
Freevo'
- print 'without a button. You can either change EVENTS in local_conf.py or
define'
- print 'a mapping on your own.'
- print
- sys.exit(0)
+iscode = re.compile('^[ \t]*([^ #\t]*)[ \t]*(0x[0-9A-Fa-f]*)').match
+# config list to start with
+lircdconf_list = [ '/etc/lircd.conf', '/etc/lirc/lircd.conf' ]
-iscode = re.compile('^[ \t]*([^ #\t]*)[ \t]*(0x[0-9A-Fa-f]*)').match
-
needed = []
mapping = []
unused = []
@@ -75,6 +61,58 @@
'RECORD' : 'REC',
}
+
+def findIncludes(name):
+ """returns a list of files included in lircd.conf via the 'include'
keyword"""
+ list = []
+ file = open(name, 'r')
+ for line in file.readlines():
+ if line.find('include ') != -1:
+ list.append(line.split()[1])
+ return list
+
+def parseFile(name):
+ found_codes = 0
+ file = open(name, 'r')
+ for line in file.readlines():
+ # find the codes section
+ if line.find('begin codes') != -1:
+ found_codes += 1
+ # continue in the codes section
+ if found_codes > 0:
+ match = iscode(line)
+ if match:
+ lirc_button = match.groups()[0]
+ freevo_button = lirc_button.upper()
+ if freevo_button in needed:
+ needed.remove(freevo_button)
+ mapping.append((freevo_button, lirc_button))
+ elif alternatives.has_key(freevo_button) and
alternatives[freevo_button] in needed:
+ needed.remove(alternatives[freevo_button])
+ mapping.append((alternatives[freevo_button], lirc_button))
+ else:
+ unused.append(lirc_button)
+ mapping.append((freevo_button, lirc_button))
+ file.close()
+ return found_codes
+
+# argument parsing
+if len(sys.argv)>1 and sys.argv[1] in ('-h', '--help'):
+ print 'script to write the freevo lircrc file'
+ print 'usage: makelircrc [-w] [section_index] [button=comand]'
+ print
+ print 'The -w will write the settings to %s' % config.LIRCRC
+ print 'If this is not the file the information should be written to, set'
+ print 'LIRCRC in your local_conf.py to the correct filename. If the file'
+ print 'exists, it will be overwritten.'
+ print
+ print 'If started with no options, this script will print the suggested
mapping'
+ print 'and a list of buttons not used right now and a list of events in
Freevo'
+ print 'without a button. You can either change EVENTS in local_conf.py or
define'
+ print 'a mapping on your own.'
+ print
+ sys.exit(0)
+
for type in config.EVENTS:
for button in config.EVENTS[type]:
if not button in needed:
@@ -82,36 +120,28 @@
write_option = False
use_pos = None
+pos = 0
for arg in sys.argv[1:]:
if arg == '-w':
write_option = True
-if os.path.exists('/etc/lircd.conf'):
- x = open('/etc/lircd.conf')
-elif os.path.exists('/etc/lirc/lircd.conf'):
- x = open ('/etc/lirc/lircd.conf')
+# first pass: search for included configurations
+for lircdconf in lircdconf_list:
+ if os.path.exists(lircdconf):
+ print "Reading: %s" % (lircdconf)
+ lircdconf_list += findIncludes(lircdconf)
+ # remove duplicates
+ lircdconf_list = list(set(lircdconf_list))
-pos = 0
-for line in x.readlines():
- if line.find('begin codes') != -1:
- pos += 1
- if pos > 0 and (use_pos == None or use_pos == pos):
- if iscode(line):
- button = iscode(line).groups()[0]
- if button.upper() in needed:
- needed.remove(button.upper())
- mapping.append((button.upper(), button))
+# second pass: read actual key config
+for lircdconf in lircdconf_list:
+ if os.path.exists(lircdconf):
+ pos = parseFile(lircdconf)
+ if pos != 1:
+ print "Warning: your %s seems to contain %d sections starting with
\"begin codes\"." % (lircdconf, pos)
- elif alternatives.has_key(button.upper()) and \
- alternatives[button.upper()] in needed:
- needed.remove(alternatives[button.upper()])
- mapping.append((alternatives[button.upper()], button))
- else:
- unused.append(button)
- mapping.append((button.upper(), button))
-x.close()
-
+# write result to file
if write_option:
out = open(config.LIRCRC, 'w')
for event, button in mapping:
@@ -121,8 +151,10 @@
out.write(' config = %s\n' % event)
out.write('end\n')
out.close()
+ print "Success: %s button mappings written to %s!" % (len(mapping),
config.LIRCRC)
sys.exit(0)
+# print stuff to stdout
print 'Mapping:'
print
for event, button in mapping:
@@ -152,7 +184,7 @@
for i in needed:
print ' %s' % i
print
-if use_pos == None and pos > 1:
- print 'Your %s seems to contain %d sections starting with "begin codes".'
% (x.name, pos)
- print 'You should select the one best matching your remote by giving its
number (1..%d)' % (pos, )
- print 'on the commandline.'
+#if use_pos == None and pos > 1:
+# print 'Your %s seems to contain %d sections starting with "begin codes".'
% (x.name, pos)
+# print 'You should select the one best matching your remote by giving its
number (1..%d)' % (pos, )
+# print 'on the commandline.'
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-devel mailing list
Freevo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freevo-devel