Browse Source

Self-removing service. Cleanup after add-on update

pull/27/head
I-A-C 1 year ago
parent
commit
066ef50147
3 changed files with 49 additions and 2 deletions
  1. 46
    0
      CleanupService.py
  2. 2
    1
      addon.xml
  3. 1
    1
      resources/settings.xml

+ 46
- 0
CleanupService.py View File

@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# CleanupService.py

import os

import xbmc
import xbmcvfs
import xbmcaddon

'''
Temporary service to TRY to make some file changes, and then remove itself.
'''

ADDON = xbmcaddon.Addon()

# 1) Do the actual file changes you need:

profileFolder = xbmc.translatePath(ADDON.getAddonInfo('profile')).decode('utf-8')
try:
oldFilePath = os.path.join(profileFolder, 'settings.xml')
if xbmcvfs.exists(oldFilePath):
xbmcvfs.delete(oldFilePath)
except:
pass

# 2) Remove itself from the add-on folder, and overwrite 'addon.xml' to remove the extension point
# that ran this service at Kodi startups.s

addonRootFolder = xbmc.translatePath(ADDON.getAddonInfo('path')).decode('utf-8')
SERVICE_FILENAME = 'CleanupService.py'

try:
serviceScriptPath = os.path.join(addonRootFolder, SERVICE_FILENAME)
xbmcvfs.delete(serviceScriptPath)

addonXMLPath = os.path.join(addonRootFolder, 'addon.xml')
with open(addonXMLPath, 'r+') as xmlFile:
originalLines = xmlFile.readlines()
xmlFile.seek(0)
for line in originalLines:
if SERVICE_FILENAME not in line: # Ignore the line with your service entry, accept all others.
xmlFile.write(line)
xmlFile.truncate()
# Now 'addon.xml' doesn't have the service extension point anymore.
except:
pass

+ 2
- 1
addon.xml View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.lambdascrapers" name="Lambdascrapers Module" version="1.5.4a" provider-name="I-A-C">
<addon id="script.module.lambdascrapers" name="Lambdascrapers Module" version="1.5.4b" provider-name="I-A-C">
<requires>
<import addon="xbmc.python" version="2.1.0" />
<import addon="script.module.beautifulsoup4"/>
@@ -8,6 +8,7 @@
<extension point="xbmc.python.pluginsource" library="lib/default.py">
<provides>executable</provides>
</extension>
<extension point="xbmc.service" library="CleanupService.py" start="startup" />
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<summary lang="en">Lambdascrapers Module</summary>

+ 1
- 1
resources/settings.xml View File

@@ -2,7 +2,7 @@
<settings>
<category label="Modules">
<setting type="sep" />
<setting id="module.provider" label="Choose Module Scraper" type="action" option="close" action="RunPlugin(plugin://script.module.lambdascrapers/?mode=ScraperChoice)" default=" Lambdascrapers" />
<setting id="module.provider" label="Choose Module Scraper" type="action" option="close" action="RunPlugin(plugin://script.module.lambdascrapers/?mode=ScraperChoice)" default="" />
<setting label="Enable All Providers (for current Module)" type="action" action="RunPlugin(plugin://script.module.lambdascrapers/?mode=ToggleProviderAll&amp;action=EnableModuleAll)" option="close"/>
<setting label="Disable All Providers (for current Module)" type="action" action="RunPlugin(plugin://script.module.lambdascrapers/?mode=ToggleProviderAll&amp;action=DisableModuleAll)" option="close"/>
<setting label="Disable All Providers" type="action" action="RunPlugin(plugin://script.module.lambdascrapers/?mode=toggleAll&amp;setting=false&amp;open_id=1.1)" option="close"/>

Loading…
Cancel
Save