mount dvd within script
#1
Hi,

i wrote a little script to copy DVD content to my server.
My OS is Ubuntu 'hardy'
From Terminal it runs fine. Usying Python 2.5.2

Now i wanted to implent this into xbmc.

So here is the problem:
Poben is not working as expected so the drive doesn't mount.
Also i can't see any DEBUG-Info in XBMC.

It is is something with permissions i think Oo
I want to mount the drive in order to get the DVD-size, so i can
show up a progressbar during copy.

Please help.

Code:
import os
import sys
import time
import string
import commands
from subprocess import Popen


def iter_files(path):                   
    files = []

    for root, dirs, filenames in os.walk(path):
        for filename in filenames:
           files.append(os.path.join(root, filename))

    return files

def get_dir_size(directory):
    files = iter_files(directory)
    dir_size = 0

    for file in files:
        dir_size += os.path.getsize(file)
    
    return dir_size    

#ismount = commands.getoutput('cat /proc/mounts | grep /cdrom | wc -l')
#if ismount == '0':                    # not mountet

mdvd = Popen(['mount','/dev/scd0','/cdrom'])     #mount dvd <<< MY PROBLEM!!!
retcode = mdvd.wait()                        #wait for...
print retcode
...
Reply
#2
Why don´t you just run xbmc in standalone? then it will mount DVD´s

Quote:xbmc --standalone
If you have problems please read this before posting

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

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#3
I've testet a bit and found out that
other parts of my script also seems to be non-functional

So it's not only the mounting thing.
With the following code i normally get the name of my DVD. Confused

My question is why do i have other behaviour running my script in XBMC?

What do i have to change in my script?

For example the following:
Code:
...
dvdname = commands.getoutput('hal-get-property --udi `hal-find-by-capability --capability volume.disc` --key info.product').split('\n')
dvdname = dvdname[0].translate(string.maketrans('_',' '))
...
XBMC-Debug:
Traceback (most recent call last):
File "/home/xbmc/.xbmc/scripts/test.py", line 42, in ?
dvdname = commands.getoutput('hal-get-property --udi `hal-find-by-capability --capability volume.disc` --key info.product').split('\n')
File "/usr/share/xbmc/system/python/python24.zip/commands.py", line 44, in getoutput
return getstatusoutput(cmd)[1]
File "usr/share/xbmc/system/python/python24.zip/commands.py", line 53, in getstatusoutput
pipe = os.popen('{'+ cmd +';} 2>&1','r')
OSError: (0,'Error')
Eek
Reply
#4
I don't have any experience with Linux or Popen, so I'm not going to be the one who solves your problems for you.

But to answer your last question (at least partially), XBMC runs Python 2.4. If you're seeing differences between a script's functionality in your Python interpreter and in XBMC, I'd recommend installing Python 2.4 on your development machine (you can easily have multiple versions installed simultaneously, if you also want access to the new stuff).

That will let you test your XBMC Python code against a similar install.

Now, if this program works in Python 2.4 but not in XBMC, then I'd guess it's a problem with the Popen installation, but as I said above, I don't really know anything about that.
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#5
Have you tried the popen method from the os or sys (I forget which) module?
Reply
#6
@alexpoet:
I am using Python 2.5 instead of 2.4, thats right but i read the release notes and "Porting to Python 2.5" but found nothing relevant.
Maybe i give it a try...
@althekiller
hmm, i guess i tried >os.popen< before without luck.
Tomorrow i have more time to test.

Why is xbmc not using newest version of python?
Is this because many other scripts will get corrupted?
Reply
#7
I believe it's because the Python version has to be explicitly ported to the XBMC environment, which is a non-trivial task. I have never tried implementing a Python interpreter, but it's got to be hard work.

The first thing I did was check to make sure the version of Popen you're using was available in Python 2.4 and it is. It might behave differently (which could explain the problems you're having), but it's not as simple as, say, trying to use sqlite3 (which works in Python 2.5 but is not included with 2.4).

Still worth checking, though. If nothing else, you can do trial and error faster in the interpreter command-line than you can tweaking things in XBMC. I can certainly understand your frustration, getting different results in different environments.
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#8
I tried running my script with Pyhton 2.4(.5) on my terminal, and it
worked as expected.
The next thing i will try is to find alternative commands to get the following:

-name of DVD
-size of DVD

Suggestions are welcome Big Grin
(And YES it IS frustrating)
Reply
#9
os.popen is NOT implemented in XBMC Python script, you need to use os.system( ) instead.

Cheers,
Tobias
If you have problems please read this before posting

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

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#10
Quote:
import os
os.popen("notepad.exe")

works fine in xbmc on windows. notice the casing.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#11
Nuka1195 Wrote:works fine in xbmc on windows. notice the casing.

But but?! that call should get caught by the emu_something.cpp? Or perhaps that is only linux. Last I tried it did not work atleast.
If you have problems please read this before posting

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

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#12
Exclamation 
Hello mcfan,

any progress on the script you were writing? I am looking for a similar script.

Maybe i can use yours and adapt it.

I want to be able to mount a bluray iso from a script in xbmc, so i can play the m2ts file it contains.

In linux (i am running xbmc live) i can do this with

Quote:sudo mount -t udf -o loop /home/bluray.iso /media/bluray

Is there any way i can do this in phyton?
Reply

Logout Mark Read Team Forum Stats Members Help
mount dvd within script0