Win Run custom python script from remote.xml
#1
Information 
Hi all

Just wondering if anyone knows how to run a custom python script from the remote.xml?

Seems to fail when the built in python interpreter tries to run it.

Does my script need to be placed somewhere inside appdata.roaming/xbmc?

Here is my current remote xml file.
------------------------------------------------------------------------------------------------------
<keymap>
<global>
<remote>
<red>UpdateLibrary(video)</red>
<green>XBMC.RunScript(C:\4_USB_Relay\relay_1.pyw)</green>
<yellow>ActivateWindow(Home)</yellow>
<blue>XBMC.RunScript(C:\4_USB_Relay\relay_4.pyw)</blue>
</remote>
</global>
</keymap>

-----------------------------------------------------------------------------------------------------

Here is the relay_1.pyw script
-----------------------------------------------------------------------------------------------------
import subprocess

get_state = "python drcontrol.py -d DAE001DQ -r 1 -c STATE"
turn_on = "python drcontrol.py -d DAE001DQ -r 1 -c ON"
turn_off = "python drcontrol.py -d DAE001DQ -r 1 -c OFF"

x = subprocess.check_output(get_state, shell=True)
x = x.rstrip('\n')

if 'ON' in x:
subprocess.call(turn_off, shell=True)
else:
subprocess.call(turn_on, shell=True)

-----------------------------------------------------------------------------------------------------

Also I have tried these scripts outside of xbmc and they run fine.

Not sure if .pyw is the issue in xbmc but I have tried both .pyw and .py. Smile
Cheers, Damien
Reply
#2
If you use Helix then *I think* that this does not work anymore. you would have to put it into an add-on. (basically just needs adding an addon.xml and putting that into a folder)
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#3
(2014-12-17, 00:28)phil65 Wrote: If you use Helix then *I think* that this does not work anymore. you would have to put it into an add-on. (basically just needs adding an addon.xml and putting that into a folder)

So I'm using Gotham 13.2

So create a folder such as relay.script and place it in the addons folder?

relay.script will contain the following
addon.xml
relay_1.py

Basically just follow the following link? http://kodi.wiki/view/Add-on_structure
Reply
#4
yeah just look how other addons are structured. Other people´s code is the best documentation. Smile
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#5
(2014-12-16, 23:38)bkafi Wrote: Seems to fail when the built in python interpreter tries to run it.
What's the error? I have no idea what "pyw" is and if that will work..
Reply
#6
(2014-12-17, 12:52)takoi Wrote:
(2014-12-16, 23:38)bkafi Wrote: Seems to fail when the built in python interpreter tries to run it.
What's the error? I have no idea what "pyw" is and if that will work..

The w just allows .py files to run silently.

So I have taken "phil65" advice and created an addon. I have mapped the "e" key to trigger the addon but the python interpreter doesn't seem to like it.

error below
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
22:41:34 T:2540 NOTICE: -->Python Interpreter Initialized<--
22:41:35 T:2540 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <class 'subprocess.CalledProcessError'>
Error Contents: Command 'python drcontrol.py -d DAE001DQ -r 1 -c STATE' returned non-zero exit status 2
Traceback (most recent call last):
File "C:\Users\Damien\AppData\Roaming\XBMC\addons\script.relay\relay_1.py", line 7, in <module>
x = subprocess.check_output(get_state, shell=True)
File "C:\Program Files (x86)\XBMC\system\python\Lib\subprocess.py", line 575, in check_output
raise CalledProcessError(retcode, cmd, output=output)
CalledProcessError: Command 'python drcontrol.py -d DAE001DQ -r 1 -c STATE' returned non-zero exit status 2
-->End of Python script error report<--

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Any ideas?

Not sure if i have to create an addon in order to run a custom .py script and assign a key in the keyboard.xml.

Cheers
Reply
#7
There should be no need to run "python xx.py" from inside a python script. add that file to your addon and call its functions directly.
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#8
(2014-12-17, 15:01)phil65 Wrote: There should be no need to run "python xx.py" from inside a python script. add that file to your addon and call its functions directly.

Sorry are you referring to the python drcontrol.py ?

-----------------------------------------------------------------------------------------------------
import subprocess

get_state = "python drcontrol.py -d DAE001DQ -r 1 -c STATE"
turn_on = "python drcontrol.py -d DAE001DQ -r 1 -c ON"
turn_off = "python drcontrol.py -d DAE001DQ -r 1 -c OFF"

x = subprocess.check_output(get_state, shell=True)
x = x.rstrip('\n')

if 'ON' in x:
subprocess.call(turn_off, shell=True)
else:
subprocess.call(turn_on, shell=True)
-----------------------------------------------------------------------------------------------------
Reply
#9
(2014-12-17, 15:01)phil65 Wrote: There should be no need to run "python xx.py" from inside a python script. add that file to your addon and call its functions directly.
Assuming that third party script support it..

You don't have to create an addon bkafi. It should work fine, in helix too. It looks like it's a problem within drcontrol.py or with shell/windows. I'm not sure how this works on windows, maybe it is a path problem. Try specifying the full paths to "python" and "drcontrol.py" in you commands.
Reply
#10
(2014-12-17, 15:09)takoi Wrote:
(2014-12-17, 15:01)phil65 Wrote: There should be no need to run "python xx.py" from inside a python script. add that file to your addon and call its functions directly.
Assuming that third party script support it..

You don't have to create an addon bkafi. It should work fine, in helix too. It looks like it's a problem within drcontrol.py or with shell/windows. I'm not sure how this works on windows, maybe it is a path problem. Try specifying the full paths to "python" and "drcontrol.py" in you commands.
Wasn´t it changed so that only Python stuff with script extension point can get called by skin? (Might be wrong since I didnt have a closer look yet, but I think I read that somewhere Smile )
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#11
(2014-12-17, 15:09)takoi Wrote:
(2014-12-17, 15:01)phil65 Wrote: There should be no need to run "python xx.py" from inside a python script. add that file to your addon and call its functions directly.
Assuming that third party script support it..

You don't have to create an addon bkafi. It should work fine, in helix too. It looks like it's a problem within drcontrol.py or with shell/windows. I'm not sure how this works on windows, maybe it is a path problem. Try specifying the full paths to "python" and "drcontrol.py" in you commands.

So is the following remote.xml command correct?

------------------------------------------------------------------------------------------------------
<keymap>
<global>
<remote>
<red>UpdateLibrary(video)</red>
<green>XBMC.RunScript(C:\4_USB_Relay\relay_1.py)</green>
<yellow>ActivateWindow(Home)</yellow>
<blue>XBMC.RunScript(C:\4_USB_Relay\relay_4.py)</blue>
</remote>
</global>
</keymap>
-----------------------------------------------------------------------------------------------------

And here you said to provide the actual path to python and drcontrol.py.
-----------------------------------------------------------------------------------------------------
import subprocess

get_state = "C:\Python34\python.exe C:\4_USB_Relay\drcontrol.py -d DAE001DQ -r 1 -c STATE"
turn_on = "C:\Python34\python.exe C:\4_USB_Relay\drcontrol.py -d DAE001DQ -r 1 -c ON"
turn_off = "C:\Python34\python.exe C:\4_USB_Relay\drcontrol.py -d DAE001DQ -r 1 -c OFF"

x = subprocess.check_output(get_state, shell=True)
x = x.rstrip('\n')

if 'ON' in x:
subprocess.call(turn_off, shell=True)
else:
subprocess.call(turn_on, shell=True)
-----------------------------------------------------------------------------------------------------

Is that about right? Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Run custom python script from remote.xml0