Compiling and packaging cross platform pyc/pyo in addon instead of py

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
xbmc007 Offline
Junior Member
Posts: 14
Joined: Apr 2013
Reputation: 0
Post: #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
find quote
Hedda Offline
Fan
Posts: 436
Joined: Feb 2013
Reputation: 9
Post: #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
find quote
takoi Offline
Team-Kodi Member
Posts: 842
Joined: Oct 2009
Reputation: 12
Location: Norway
Post: #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..
find quote
Martijn Offline
Team Kodi
Posts: 12,277
Joined: Jul 2011
Reputation: 170
Location: Dawn of time
Post: #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

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
(This post was last modified: 2013-12-23 16:09 by Martijn.)
find quote
davilla Offline
Retired-Team-XBMC Developer
Posts: 11,508
Joined: Feb 2008
Reputation: 64
Post: #5
obfuscation is what he's trying to do. if you want that, look elsewhere.


MediaInfo : http://mediainfo.sourceforge.net/
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
find quote
xbmc007 Offline
Junior Member
Posts: 14
Joined: Apr 2013
Reputation: 0
Post: #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
find quote
Dipti Offline
Junior Member
Posts: 28
Joined: Apr 2014
Reputation: 0
Post: #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
(This post was last modified: 2014-06-13 09:37 by Dipti.)
find quote