How to detect usb storage ?
#1
Hello , i try to write an addon that can read local directory and files

and i want to detect the usb storage that added or removed and refresh the video/music list immediately

i found two python modules named pyudev and pyusb , but it cant use in XBMC

when i try to run the addon , it always give me error.Sad

this is pyudev code below
PHP Code:
import pyudev

def check
(device):
    
context pyudev.Context()
    
monitor pyudev.Monitor.from_netlink(context)
    
monitor.filter_by('block')
    
observer pyudev.MonitorObserver(monitor,callback=check)
    
observer.daemon false
    observer
.stop()
    
observer.start() 

this code can run on my machine , but cant in XBMC addon

what should i do furthor more? or any other solutions to detect usb storage?
Reply
#2
You can start by telling what the error is. I imagine it's an import error because the only reason that code snippet work is because it does nothing. You need to put the pyudev module inside your addon.
Reply
#3
I checked sys.path, the module path is included and i try to sys.path.append() but still cant.
my OS is ubuntu 11.04, i think the problem is not relatvie to the OS.
Reply
#4
We still need to know what the error message is. We simply can't help you without it.
Reply
#5
(2012-10-27, 20:24)Bstrdsmkr Wrote: We still need to know what the error message is. We simply can't help you without it.

when i write "import pyudev" in my python file , and execute XBMC to run my addon
it show plugin.video.xxxxx error, then i write sys.path to check the module is included or not
i have no idea to fix the problem. I had reference the xbmc python api document.
It seens not provide any function to detect usb storage.
the worst situation is that i must extend the APIs to do it by using libudev.h library.Sad
Reply
#6
(2012-10-28, 08:19)beginerr0 Wrote:
(2012-10-27, 20:24)Bstrdsmkr Wrote: We still need to know what the error message is. We simply can't help you without it.

when i write "import pyudev" in my python file , and execute XBMC to run my addon
it show plugin.video.xxxxx error, then i write sys.path to check the module is included or not
i have no idea to fix the problem. I had reference the xbmc python api document.
It seens not provide any function to detect usb storage.
the worst situation is that i must extend the APIs to do it by using libudev.h library.Sad

What is being asked for is the output that your script puts into your xbmc.log file. XBMC outputs the traceback errors to the xbmc.log. This file is found in your ~\.xbmc\temp folder.

Reply
#7
Quote:What is being asked for is the output that your script puts into your xbmc.log file. XBMC outputs the traceback errors to the xbmc.log. This file is found in your ~\.xbmc\temp folder.

here is my xbmc.log detail:it got some errors

08:23:37 T:2717907824 NOTICE: -->Python Interpreter Initialized<--
08:23:37 T:2717907824 DEBUG: Process - The source file to load is /home/hi/.xbmc/addons/plugin.video.videos/default.py
08:23:37 T:2717907824 DEBUG: Process - Setting the Python path to /home/hi/.xbmc/addons/plugin.video.videos:/usr/share/xbmc/addons/script.module.simplejson/lib:/usr/share/xbmc/addons/script.module.pil/lib:/home/hi/.xbmc/addons/script.common.plugin.cache/lib:/home/hi/.xbmc/addons/script.module.simple.downloader/lib:/home/hi/.xbmc/addons/script.module.keyboard.chinese/lib:/home/hi/.xbmc/addons/script.module.parsedom/lib:/home/hi/.xbmc/addons/script.module.elementtree/lib:/usr/share/xbmc/addons/script.module.pysqlite/lib:/usr/lib/python2.7:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages/PIL:/usr/lib/pymodules/python2.7/gtk-2.0:/usr/lib/python2.7/dist-packages/gst-0.10:/usr/lib/python2.7/dist-packages/gtk-2.0:/usr/lib/pymodules/python2.7:/usr/lib/pymodules/python2.7/ubuntuone-client:/usr/lib/pymodules/python2.7/ubuntuone-control-panel:/usr/lib/pymodules/python2.7/ubuntuone-storage-protocol:
08:23:37 T:2717907824 DEBUG: Process - Entering source directory /home/hi/.xbmc/addons/plugin.video.videos
08:23:37 T:2717907824 DEBUG: Instantiating addon using automatically obtained id of "plugin.video.videos" dependent on version 1.0 of the xbmc.python api
08:23:38 T:2717907824 INFO: -->Python script returned the following error<--
08:23:38 T:2717907824 ERROR: Error Type: <type 'exceptions.IOError'>
08:23:38 T:2717907824 ERROR: Error Contents: (10, 'No child processes')
08:23:38 T:2717907824 ERROR: Traceback (most recent call last):

