[RELEASE] Texture Cache Maintenance utility
(2017-10-29, 17:47)Mr.Floppy Wrote:
(2017-10-15, 06:25)Mr.Floppy Wrote:
(2016-02-02, 16:10)Milhouse Wrote: Ah right, you don't want to execute this script in the context of the Kodi process.

Here's a fix... http://sprunge.us/eLXN

Put this alongside the texturecache.py script, call it shell.py and give it execute permissions - on Linux:
wget http://sprunge.us/eLXN -O ~/.kodi/userdata/shell.py && chmod +x ~/.kodi/userdata/shell.py

Now your Runscript() call needs to be (note this assumes the texturecache.py script is alongside the shell.py script, otherwise specify the full path to texturecache.py - don't use special://whatever):

For instance to map this to a remote control button:

As a bonus you'll get notifications on start and finish, and you won't be able to run multiple instances (which wouldn't be good).      


While the solution via the shell.py script is working fine on my KODI Krypton v17.4 installations under LibreELEC on my Raspberry Pi and ANDROID box, I can't get it to work on my PC using KODI for windows...

First problem:
As there are no "/var/run/" directories on the KODI installation on my PC running Windows 7, I replaced the line from
pidfile = "/var/run/shellpy.pid"
pidfile = "C:\Users\Stefan\AppData\Roaming\KODI\userdata\shellpy.pid"

-> problem solved

Second problem:
Trying to run the script shell.py throws the following excepton in the KODI log:
05:43:21.729 T:2148   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.WindowsError'>
                                            Error Contents: [Error 2] Das System kann die angegebene Datei nicht finden
                                            Traceback (most recent call last):
                                              File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 31, in <module>
                                              File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 24, in shellnotify
                                                notify("Starting...", " ".join(args))
                                              File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 11, in notify
                                                shellcmd(["kodi-send", "--action", "Notification(%s,%s)" % (header, text)])
                                              File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 7, in shellcmd
                                                process = subprocess.Popen(args, stderr=open(os.devnull, 'w'))
                                              File "C:\Program Files (x86)\Kodi\system\python\Lib\subprocess.py", line 390, in __init__
                                                errread, errwrite)
                                              File "C:\Program Files (x86)\Kodi\system\python\Lib\subprocess.py", line 640, in _execute_child
                                            WindowsError: [Error 2] Das System kann die angegebene Datei nicht finden
                                            -->End of Python script error

I assume that the "WindowsError: [Error 2] Das System kann die angegebene Datei nicht finden" (translated to english: "The system can't find the specified file") is caused by the missing "kodi-send" command under Windows, right?
I was not able to find an alternative command line tool for windows, but maybe I didn't use the appropriate search terms, since I'm a noob regarding python programming...

So - how could I get a "work-around" for this problem?      

Okay - after having dealt with Python and shell scripting under Windows for quite some time now, I finally found a way to modify the shell.py script so that it works now under this OS, too.

There are some important points to remember:
a) Since Windows (other than Linux) has no built-in Python interpreter and bash shell, you have to install them separately.
b) To avoid any problems with KODI, you have to install "Python 2.x" - "Python 3.x" won't work!
c) The paths to the executable files must be added to the environment variable PATH in Windows.

But don't afraid - this is not complicated at all if you follow my advices:
1. Download and install a "Python 2.x" version from the website under https://www.python.org/downloads/windows/ ; make sure that you enable "Add python.exe to path" in the process of installation!
2. Download and install "Git for windows" (which provides a BASH emulation) from the website under https://git-for-windows.github.io/ ; make sure that you enable "Use Git and optional Unix tools from the Windows Command Prompt" in the process of installation!

And here's the modified shell.py script:
!/usr/bin/env python
# -*- coding: utf-8 -*-

import os, subprocess, sys, xbmc

def shellcmd(args):
  if sys.argv[1].endswith(".py"):
    command = "python " + " ".join(args)
  elif sys.argv[1].endswith(".sh"):
    command = "sh " + " ".join(args)

  subprocess.call(command, shell=True)

def notify(header, text):
  xbmc.executebuiltin('notification(%s, %s)' % (header, text))

def shellnotify(args):
  pidfile = "shellpy.pid"

  if os.path.isfile(pidfile):
   notify("Already running!", file(pidfile, 'r').read())

  file(pidfile, 'w').write(" ".join(args))

    notify("Starting...", " ".join(args))
    notify("Finished", " ".join(args))


The beauty of this solution is that it will work not only with the Runscript() call of "./texturecache.py", but also with any other shell script; for an example see here: https://forum.kodi.tv/showthread.php?tid...pid2233173

Have fun with it :-)      

Since upgrading from KODI v17.6 to KODI v18 (RC2), the solution I posted above doesn't work under Windows 7 anymore, it seems that texturecache.py isn't compatible with this KODI version and OS :-(
The shell.py from above itself does work, I tested it with the following simple shell script callled "test.sh":

echo -en "\007"
c:/Users/Stefan/AppData/Roaming/Kodi/userdata/scripts/texturecache.py volume mute

When calling this example script via shell.py by "RunScript(special://userdata/scripts/shell.py,./test.sh)", I can hear the "beep" sound coming from the first command line, but the second one does nothing (it should mute the volume and invoke the corresponding "muted speaker" symbol on the KODI screen).
Testing the same example under my other KODI 18 RC2 installations using LibreElec on Android TV Box and RaspberryPi, it works without any problems - under KODI v17.6 it worked under Windows 7, too.

Could you please fix it?

Thank you in advance!

Messages In This Thread
Crash on Gotham on OS X - by desepticon - 2014-05-29, 17:57
RE: [RELEASE] Texture Cache Maintenance utility - by Mr.Floppy - 2018-12-12, 07:09
Cleaning - by AleisterHH - 2018-05-28, 22:03
RE: Cleaning - by Milhouse - 2018-05-28, 22:16
qax genre not updated - by Just-Me_A-User - 2018-06-12, 22:06
RE: qax genre not updated - by Milhouse - 2018-06-12, 23:40

Logout Mark Read Team Forum Stats Members Help
[RELEASE] Texture Cache Maintenance utility17
This forum uses Lukasz Tkacz MyBB addons.