Skip to content

Commit

Permalink
Add auto clean functionality + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
peno64 committed Jan 12, 2023
1 parent 9c443a4 commit d3d7d0a
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 324 deletions.
29 changes: 28 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.ezmaintenanceplus" name="EZ Maintenance+" version="2023.01.01.0" provider-name="aenema, peno">
<addon id="script.ezmaintenanceplus" name="EZ Maintenance+" version="2023.01.09.0" provider-name="aenema, peno">
<requires>
<import addon="script.module.requests" version="1.0.0" />
</requires>
Expand All @@ -19,5 +19,32 @@
<icon>icon.png</icon>
<fanart>fanart.png</fanart>
</assets>
<news>
2023.01.09.0
- Added AutoClean Cache functionality every x days at a given hour.
- Backup always replaced the home folder reference in xml files with special://home
Not all addons can handle this replace so it is now possible via a setting to disable this.
- Backup Cancel didn't work. This is now fixed.

2023.01.01.0
- Fix a fix on 2022.12.28.0

2022.12.28.0
- Fix crash with full backup when there are foreign, like Hebrew, characters in xml files

2021.12.19.0
- Made kodi 19 (Matrix) compatible.

2021.11.03.0
- Fix Speedtest crash.

2020.12.19.1
- The plugin was also installed under Video add-ons. Now it only is in Program add-ons where it belongs
- Clean removed some files created by Common plugin cache or StorageServer or script.common.plugin.cache at kodi startup.
This resulted in breaking cache functionality of kodi
- Upload kodi log file to pastebin didn't always work and the first bytes were binary characters
- Made all decode calls UTF-8
- Improved ADVANCED SETTINGS(BUFFER SIZE) functionality
</news>
</extension>
</addon>
14 changes: 13 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ v2020.12.19.1
- Improved ADVANCED SETTINGS(BUFFER SIZE) functionality

v2021.11.03.0
- Fix for kodi 20. Speedtest crashed.
- Fix Speedtest crash.

v2021.12.19.0
- Made kodi 19 (Matrix) compatible.

v2022.12.28.0
- Fix backup. Crashed when foreign like Hebrew characters are used in xml files

2023.01.01.0
- Fix a fix on 2022.12.28.0

2023.01.09.0
- Added AutoClean Cache functionality every x days at a given hour.
- Backup always replaced the home folder reference in xml files with special://home
Not all addons can handle this replace so it is now possible via a setting to disable this.
- Backup Cancel didn't work. This is now fixed.
23 changes: 11 additions & 12 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@
import requests
from resources.lib.modules import control, tools
from resources.lib.modules.backtothefuture import unicode, PY2
from resources.lib.modules import maintenance

if PY2:
quote_plus = urllib.quote_plus
translatePath = xbmc.translatePath
else:
quote_plus = urllib.parse.quote_plus
translatePath = xbmcvfs.translatePath

AddonID ='script.ezmaintenanceplus'
USER_AGENT = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'
selfAddon = xbmcaddon.Addon(id=AddonID)

# Code to map the old translatePath
try:
translatePath = xbmcvfs.translatePath
except AttributeError:
translatePath = xbmc.translatePath

# ADDON SETTINGS
wizard1 = control.setting('enable_wiz1')
wizard2 = control.setting('enable_wiz2')
Expand Down Expand Up @@ -82,6 +79,10 @@ def CAT_TOOLS():
print ("NONE YET")

def MAINTENANCE():
nextAutoCleanup = maintenance.getNextMaintenance()
if nextAutoCleanup > 0:
nextAutoCleanup = time.strftime("%a, %d %b %Y %I:%M:%S %p %Z", time.localtime(nextAutoCleanup))
CreateDir('Next Auto Cleanup: %s' % nextAutoCleanup,'xxx','xxx',None,ADDON_FANART,'',isFolder=False,iconImage='DefaultIconInfo.png')
CreateDir('Clear Cache','url','clear_cache',ADDON_ICON,ADDON_FANART,'')
CreateDir('Clear Packages','url','clear_packages',ADDON_ICON,ADDON_FANART,'')
CreateDir('Clear Thumbnails','url','clear_thumbs',ADDON_ICON,ADDON_FANART,'')
Expand Down Expand Up @@ -201,15 +202,15 @@ def killxbmc():



def CreateDir(name, url, action, icon, fanart, description, isFolder=False):
def CreateDir(name, url, action, icon, fanart, description, isFolder=False, iconImage="DefaultFolder.png"):
if icon == None or icon == '': icon = ADDON_ICON
u=sys.argv[0]+"?url="+quote_plus(url)+"&action="+str(action)+"&name="+quote_plus(name)+"&icon="+quote_plus(icon)+"&fanart="+quote_plus(fanart)+"&description="+quote_plus(description)
ok=True
if PY2:
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=icon)
liz=xbmcgui.ListItem(name, iconImage=iconImage, thumbnailImage=icon)
else:
liz=xbmcgui.ListItem(name)
liz.setArt({'icon':"DefaultFolder.png"})
liz.setArt({'icon': iconImage})
liz.setArt({'thumbnailImage': icon})
liz.setInfo(type="Video", infoLabels={ "Title": name, "Plot": description } )
liz.setProperty( "Fanart_Image", fanart)
Expand Down Expand Up @@ -261,7 +262,7 @@ def CreateDir(name, url, action, icon, fanart, description, isFolder=False):