File "/home/hi/.xbmc/addons/plugin.video.videos/default.py", line 2, in <module>
import xbmc, xbmcgui, xbmcplugin, pyudev
File "/usr/local/lib/python2.7/dist-packages/pyudev/__init__.py", line 46, in <module>
from pyudev.device import *
File "/usr/local/lib/python2.7/dist-packages/pyudev/device.py", line 35, in <module>
from pyudev._libudev import libudev
File "/usr/local/lib/python2.7/dist-packages/pyudev/_libudev.py", line 289, in <module>
libudev = load_udev_library()
File "/usr/local/lib/python2.7/dist-packages/pyudev/_libudev.py", line 270, in load_udev_library
udev_library_name = find_library('udev')
File "/usr/lib/python2.7/ctypes/util.py", line 236, in find_library
return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
File "/usr/lib/python2.7/ctypes/util.py", line 229, in _findSoname_ldconfig
f.close()
IOError: (10, 'No child processes')
08:23:38 T:2717907824 INFO: -->End of Python script error report<--
08:23:38 T:2717907824 INFO: Python script stopped
08:23:38 T:2717907824 DEBUG: Thread XBPyThread 2717907824 terminating
08:23:38 T:3042060080 DEBUG: WaitOnScriptResult - plugin exited prematurely - terminating
08:23:38 T:3042060080 ERROR: GetDirectory - Error getting plugin://plugin.video.videos
08:23:38 T:3042060080 ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.videos) failed

08:23:38 T:3042060080 DEBUG: waiting for python thread 1 to stop
08:23:38 T:3042060080 DEBUG: python thread 1 destructed
08:23:38 T:3042060080 DEBUG: waiting for python thread 2 to stop
08:23:38 T:3042060080 DEBUG: python thread 2 destructed
08:23:38 T:3042060080 DEBUG: waiting for python thread 5 to stop
08:23:38 T:3042060080 DEBUG: python thread 5 destructed

Reply
#8
http://trac.xbmc.org/ticket/12098 ?
Reply
#9
(2012-10-29, 10:08)takoi Wrote: http://trac.xbmc.org/ticket/12098 ?

so it's a bug when call external python module!?
or any other way to solve usb storage detect problem and refresh list !?maybe i need some hints to do,if the way cant...Huh
i had already try python mutlit-thread and modify the xbmcmodule.cpp ,but util now still useless. Confused
Reply
#10
No, generally external modules work. But clearly find_library fails. Either it's xbmc doing something or find_library not finding the library. The error message sure is obscure.
Reply
#11
I had already try detect usb flash for few days but still failed

now i modified xbmc source code to extend Python APIs in xbmc python module

I use libudev C library, and in my addon , my code like as below

PHP Code:
while True:
    
result xbmc.USB_Detect()
    if 
result == 1:
        
xbmc.executebuiltin('RunAddon(plugin.video.videos)')
        
result 0
    time
.sleep(3

USB_Detect function can run correctly, when i plug the usb media in or out, it can return result

but both xbmc.executebuiltin() or xbmc.executescrpit() not executed, my UI did not do anything. Why?
Reply

Logout Mark Read Team Forum Stats Members Help
How to detect usb storage ?0