forked from zach-morris/plugin.program.iagl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_addonxml_provides_games.py
36 lines (36 loc) · 1.66 KB
/
update_addonxml_provides_games.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from kodi_six import xbmc, xbmcgui, xbmcvfs
from contextlib import closing
import os
WIN = xbmcgui.Window(10000)
if not WIN.getProperty('iagl.script_started'):
WIN.setProperty('iagl.script_started','True')
try:
xbmc.log(msg='IAGL: Update addon to provide video', level=xbmc.LOGDEBUG)
from resources.lib.main import iagl_utils
IAGL = iagl_utils() #IAGL utils Class
addon_xml_path = os.path.join(IAGL.get_addon_install_path(),'addon.xml')
success = list()
with closing(xbmcvfs.File(addon_xml_path)) as content_file:
byte_string = bytes(content_file.readBytes())
try:
file_contents = byte_string.decode('utf-8')
success.append(True)
except Exception as exc1:
file_contents = None
success.append(False)
xbmc.log(msg='IAGL Error: Update addon to provide video, Exception %(exc)s' % {'exc': str(exc1)}, level=xbmc.LOGERROR)
if file_contents is not None:
new_content = file_contents.split('<provides>')[0]+'<provides>game</provides>'+file_contents.split('</provides>')[-1]
with closing(xbmcvfs.File(addon_xml_path,'w')) as content_file:
content_file.write(bytearray(new_content.encode('utf-8')))
success.append(True)
if False not in success:
current_dialog = xbmcgui.Dialog()
ok_ret = current_dialog.ok('Completed','Addon updated to provide video')
xbmc.executebuiltin('Container.Refresh')
except Exception as exc:
xbmc.log(msg='IAGL Error: Addon xml could not be updated, Exception %(exc)s' % {'exc': str(exc)}, level=xbmc.LOGERROR)
WIN.clearProperty('iagl.script_started')
xbmc.log(msg='IAGL: Update addon to provide video completed', level=xbmc.LOGDEBUG)
else:
xbmc.log(msg='IAGL: Script already running', level=xbmc.LOGDEBUG)