Skip to content

Commit

Permalink
Merge pull request #31 from aanderse/addon-update-mechanism
Browse files Browse the repository at this point in the history
Implement addon upgrade mechanism & improve delete cache reliability
  • Loading branch information
aanderse authored Aug 14, 2021
2 parents 299c53c + d2610e2 commit 29fbecb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
6 changes: 3 additions & 3 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.program.steam.library" name="Steam Library" version="0.8.0" provider-name="aanderse">
<addon id="plugin.program.steam.library" name="Steam Library" version="0.8.1" provider-name="aanderse">
<requires>
<import addon="xbmc.python" version="3.0.0" />
<import addon="script.module.requests" version="2.18.4" />
<import addon="script.module.requests-cache" version="0.4.13" />
<import addon="script.module.requests" version="2.22.0" />
<import addon="script.module.requests-cache" version="0.5.2" />
<import addon="script.module.routing" version="0.2.0"/>
</requires>
<extension point="xbmc.python.pluginsource" library="addon.py">
Expand Down
12 changes: 11 additions & 1 deletion resources/arts.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,14 @@ def delete_cache():
"""
Deletes the cache containing the data about which art types are available or not
"""
os.remove(ART_AVAILABILITY_CACHE_FILE + ".sqlite")
# If Kodi's request-cache module is updated to >0.7.3 , we will only need to issue cached_requests.cache.clear() which will handle all scenarios. Until then, we must recreate the backend ourselves
try:
cached_requests.cache.clear()
except Exception:
log('Failed to clear cache. Attempting manual deletion')
try:
os.remove(ART_AVAILABILITY_CACHE_FILE + ".sqlite")
except:
log('Failed to delete cache file')
cached_requests.cache.responses = requests_cache.backends.storage.dbdict.DbPickleDict(ART_AVAILABILITY_CACHE_FILE + ".sqlite", 'responses', fast_save=True)
cached_requests.cache.keys_map = requests_cache.backends.storage.dbdict.DbDict(ART_AVAILABILITY_CACHE_FILE + ".sqlite", 'urls')
16 changes: 16 additions & 0 deletions resources/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ def main():
# first time run, store version
__addon__.setSetting('version', __addon__.getAddonInfo('version'))

else:
previous_version= __addon__.getSetting('version').split(".")
previous_version= list(map(int, previous_version))

new_version= __addon__.getSetting('version').split(".")
new_version= list(map(int,new_version))

if previous_version[0] == 0 & previous_version[1] < 8:
#Starting with 0.8.0, the cache encoding changed and previous caches needs to be reset.
delete_cache()

# Insert version upgrade mechanisms here before the following call

__addon__.setSetting('version', __addon__.getAddonInfo('version'))


# prompt the user to configure the plugin with their steam details
if not all_required_credentials_available():
__addon__.openSettings()
Expand Down
18 changes: 16 additions & 2 deletions resources/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
STEAM_GAMES_CACHE_FILE = xbmc.translatePath(os.path.join(addonUserDataFolder, 'requests_cache_games'))

# cache expires after: 86400=1 day 604800=7 days
cached_requests = requests_cache.core.CachedSession(STEAM_GAMES_CACHE_FILE, backend='sqlite',
cached_requests = requests_cache.CachedSession(STEAM_GAMES_CACHE_FILE, backend='sqlite',
expire_after=60 * minutesBeforeGamesListsExpiration,
old_data_on_error=True)

Expand Down Expand Up @@ -106,4 +106,18 @@ def get_user_games(steam_api_key, steam_user_id, recent_only=False):


def delete_cache():
os.remove(STEAM_GAMES_CACHE_FILE + ".sqlite")
"""
Deletes the cache containing the data about which games are owned or not
"""
# If Kodi's request-cache module is updated to >0.7.3 , we will only need to issue cached_requests.cache.clear() which will handle all scenarios. Until then, we must recreate the backend ourselves
try:
cached_requests.cache.clear()
except Exception:
log('Failed to clear cache. Attempting manual deletion')
try:
os.remove(STEAM_GAMES_CACHE_FILE + ".sqlite")
except:
log('Failed to delete & recreate cache')
cached_requests.cache.responses = requests_cache.backends.storage.dbdict.DbPickleDict(STEAM_GAMES_CACHE_FILE + ".sqlite", 'responses', fast_save=True)
cached_requests.cache.keys_map = requests_cache.backends.storage.dbdict.DbDict(STEAM_GAMES_CACHE_FILE + ".sqlite", 'urls')

0 comments on commit 29fbecb

Please sign in to comment.