def xbmcvfs.copy (source,destination)

Requests, suggestions, support, and everything else python / plugin related.
Post Reply
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

def xbmcvfs.copy (source,destination)

Post by byron »

could someone please explain (by example perhaps) how this works exactly?

http://romanvm.github.io/xbmcstubs/docs ... 2f5f679d2d

I would like to take a file from one place, replace a file with the same name in a different path, and then ultimately delete the original file being copied when the task is finished...all via python. I made a couple of terrible attempts that did not work :(

Code: Select all

import xmbcvfs

source       = 'whatever/file/I/want/to/copy'
destination  = 'whatever/file/I/want/to/replace'

def xbmcvfs.copy ( source , destination ) 
my python skills are not so great, was wondering if someone could show me how this works exactly...tia
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: def xbmcvfs.copy (source,destination)

Post by Dan Dar3 »

xbmcvfs implementation in XBMC4Xbox is a Python script, you can check it in your Q:\scripts\.modules\script.module.xbmcvfs\lib\xbmcvfs.py. Also check your log file for errors.
https://svn.exotica.org.uk:8443/xbmc4xb ... mcvfs/lib/

Alternatively, why not use Python native commands? like shutil.copyfile() and os.delete() or shutile.move()?
https://docs.python.org/2/library/shutil.html
https://docs.python.org/2/library/os.html#os.remove
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: def xbmcvfs.copy (source,destination)

Post by byron »

dandar3 wrote:Alternatively, why not use Python native commands? like shutil.copyfile() and os.delete() or shutile.move()?
Right...that's what I finally came up with:

Code: Select all

import shutil
import os

rmfile      = 'Q://UserData/script_data/CU LRC Lyrics/settings.xml'
filename    = 'Q://skin/rapier-clarity-mod/scripts/CU LRC Lyrics/settings.xml'
destination = 'Q://scripts/CU LRC Lyrics/resources/settings.xml'

shutil.copyfile(filename,destination)

os.remove(rmfile)
This whole thing has got me pulling my hair out...but I finally found a work around for that at least. When installed CU LRC Lyrics (1.0.7) works, but some of the default settings in the settings.xml make it not xbmc4xbox friendly. The whole point of this script is to place it in the script folder of my skin, replace all of the files that need fixing for us, and then delete them when it's finished (the above code isn't finished yet...still need to replace a couple of scrapers in the same manner along with musicosd). I figure rather than hosting the link, or modding it to work, I can get away with just replacing specific files in this manner once it's installed. A really dirty hack, but what's up above is working so far :D I'm getting a script error from the "os.remove" but is working...to lazy to paste a debug right now, been working on this for hours.

Really the goal is just to make a button install a script for the user (all about easy logical use of the software), and then be able to run it without the hassle of manually installing it...really appreciate the post, tyvm! BTW, how exactly does os.remove work? Does what I have up there work?
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: def xbmcvfs.copy (source,destination)

Post by Dan Dar3 »

Right, I see interesting - yeah it usually does that doesn't it, you start with one end and eventually find yourself fixing this in other parts :-)

Possibly the file doesn't exist to remove, see this thread for how to catch the exception or how to check whether it exists or not. How does it work? It asks the file system to delete the file :-) if any problems with that (file doesn't exist, file is in use etc) it might throw an exception.
http://stackoverflow.com/questions/1084 ... -not-exist
Post Reply