Merge pull request #3621 from vpeter4/sundtek

sundtek-mediatv: allow running scripts from addon settings
This commit is contained in:
Stefan Saraev 2014-11-15 16:23:46 +02:00
commit 80e4028df9
11 changed files with 136 additions and 73 deletions

View File

@ -1,6 +1,6 @@
4.3.4 4.3.4
fixed xbmc/kodi rebranding error fixed xbmc/kodi rebranding error
removed driver update option (can't run script from addon settings anymore) some fixes
4.3.3 4.3.3
addon transformed to service addon addon transformed to service addon
new addon settings option to enable to check for new driver at boot 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" INSTALLER_URL="http://sundtek.de/media/netinst/armsysvhf/installer.tar.gz"
;; ;;
esac esac
wget -O installer.tar.gz $INSTALLER_URL wget -O installer.tar.gz $INSTALLER_URL
tar -xzf installer.tar.gz tar -xzf installer.tar.gz
chmod -R 755 opt/ etc/ 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 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 # 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 # OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # 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) version_latest=$(cat version.latest)
if [ "$version_used" != "$version_latest" ]; then if [ "$version_used" != "$version_latest" ]; then
# new version exist # 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
)& )&
fi fi

View File

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# This file is part of OpenELEC - http://www.openelec.tv # 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 # OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # 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_HOME="$HOME/.kodi/userdata/addon_data/driver.dvb.sundtek-mediatv"
SUNDTEK_ADDON_SETTINGS="$SUNDTEK_ADDON_HOME/settings.xml" SUNDTEK_ADDON_SETTINGS="$SUNDTEK_ADDON_HOME/settings.xml"
logger -t Sundtek "### Starting updating driver ###" trap_exit_install() {
kodi-send -a "Notification(Sundtek, Starting updating driver, 2000, $SUNDTEK_ADDON_DIR/icon.png)" 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" cd "$SUNDTEK_ADDON_DIR"
rm -fr tmp rm -fr tmp
mkdir tmp mkdir tmp
cd 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 wget -O ../version.used http://sundtek.de/media/latest.phtml
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
logger -t Sundtek "### Can't get latest version ###" 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 .. cd ..
rm -fr tmp/ rm -fr tmp/
exit 1 exit 1
@ -66,6 +83,7 @@ if [ $? -ne 0 ]; then
rm -fr tmp/ rm -fr tmp/
exit 3 exit 3
fi fi
logger -t Sundtek "### Extracting archive ###" logger -t Sundtek "### Extracting archive ###"
kodi-send -a "Notification(Sundtek, Extracting archive, 2000, $SUNDTEK_ADDON_DIR/icon.png)" kodi-send -a "Notification(Sundtek, Extracting archive, 2000, $SUNDTEK_ADDON_DIR/icon.png)"
tar -xzf installer.tar.gz tar -xzf installer.tar.gz
@ -77,12 +95,12 @@ if [ $? -ne 0 ]; then
exit 4 exit 4
fi fi
# fix permissions
chmod -R 755 opt/ etc/ chmod -R 755 opt/ etc/
killall -9 mediaclient &>/dev/null rm -f opt/bin/getinput.sh
killall -9 mediasrv &>/dev/null rm -f opt/bin/lirc.sh
rm -fr opt/lib/pm/
chmod 755 opt/bin/*
cp -Pa opt/bin/* ../bin/ cp -Pa opt/bin/* ../bin/
cp -Pa opt/lib/* ../lib/ cp -Pa opt/lib/* ../lib/
@ -93,4 +111,9 @@ rm -fr tmp
logger -t Sundtek "### Driver update finished ###" 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, Driver update finished, 5000, $SUNDTEK_ADDON_DIR/icon.png)"
kodi-send -a "Notification(Sundtek, Please reboot, 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 exit 0

View File

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# This file is part of OpenELEC - http://www.openelec.tv # 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 # OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # 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 # You should have received a copy of the GNU General Public License
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>. # 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 # 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 # OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by

View File

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

View File

@ -27,13 +27,11 @@
<category label="9000"> <category label="9000">
<setting type="sep" /> <setting type="sep" />
<setting id="ENABLE_TUNER_TYPES" type="bool" label="9005" default="true" /> <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>
<!--
<category label="3000"> <category label="3000">
<setting type="sep" /> <setting type="sep" />
<setting id="CHECK_BOOT" type="bool" label="3020" default="false" /> <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> </category>
-->
</settings> </settings>