Compiling and packaging cross platform pyc/pyo in addon instead of py
#1
Was wondering if there were any best practices around creating and packaging compiled versions of a python library as part of an addon in a way thats platform independent? e.g. to protect the addon code from being manipulated by end users, is it possible to package only the compiled version of a library w/o the code

I did a small test by including a py file containing a bunch of methods within an addon dir and it seems:
-on OSX it generates a .pyc file. Now if I remove the original py file, the addon still works
-on windows it generates a pyo file. Now if I remove the original py file, the addon still works
-now if I try copying the addon to linux with only the pyc file from above (ie without the py code), it complains "ImportError: Bad magic number in ...pyc" which implies a mismatch in python version

It seems like on each platform it needs the original py for the very first time so I tried a hack where I package the py file and then in the code, on startup, just delete the py file which seems to work on subsequent launches but I'm hoping there is a better way to solve this

Code:
__addon__ = xbmcaddon.Addon(id='plugin.video.someplugin')
os.remove(os.path.join(__addon__.getAddonInfo( 'path' ), 'somelibraryname.py' ))

Disclaimer: This is not for anything that will be packaged in official repo but for personal repo
Reply
#2
(2013-12-23, 05:13)xbmc007 Wrote: Disclaimer: This is not for anything that will be packaged in official repo but for personal repo
Looks like you are already aware why it will not make it into official repo http://wiki.xbmc.org/index.php?title=Add-on_rules
Reply
#3
Those are byte code so yes it's cross platform but not cross version. Python version in xbmc can be different for each system so it won't even be portable on the same platform. Best practice? Don't. I have no idea what you're trying to achieve here..
Reply
#4
(2013-12-23, 16:01)Hedda Wrote:
(2013-12-23, 05:13)xbmc007 Wrote: Disclaimer: This is not for anything that will be packaged in official repo but for personal repo
Looks like you are already aware why it will not make it into official repo http://wiki.xbmc.org/index.php?title=Add-on_rules

and it is very bad to even use such a way as you will only get complaining users
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#5
obfuscation is what he's trying to do. if you want that, look elsewhere.
Reply
#6
Thanks for the replies. I had stumbled across this old post which is why I thought someone might have tried this out in the past
http://forum.xbmc.org/showthread.php?tid...#pid127225
Reply
#7
I have a same issue,

I am working on windows .
Please, tell me how to use pyo file of addon's for windows.
If I am removing original py file, addon is not working still there is present pyo files.
Please, guide me what will be process of removing py file and execute pyo file.

Thanks
Reply

Logout Mark Read Team Forum Stats Members Help
Compiling and packaging cross platform pyc/pyo in addon instead of py0