content = params.get('content')


#xbmc.log("ezmaintenanceplus: action: %s" % action, level=xbmc.LOGINFO)

if action == None: CATEGORIES()
elif action == 'settings': control.openSettings()
Expand Down Expand Up @@ -318,7 +319,5 @@ def CreateDir(name, url, action, icon, fanart, description, isFolder=False):
elif action == 'speedtest':
xbmc.executebuiltin('Runscript("special://home/addons/script.ezmaintenanceplus/resources/lib/modules/speedtest.py")')



xbmcplugin.endOfDirectory(int(sys.argv[1]))

8 changes: 4 additions & 4 deletions resources/lib/modules/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os,sys

import xbmc,xbmcaddon,xbmcplugin,xbmcgui,xbmcvfs
from resources.lib.modules.backtothefuture import PY2


integer = 1000
Expand Down Expand Up @@ -78,11 +79,10 @@

listDir = xbmcvfs.listdir

# Code to map the old translatePath
try:
translatePath = xbmcvfs.translatePath
except AttributeError:
if PY2:
translatePath = xbmc.translatePath
else:
translatePath = xbmcvfs.translatePath

skinPath = translatePath('special://skin/')

Expand Down
8 changes: 0 additions & 8 deletions resources/lib/modules/logviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@
def open_Settings():
open_Settings = xbmcaddon.Addon(id=AddonID).openSettings()

def _get_keyboard( default="", heading="", hidden=False ):
""" shows a keyboard and returns a value """
keyboard = xbmc.Keyboard( default, heading, hidden )
keyboard.doModal()
if ( keyboard.isConfirmed() ):
return unicode( keyboard.getText())
return default

def logView():
modes = ['View Log', 'Upload Log to Pastebin']
logPaths = []
Expand Down
59 changes: 55 additions & 4 deletions resources/lib/modules/maintenance.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import xbmc, xbmcaddon, xbmcgui, xbmcplugin, os, sys, xbmcvfs, glob
import xbmc, xbmcaddon, xbmcgui, xbmcplugin, os, sys, xbmcvfs, glob, math, time
import shutil
import urllib
import re
import os
from resources.lib.modules.backtothefuture import PY2

# Code to map the old translatePath
try:
translatePath = xbmcvfs.translatePath
except AttributeError:
if PY2:
translatePath = xbmc.translatePath
loglevel = xbmc.LOGNOTICE
else:
translatePath = xbmcvfs.translatePath
loglevel = xbmc.LOGINFO

thumbnailPath = translatePath('special://thumbnails');
cachePath = os.path.join(translatePath('special://home'), 'cache')
Expand Down Expand Up @@ -169,3 +172,51 @@ def purgePackages(mode='verbose'):
# dialog = xbmcgui.Dialog()
# dialog.ok("Maintenance", "Deleting Packages all done")
if mode == 'verbose': xbmc.executebuiltin('Notification(%s, %s, %s, %s)' % ('Maintenance' , 'Clean Packages Completed' , '3000', iconpath))

def determineNextMaintenance():
getSetting = xbmcaddon.Addon().getSetting

autoCleanDays = getSetting('autoCleanDays')
if autoCleanDays is None:
days = 0
else:
days = int(autoCleanDays)

t1 = 0

if days > 0:
autoCleanHour = getSetting('autoCleanHour')
if autoCleanHour is None:
hour = 0
else:
hour = int(autoCleanHour)

t0 = int(math.floor(time.time()))

t1 = t0 + (days * 24 * 60 * 60) # days * 24h * 60m * 60s

x = time.localtime(t1)

t1 += (hour - x.tm_hour) * 60 * 60 - x.tm_min * 60 - x.tm_sec
while (t1 <= t0):
t1 += 24 * 60 * 60 # add days until we are in the future

#t1 = t0 + 1 * 60 # for testing - every minute

win = xbmcgui.Window(10000)
win.setProperty("ezmaintenance.nextMaintenanceTime", str(t1))

logMaintenance("setNextMaintenance: %s" % str(t1))


def getNextMaintenance():
win = xbmcgui.Window(10000)
t1 = int(win.getProperty("ezmaintenance.nextMaintenanceTime"))

logMaintenance("getNextMaintenance: %s" % str(t1))

return t1

def logMaintenance(message):
xbmc.log("ezmaintenanceplus: %s" % message, level=loglevel)

Loading

0 comments on commit d3d7d0a

Please sign in to comment.