How to correctly DEBUG python scripts?
#1
Question 
I am just trying to create a new script and it is a real pain in the a**. Big Grin

So, i am used to use a Debugger (like in Visual Basic, which goes line through line and displays the corresponding variables when hovered with the mouse).

Are there any solutions (code snippets, tools) how i can easily debug my script?
Or should i just use the "print" command to write the variables to the python log? Oo

Cheers,
sCAPe
My XBOX built into a Sony Hifi CD-Player Case
XBOX Hifi Media Center Picture Gallery

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


Image
Reply
#2
import traceback

then in all the functions, wrpa them with a try/except catch

Code:
try:
    your code
except:
    print 'ERROR: defname'
    traceback.print_exc()
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#3
Thanks Nuka, i will try that..

It is really difficult, equipped just with Notepad++ and with XBMC_PC for debugging..
My XBOX built into a Sony Hifi CD-Player Case
XBOX Hifi Media Center Picture Gallery

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


Image
Reply
#4
Smile 
If you are used to debugging using Visual studio or similar, I would suggest that you download Eclipse and the PyDev plugin. With that IDE you can develop, test and debug your XBMC script. The debug features has all the common features, step, continue, step out, variable watch, call stack, etc

The downside is that you have to use a simplified python GUI that (almost) behaves like the real XBMC app. Look around for xbmc.py and xbmcgui.py.

I use it whenever I develop my scripts, and I think eclipse is the best IDE out there.

http://pydev.sourceforge.net/
http://www.eclipse.org/downloads/

If you have any questions, just ask and I will try to answer them.
Reply
#5
or try nano's debug logger class :-D - can be found in his Youtube script :-D

http://xbmc-scripting.googlecode.com/svn...default.py

its the first class.
Reply
#6
redsolo - I use eclipse too and it is a good ide. Really though the xbmc.py and xbmcgui.py emulator scripts are terribly out-of-date and I dont think they could render things like the XBMC threading model and control behavior accurately enough. There is really no replacement for the actual environment you get in XBMC_PC which rules out the pydev debugger.

This makes the pydev environment kinda overkill (it also annoyed me that it cant be installed if the eclipse path has spaces in it... wtf? ).

Anyway my method is just gratuitous logging of critical areas. I have a debug logger too that logs stuff out to a file (and can be enabled/disabled). A file is important since lots of times a script error will lockup xbmc so you cant get to the scriptsdebuginfo window Smile

Code:
DO_LOGGING = 1
try:
    LOG_FILE.close()
except Exception:
    pass
if DO_LOGGING:
    LOG_FILE = open(ROOT_DIR+"log.txt",'w')
def LOG(message):
    if DO_LOGGING:
        LOG_FILE.write(str(message)+"\n")
        LOG_FILE.flush()    
def LOGCLOSE():
    if DO_LOGGING:
        LOG_FILE.close()
Reply
#7
Well if you're debugging, you should be in debug mode in XBMC, so everything get's printed to the log file.

I've found traceback invaluable for tracking down the simpleist to the most difficult to find bugs.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#8
[quote=Nuka1195]Well if you're debugging, you should be in debug mode in XBMC, so everything get's printed to the log file.QUOTE]

If you don't know how to do this (some people don't)
then check out the link below about Advancedsettings.xml
http://www.xboxmediacenter.com/wiki/inde...ttings.xml

Wink
Reply
#9
I hope he knows how he's a beta tester Smile
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#10
Logging helps tons with things like threading issues (waiting on locks and the whatnot). On full debug xbmc.log has tons of button presses and is a little crowded.
Reply
#11
Asteron Wrote:redsolo - I use eclipse too and it is a good ide. Really though the xbmc.py and xbmcgui.py emulator scripts are terribly out-of-date and I dont think they could render things like the XBMC threading model and control behavior accurately enough. There is really no replacement for the actual environment you get in XBMC_PC which rules out the pydev debugger.

Yes, those are out of date, but Ive updated them (in some parts) so they work with the API changes. But I dont agree with you that they can be ruled out completly, as Ive developed scripts using those emulator script. Yes, the display is hideous, but that isnt important when developing (as long as it is control logic that is developed.). Of course, when making GUI changes (moving controls,labels,etc) it can not be used; but then I can use the PC emulator for that so I dont have to sit in front of the TV.

The control behvaiour worked out fine for me, but then I only use it to handle buttons, lists, keys and context menus.
What problems are there with the XBMC threading model that is specific for XBMC?

Could there be something Ive missed, which would produce bugs in my scripts?

Asteron Wrote:This makes the pydev environment kinda overkill (it also annoyed me that it cant be installed if the eclipse path has spaces in it... wtf? ).
I wouldnt say it is overkill if you want to use an IDE; with Eclipse you get SVN/CVS support, code completion, pylint and pyunit support, Mylar (great eclipse plugin), free, etc. The bug when installing must have been fixed, as I just installed it to "c:\program files\eclipse\"

Anyhow, the original question was if it was possible to debug the XBMC scripts. Yes, if you use an IDE as Eclipse (and pydev), not otherwise. Logging works, but it is not really debugging.
Reply
#12
yes stanley and nuka, i know how to enable debug logging.. Rofl

Thanks all for their replies .. I think asterons idea with the logging to a file (as script output) is just what i need, because i often had the problem that XBMC_PC just freezed because of an script error..
Will try that later on, but now i have other problems with my script as the stream i am trying to playback is currently not playable by mplayer .. i am trying to find a solution for this (perhaps the user-agent needs to be changed, thx asteron for the hint) Wink
My XBOX built into a Sony Hifi CD-Player Case
XBOX Hifi Media Center Picture Gallery

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


Image
Reply
#13
If it was a genuine mplayer error I would think that should show up in xbmc.log though...
Reply
#14
I have a debug issue maybe someone in this thread can help with. I am trying to figure out why the SageTV script is no longer functioning properly. I have logging set to 3 in the advancedsettings.xml. XBMC and XBMC_PC give slightly different logs so I am confused on what is going on. I am very new to Python so I do not know what I am doing yet. Here is a link to the Xbox-scene forums where I have posted some logs from an older version of XBMC where things worked and a newer version where watching a show is not working. Here is a brief description of what happens with XBMC_PC and how it differs from the xbox log. Can anyone tell me how to deug/log this properly so I can see what the issue is?
Reply

Logout Mark Read Team Forum Stats Members Help
How to correctly DEBUG python scripts?0