hdhomerun: allow running scripts from addon settings

This commit is contained in:
vpeter4 2014-11-15 15:06:36 +01:00 committed by Stephan Raue
parent 0e933bb5b4
commit 2a2e30d38d
6 changed files with 82 additions and 47 deletions

View File

@ -1,3 +1,5 @@
4.3.2
allow running scripts from addon settings
4.3.1
rebuild for addon api bump
4.3.0

View File

@ -18,7 +18,7 @@
PKG_NAME="hdhomerun"
PKG_VERSION="4.3"
PKG_REV="1"
PKG_REV="2"
PKG_ARCH="any"
PKG_LICENSE="GPL"
PKG_SITE="http://www.silicondust.com/products/hdhomerun/dvbt/"

View File

@ -1,6 +1,6 @@
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2013 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
#
# OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -15,18 +15,3 @@
# You should have received a copy of the GNU General Public License
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
import os
import sys
import xbmcaddon
__settings__ = xbmcaddon.Addon(id = 'driver.dvb.hdhomerun')
__cwd__ = __settings__.getAddonInfo('path')
__resources_lib__ = xbmc.translatePath(os.path.join(__cwd__, 'resources', 'lib'))
__settings_xml__ = xbmc.translatePath(os.path.join(__cwd__, 'resources', 'settings.xml'))
if __name__ == "__main__" and len(sys.argv) == 2 and sys.argv[1] == 'refresh_tuners':
sys.path.append(__resources_lib__)
from functions import refresh_hdhomerun_tuners
refresh_hdhomerun_tuners(__settings_xml__)
__settings__.openSettings()

View File

@ -0,0 +1,32 @@
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
#
# OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# OpenELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
import os
import sys
import xbmcaddon
__settings__ = xbmcaddon.Addon(id = 'driver.dvb.hdhomerun')
__cwd__ = __settings__.getAddonInfo('path')
__resources_lib__ = xbmc.translatePath(os.path.join(__cwd__, 'resources', 'lib'))
__settings_xml__ = xbmc.translatePath(os.path.join(__cwd__, 'resources', 'settings.xml'))
if len(sys.argv) == 2 and sys.argv[1] == 'refresh_tuners':
sys.path.append(__resources_lib__)
from functions import refresh_hdhomerun_tuners
refresh_hdhomerun_tuners(__settings_xml__)
__settings__.openSettings()

View File

