Difference between revisions of "Lircrc builder"

From MythTV Official Wiki
Jump to: navigation, search
(Source code: Fix a bug)
m (new code template)
Line 1: Line 1:
 
==Introduction==
 
==Introduction==
 
This is a simple python script I made to convert shorthand lirc config to full config. Remeber this is in beta and may have problems use at your own risk.
 
This is a simple python script I made to convert shorthand lirc config to full config. Remeber this is in beta and may have problems use at your own risk.
 +
 
==Howto==
 
==Howto==
 
For an example create this file
 
For an example create this file
{{Box File|lrc.txt|
+
{{Code box|lrc.txt|
 
<pre>
 
<pre>
 
Play-button p
 
Play-button p
Line 46: Line 47:
 
end
 
end
 
</pre>
 
</pre>
 +
 
==Source code==
 
==Source code==
{{Box File|lrc.py|
+
{{Code box|lrc.py|
 
<pre>
 
<pre>
 
#!/usr/bin/python
 
#!/usr/bin/python
Line 97: Line 99:
 
</pre>
 
</pre>
 
}}
 
}}
 +
 
[[Category:Python Scripts]]
 
[[Category:Python Scripts]]
 
[[Category:Scripts]]
 
[[Category:Scripts]]

Revision as of 21:05, 3 April 2007

Introduction

This is a simple python script I made to convert shorthand lirc config to full config. Remeber this is in beta and may have problems use at your own risk.

Howto

For an example create this file

Script.png lrc.txt

Play-button p
Vol-up F11
Vol-down F10
prog mplayer
Play-button p

Then run

# python lrc.py

That will output this

#Generated by: t0ny's lircrc builder

begin
 prog = mythtv
 button = Play-button
 repeat = 3
 config = p
end

begin
 prog = mythtv
 button = Vol-up
 repeat = 3
 config = F11
end

begin
 prog = mythtv
 button = Vol-down
 repeat = 3
 config = F10
end

begin
 prog = mplayer
 button = Play-button
 repeat = 3
 config = p
end

Source code

Script.png lrc.py

#!/usr/bin/python
import sys

#By Tony Speer 2007 under GPL v2
#USE AT YOUR OWN RISK!
#Version 0.1 Beta

#defaults
prog = "mythtv"
repeat = 3
fn = "lrc.txt"

x = 0

while x < len(sys.argv):
	arg = sys.argv[x]
	if arg == "--file":
		fn = sys.argv[x + 1]
	x += 1

f = open(fn, "r")

print "#Generated by: t0ny's lircrc builder\n"

for line in f.readlines():
	if line.find("#") != -1: #check for comment
		line = line.split("#")[1] # remove comments

	line = line.replace("\n", "")

	if line.startswith("prog"):
		prog = line.split(" ")[1]
	elif line.startswith("repeat"):
		repeat = int(line.split(" ")[1])
	else:
		b = line.split(" ")
		if len(b) > 1:
			print """begin
 prog = %s
 button = %s
 repeat = %s
 config = %s
end\n""" % (prog, b[0], repeat, b[1])
	

f.close()