sundtek-mediatv: allow running scripts from addon settings

This commit is contained in:
vpeter4 2014-11-15 14:38:05 +01:00 committed by Stephan Raue
parent 2a2e30d38d
commit 448a0279be
11 changed files with 135 additions and 72 deletions

View File

@ -1,6 +1,6 @@
4.3.4
fixed xbmc/kodi rebranding error
removed driver update option (can't run script from addon settings anymore)
some fixes
4.3.3
addon transformed to service addon
new addon settings option to enable to check for new driver at boot

View File

@ -47,10 +47,17 @@ make_target() {
INSTALLER_URL="http://sundtek.de/media/netinst/armsysvhf/installer.tar.gz"
;;
esac
wget -O installer.tar.gz $INSTALLER_URL
tar -xzf installer.tar.gz
chmod -R 755 opt/ etc/
rm -f opt/bin/getinput.sh
rm -f opt/bin/lirc.sh
rm -fr opt/lib/pm/
wget -O version.used http://sundtek.de/media/latest.phtml
}

View File

@ -2,7 +2,7 @@
################################################################################
# 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
@ -78,7 +78,7 @@ if [ "$CHECK_BOOT" = "true" ]; then
version_latest=$(cat version.latest)
if [ "$version_used" != "$version_latest" ]; then
# new version exist
kodi-send -a "Notification(Sundtek, \"New driver version exist, update manually\", 7000, $SUNDTEK_ADDON_DIR/icon.png)"
kodi-send -a "Notification(Sundtek, \"New driver version exist, update manually\", 4000, $SUNDTEK_ADDON_DIR/icon.png)"
fi
)&
fi

View File

@ -2,7 +2,7 @@
################################################################################
# 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

View File

@ -24,18 +24,35 @@ SUNDTEK_ADDON_DIR="$HOME/.kodi/addons/driver.dvb.sundtek-mediatv"
SUNDTEK_ADDON_HOME="$HOME/.kodi/userdata/addon_data/driver.dvb.sundtek-mediatv"
SUNDTEK_ADDON_SETTINGS="$SUNDTEK_ADDON_HOME/settings.xml"
logger -t Sundtek "### Starting updating driver ###"
kodi-send -a "Notification(Sundtek, Starting updating driver, 2000, $SUNDTEK_ADDON_DIR/icon.png)"
trap_exit_install() {
kodi-send -a "Notification(Sundtek, Something went wrong. Cleaning..., 8000, $SUNDTEK_ADDON_DIR/icon.png)"
cd "$SUNDTEK_ADDON_DIR"
rm -fr tmp
exit 5
}
# kill process
systemctl stop driver.dvb.sundtek-mediatv
killall -9 mediaclient &>/dev/null
killall -9 mediasrv &>/dev/null
# exit on errors
set -e
trap trap_exit_install EXIT
cd "$SUNDTEK_ADDON_DIR"
rm -fr tmp
mkdir tmp
cd tmp
logger -t Sundtek "### Starting updating driver ###"
kodi-send -a "Notification(Sundtek, Starting updating driver, 2000, $SUNDTEK_ADDON_DIR/icon.png)"
wget -O ../version.used http://sundtek.de/media/latest.phtml
if [ $? -ne 0 ]; then
logger -t Sundtek "### Can't get latest version ###"
kodi-send -a "Notification(Sundtek, Can't get latest version, 8000, $SUNDTEK_ADDON_DIR/icon.png)"
kodi-send -a "Notification(Sundtek, Cant get latest version, 8000, $SUNDTEK_ADDON_DIR/icon.png)"
cd ..
rm -fr tmp/
exit 1
@ -66,6 +83,7 @@ if [ $? -ne 0 ]; then
rm -fr tmp/
exit 3
fi
logger -t Sundtek "### Extracting archive ###"
kodi-send -a "Notification(Sundtek, Extracting archive, 2000, $SUNDTEK_ADDON_DIR/icon.png)"
tar -xzf installer.tar.gz
@ -77,12 +95,12 @@ if [ $? -ne 0 ]; then
exit 4
fi
# fix permissions
chmod -R 755 opt/ etc/
killall -9 mediaclient &>/dev/null
killall -9 mediasrv &>/dev/null
chmod 755 opt/bin/*
rm -f opt/bin/getinput.sh
rm -f opt/bin/lirc.sh
rm -fr opt/lib/pm/
cp -Pa opt/bin/* ../bin/
cp -Pa opt/lib/* ../lib/
@ -93,4 +111,9 @@ rm -fr tmp
logger -t Sundtek "### Driver update finished ###"
kodi-send -a "Notification(Sundtek, Driver update finished, 5000, $SUNDTEK_ADDON_DIR/icon.png)"
kodi-send -a "Notification(Sundtek, Please reboot, 5000, $SUNDTEK_ADDON_DIR/icon.png)"
trap - EXIT
systemctl start driver.dvb.sundtek-mediatv
exit 0

View File

@ -2,7 +2,7 @@
################################################################################
# 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

View File

@ -15,29 +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 subprocess
import xbmcaddon
__settings__ = xbmcaddon.Addon(id = 'driver.dvb.sundtek-mediatv')
__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'))
__mediaclient__ = xbmc.translatePath(os.path.join(__cwd__, 'bin', 'mediaclient'))
__mediaclient_e__ = __mediaclient__ + ' -e'
__update_sh__ = xbmc.translatePath(os.path.join(__cwd__, 'bin', 'sundtek-update-driver.sh'))
if __name__ == "__main__" and len(sys.argv) == 2:
if sys.argv[1] == 'refresh_tuners':
sys.path.append(__resources_lib__)
from functions import refresh_sundtek_tuners
refresh_sundtek_tuners(__settings_xml__, __mediaclient_e__)
__settings__.openSettings()
elif sys.argv[1] == 'update_driver':
proc = subprocess.Popen([__update_sh__], shell = True)
return_code = proc.wait()
print "sundtek update driver return value" + str(return_code)
__settings__.openSettings()

View File

@ -0,0 +1,45 @@
################################################################################
# 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 subprocess
import xbmcaddon
__settings__ = xbmcaddon.Addon(id = 'driver.dvb.sundtek-mediatv')
__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'))
__mediaclient__ = xbmc.translatePath(os.path.join(__cwd__, 'bin', 'mediaclient'))
__mediaclient_e__ = __mediaclient__ + ' -e'
__update_sh__ = xbmc.translatePath(os.path.join(__cwd__, 'bin', 'sundtek-update-driver.sh'))
if len(sys.argv) == 2:
if sys.argv[1] == 'refresh_tuners':
print "sundtek refresh tuners"
sys.path.append(__resources_lib__)
from functions import refresh_sundtek_tuners
refresh_sundtek_tuners(__settings_xml__, __mediaclient_e__)
__settings__.openSettings()
elif sys.argv[1] == 'update_driver':
print "sundtek update driver"
proc = subprocess.Popen([__update_sh__], shell = True)
return_code = proc.wait()
print "sundtek update driver return value " + str(return_code)
__settings__.openSettings()

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

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

@ -27,13 +27,11 @@
<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>
<!--
<category label="3000">
<setting type="sep" />
<setting id="CHECK_BOOT" type="bool" label="3020" default="false" />
<setting label="3010" option="close" type="action" action="RunScript($ID, update_driver)" />
<setting label="3010" option="close" type="action" id="update_driver" action="RunScript($CWD/resources/actions.py, update_driver)" />
</category>
-->
</settings>