@ -37,36 +37,39 @@ def _usage(this_file):
return """SYNOPSIS: pretty print an XML document
USAGE: python %s <filename> \n""" % this_file
def _pprint_line(indent_level, line, width=100, output=_sys.stdout):
def _pprint_line(indent_level, line, width=100, output=_sys.stdout, ignore_contents = False):
if line.strip():
start = ""
number_chars = 0
for l in range(indent_level):
start = start + " "
number_chars = number_chars + 1
try:
elem_start = _re.findall("(\<\W{0,1}\w+:\w+) ?", line)[0]
elem_finished = _re.findall("([?|\]\]/]*\>)", line)[0]
#should not have *
attrs = _re.findall("(\S*?\=\".*?\")", line)
output.write(start + elem_start)
number_chars = len(start + elem_start)
for attr in attrs:
if (attrs.index(attr) + 1) == len(attrs):
number_chars = number_chars + len(elem_finished)
if (number_chars + len(attr) + 1) > width:
output.write("\n")
for i in range(len(start + elem_start) + 1):
if not ignore_contents:
try:
elem_start = _re.findall("(\<\W{0,1}\w+:\w+) ?", line)[0]
elem_finished = _re.findall("([?|\]\]/|\-\-]*\>)", line)[0]
#should not have *
attrs = _re.findall("(\S*?\=\".*?\")", line)
output.write(start + elem_start)
number_chars = len(start + elem_start)
for attr in attrs:
if (attrs.index(attr) + 1) == len(attrs):
number_chars = number_chars + len(elem_finished)
if (number_chars + len(attr) + 1) > width:
output.write("\n")
for i in range(len(start + elem_start) + 1):
output.write(" ")
number_chars = len(start + elem_start) + 1
else:
output.write(" ")
number_chars = len(start + elem_start) + 1
else:
output.write(" ")
number_chars = number_chars + 1
output.write(attr)
number_chars = number_chars + len(attr)
output.write(elem_finished + "\n")
except IndexError:
#give up pretty print this line
number_chars = number_chars + 1
output.write(attr)
number_chars = number_chars + len(attr)
output.write(elem_finished + "\n")
except IndexError:
#give up pretty print this line
output.write(start + line + "\n")
else:
output.write(start + line + "\n")
@ -80,7 +83,8 @@ def _get_next_elem(data):
start_pos = data.find("<")
end_pos = data.find(">") + 1
retval = data[start_pos:end_pos]
stopper = retval.rfind("/")
stopper = retval.rfind("/")
ignore_contents = False
if stopper < retval.rfind("\""):
stopper = -1
single = (stopper > -1 and ((retval.find(">") - stopper) < (stopper - retval.find("<"))))
@ -89,11 +93,19 @@ def _get_next_elem(data):
ignore_question = retval.find("<?") > -1
if ignore_excl:
ignore_contents = True
cdata = retval.find("<![CDATA[") > -1
if cdata:
end_pos = data.find("]]>")
if end_pos > -1:
end_pos = end_pos + len("]]>")
stopper = end_pos
else:
end_pos = data.find("-->")
if end_pos > -1:
end_pos = end_pos + len("-->")
stopper = end_pos
retval = data[start_pos:end_pos]
elif ignore_question:
end_pos = data.find("?>") + len("?>")
@ -101,11 +113,12 @@ def _get_next_elem(data):
no_indent = ignore or single
#print retval, end_pos, start_pos, stopper > -1, no_indent
return start_pos, \
end_pos, \
stopper > -1, \
no_indent
no_indent, \
ignore_contents
def get_pprint(xml, indent=4, width=80):
"""Returns the pretty printed xml """
@ -116,6 +129,8 @@ def get_pprint(xml, indent=4, width=80):
self.output += string
out = out()
pprint(xml, output=out, indent=indent, width=width)
return out.output
@ -126,7 +141,7 @@ def pprint(xml, output=_sys.stdout, indent=4, width=80):
Use indent to select indentation level. Default is 4 """
data = xml
indent_level = 0
start_pos, end_pos, is_stop, no_indent = _get_next_elem(data)
start_pos, end_pos, is_stop, no_indent, ignore_contents = _get_next_elem(data)
while ((start_pos > -1 and end_pos > -1)):
_pprint_elem_content(indent_level, data[:start_pos].strip(),
output=output)
@ -136,7 +151,8 @@ def pprint(xml, output=_sys.stdout, indent=4, width=80):
_pprint_line(indent_level,
data[:end_pos - start_pos],
width=width,
output=output)
output=output,
ignore_contents=ignore_contents)
data = data[end_pos - start_pos:]
if not is_stop and not no_indent :
indent_level = indent_level + indent
@ -144,7 +160,7 @@ def pprint(xml, output=_sys.stdout, indent=4, width=80):
if not data:
break
else:
start_pos, end_pos, is_stop, no_indent = _get_next_elem(data)
start_pos, end_pos, is_stop, no_indent, ignore_contents = _get_next_elem(data)
if __name__ == "__main__":

View File

@ -11,6 +11,6 @@
<category label="9000">
<setting type="sep" />
<setting id="ENABLE_TUNER_TYPES" type="bool" label="9005" default="true" />
<setting label="9010" option="close" type="action" action="RunScript($ID, refresh_tuners)" />
<setting label="9010" option="close" type="action" id="refresh_tuners" action="RunScript($CWD/resources/actions.py, refresh_tuners)" />
</category>
</settings>