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:
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.
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.