Author: duncan
Date: Fri Mar 21 08:25:34 2008
New Revision: 10554

Log:
[ 1922045 ] makelircrc does not follow "include"
Patch from Florian Demmer applied


Modified:
   branches/rel-1-7/freevo/ChangeLog
   branches/rel-1-7/freevo/src/helpers/makelircrc.py
   branches/rel-1/freevo/ChangeLog
   branches/rel-1/freevo/src/helpers/makelircrc.py

Modified: branches/rel-1-7/freevo/ChangeLog
==============================================================================
--- branches/rel-1-7/freevo/ChangeLog   (original)
+++ branches/rel-1-7/freevo/ChangeLog   Fri Mar 21 08:25:34 2008
@@ -25,6 +25,7 @@
  * Updated cd_burn plug-in to support play lists (F#1901175)
  * Updated dvbstreamer to allow the live pause to use a remote server 
(F#1915730)
  * Updated dvdbackup to allow customized menus (F#1890499)
+ * Updated makelircrc helper to allow include files (F#1922045)
  * Updated playlist to process "#EXTINF" comments in m3u files (F#1890203)
  * Updated Russian translation (B#1889826)
  * Updated tv guide with scheduled to record and favorite icons (F#1886621)

Modified: branches/rel-1-7/freevo/src/helpers/makelircrc.py
==============================================================================
--- branches/rel-1-7/freevo/src/helpers/makelircrc.py   (original)
+++ branches/rel-1-7/freevo/src/helpers/makelircrc.py   Fri Mar 21 08:25:34 2008
@@ -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' ]
+
 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')
-
-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))
-
-            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()
+# 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))
+
+# 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)
 
+# 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.'

Modified: branches/rel-1/freevo/ChangeLog
==============================================================================
--- branches/rel-1/freevo/ChangeLog     (original)
+++ branches/rel-1/freevo/ChangeLog     Fri Mar 21 08:25:34 2008
@@ -30,6 +30,7 @@
  * Updated cd_burn plug-in to support play lists (F#1901175)
  * Updated dvbstreamer to allow the live pause to use a remote server 
(F#1915730)
  * Updated dvdbackup to allow customized menus (F#1890499)
+ * Updated makelircrc helper to allow include files (F#1922045)
  * Updated playlist to process "#EXTINF" comments in m3u files (F#1890203)
  * Updated Russian translation (B#1889826)
  * Updated tv guide with scheduled to record and favorite icons (F#1886621)

Modified: branches/rel-1/freevo/src/helpers/makelircrc.py
==============================================================================
--- branches/rel-1/freevo/src/helpers/makelircrc.py     (original)
+++ branches/rel-1/freevo/src/helpers/makelircrc.py     Fri Mar 21 08:25:34 2008
@@ -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' ]
+
 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')
-
-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))
-
-            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()
+# 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))
+
+# 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)
 
+# 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-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to