Quantcast
Channel: Kodi Community Forum - All Forums
Viewing all articles
Browse latest Browse all 84005

How to monkeypatch?

$
0
0
Hi,

I'm trying to come up with a successful way of monkeypatching a module so that all calls to the module's function get routed through the patch.

Background:

I hate doing this:

http://wiki.xbmc.org/index.php?title=HOW...XBMC_paths

Instructing people to modify Eclipse source code just feels wrong to me.

So I wrote this:

Code:
#default.py
import xbmc
import pydevd_file_utils
from functools import wraps

def xbmcfilenamedecorator(func):
    @wraps(func)
    def xbmcfilename(filename):
        filename = xbmc.translatePath(filename)
        return func(filename)
    return xbmcfilename

pydevd_file_utils._NormFile = xbmcfilenamedecorator(pydevd_file_utils._NormFile)
pydevd_file_utils.NormFileToServer = xbmcfilenamedecorator(pydevd_file_utils.NormFileToServer)
pydevd_file_utils.NormFileToClient = xbmcfilenamedecorator(pydevd_file_utils.NormFileToClient)

I tried dropping that in an addon that gets autorun at startup, which works for that run. But it seems the python interpreter is restarted several times, so one script that monkey patches will not force all others too.

I'm probably coming at this from the wrong angle. Advice welcome.

Viewing all articles
Browse latest Browse all 84005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>