want help for os.remove on a running plugin

Requests, suggestions, support, and everything else python / plugin related.
Post Reply
skatulskijean
Posts: 1028
Joined: Wed Jul 04, 2012 8:01 am
Has thanked: 1 time
Been thanked: 148 times

want help for os.remove on a running plugin

Post by skatulskijean »

When ever i run a os.remove from inside my running plugin it's give me a OSError: (13, 'Permission denied') Error.

What can i do to the delete the file.

The is right located but why give it ever this error.

can i the permission set on xbmc4xbox?


Regards Jan
User avatar
BuZz
Site Admin
Posts: 1890
Joined: Wed Jul 04, 2012 12:50 am
Location: UK
Has thanked: 65 times
Been thanked: 422 times
Contact:

Re: want help for os.remove on a running plugin

Post by BuZz »

Please provide an example piece of code to reproduce and a debug log. thanks. it could be a bug in our python 2.7, or could be something else
skatulskijean
Posts: 1028
Joined: Wed Jul 04, 2012 8:01 am
Has thanked: 1 time
Been thanked: 148 times

Re: want help for os.remove on a running plugin

Post by skatulskijean »

BuZz wrote:Please provide an example piece of code to reproduce and a debug log. thanks. it could be a bug in our python 2.7, or could be something else
here is a little examplecode what bring the same error.
You can it run as program plugin i mean the code as default.py under a created Folder on plugins\programs.

Code: Select all

import urllib,zipfile,os


home=os.getcwd()
downloads=os.path.join(home+os.sep+'downloads')
unpacked=os.path.join(home+os.sep+'unpacked')
if not os.path.isdir(downloads):
	os.mkdir(downloads)
if not os.path.isdir(unpacked):
	os.mkdir(unpacked)
	
zipurl="https://github.com/Eldorados/script.module.urlresolver/archive/master.zip"
	
def main(zipurl):
	name=zipurl.split('/')[6]
	path=downloads+os.sep+name
	urllib.urlretrieve(zipurl,path)
	dirs=os.listdir(downloads)
	for testfile in dirs:
		print '-----------------------------------'
		print 'that is the downloaded zip  '+testfile
		print '-----------------------------------'
		zin = zipfile.ZipFile(downloads+os.sep+testfile, 'r')
		zin.extractall(unpacked)
		dirs=os.listdir(unpacked)
		for testfile in dirs:
			print '-----------------------------------'
			print 'that is the unpacked zip  '+testfile
			print '-----------------------------------'
	os.remove(path)
		
		
main(zipurl)
here is the error located on the debuglog:

Code: Select all

9:04:23 M: 92471296  NOTICE: -----------------------------------
09:04:23 M: 92471296  NOTICE: that is the downloaded zip  master.zip
09:04:23 M: 92471296  NOTICE: -----------------------------------
09:04:23 M: 92471296 WARNING: msvcrt.dll: dll_lseeki64 called, TODO: add 'int64 -> long' type checking
Previous line repeats 2 times.
09:04:25 M: 92463104 WARNING: -----------------------------------
09:04:25 M: 92463104  NOTICE: that is the unpacked zip  script.module.urlresolver-master
09:04:25 M: 92463104  NOTICE: -----------------------------------
09:04:25 M: 92471296    INFO: -->Python script returned the following error<--
09:04:25 M: 92471296   ERROR: Error Type: <type 'exceptions.OSError'>
09:04:25 M: 92471296   ERROR: Error Contents: (13, 'Permission denied', 'Q:\\plugins\\programs\\test remove\\downloads\\master.zip')
09:04:25 M: 92471296   ERROR: Traceback (most recent call last):
                                              File "Q:\plugins\programs\test remove\default.py", line 33, in <module>
                                                main(zipurl)
                                              File "Q:\plugins\programs\test remove\default.py", line 30, in main
                                                os.remove(path)
                                            OSError: (13, 'Permission denied', 'Q:\\plugins\\programs\\test remove\\downloads\\master.zip')
09:04:25 M: 92471296    INFO: -->End of Python script error report<--

and here is the debuglog: https://copy.com/e02AyDQChiZs1fGq


regards jan
Last edited by skatulskijean on Wed Oct 29, 2014 2:08 pm, edited 1 time in total.
tim619
Posts: 204
Joined: Sun Mar 10, 2013 10:22 am
Has thanked: 25 times
Been thanked: 59 times

Re: want help for os.remove on a running plugin

Post by tim619 »

I didn't test your code but you can find out using the answer from "PearsonArtPhoto" Link
If you find out you have no rights copy the files to different path or something. If you have no access try a delay or try to find out what has the file in use or if that doesnt help get the filerights using this

Note: Other people having same issue on windows etc. reporting you have to touch the file before delete or retry delete.
skatulskijean
Posts: 1028
Joined: Wed Jul 04, 2012 8:01 am
Has thanked: 1 time
Been thanked: 148 times

Re: want help for os.remove on a running plugin

Post by skatulskijean »

tim619 wrote:I didn't test your code but you can find out using the answer from "PearsonArtPhoto" Link
If you find out you have no rights copy the files to different path or something. If you have no access try a delay or try to find out what has the file in use or if that doesnt help get the filerights using this

Note: Other people having same issue on windows etc. reporting you have to touch the file before delete or retry delete.
This is as addon working on main xbmc Linux without problems.
and as script on linux python 2.7 working without problems but it is not working on xbmc4xbox (i can not test on main xbmc on windows or as script on windows self)
so it is a bug on xbmc4xbox or a bug on all what is windows like on python 2.7.
pleace can you it test as program addon on main xbmc running windows.
And is no matter i close the zin with zin.close or not.

Download plugin testremove for testing on main xbmc windows or xbmc4xbox:

https://copy.com/Ue3wjqY9EFNRUIL6

install with the addon Installer

Regards Jan

Ps :
I think we can not set the permission on xbmc4xbox is FATX
i have it tested with a time.sleep to.

touch over a subprozess can we not do then python on xbox is single threaded.
Yes i can the zip directly unzip from the url but that will me not help (and cost ram on the little xbox. for this file is it not a problem but for greater and more files it is this)
I think the download is closed and the unzip to so what a fucking problem.
skatulskijean
Posts: 1028
Joined: Wed Jul 04, 2012 8:01 am
Has thanked: 1 time
Been thanked: 148 times

Re: want help for os.remove on a running plugin

Post by skatulskijean »

i think its solved :

hat look on a windows pc with main xbmc installed:

s the under linux mainxbmc working script make the same error as under xbmc4xbox but the error code was a win 32 code we tim619 wrote it was in use .
On linux is that not a problem but on windows so on xbmc4xbox to.
so it was that the extracting was not close .
So i rewrite the extracting with the with statment and this close the extract prozess and os.remove works on the addon on windows to.
i have it not test momently on xbmc4xbox but i think this is the same.

working code on windows mainxbmc:

Code: Select all

import urllib,zipfile,os,xbmcaddon

ADDON_ID = 'plugin.program.testremove'
ADDON    = xbmcaddon.Addon(id=ADDON_ID)
home    = ADDON.getAddonInfo('path')

downloads=os.path.join(home+os.sep+'downloads')
unpacked=os.path.join(home+os.sep+'unpacked')
if not os.path.isdir(downloads):
	os.mkdir(downloads)
if not os.path.isdir(unpacked):
	os.mkdir(unpacked)
	
zipurl="https://github.com/Eldorados/script.module.urlresolver/archive/master.zip"
	
def main(zipurl):
	name=zipurl.split('/')[6]
	path=downloads+os.sep+name
	urllib.urlretrieve(zipurl,path)
	dirs=os.listdir(downloads)
	for testfile in dirs:
		print '-----------------------------------'
		print 'that is the downloaded zip  '+testfile
		print '-----------------------------------'
		with zipfile.ZipFile(downloads+os.sep+testfile, "r") as z:
			z.extractall(unpacked)
		dirs=os.listdir(unpacked)
		for testfile in dirs:
			print '-----------------------------------'
			print 'that is the unpacked zip  '+testfile
			print '-----------------------------------'
	os.remove(path)
	
		
		
		
		
main(zipurl)
	
	
regards jan
User avatar
BuZz
Site Admin
Posts: 1890
Joined: Wed Jul 04, 2012 12:50 am
Location: UK
Has thanked: 65 times
Been thanked: 422 times
Contact:

Re: want help for os.remove on a running plugin

Post by BuZz »

Good it's sorted. I didn't have a chance to reply earlier, but the linux filesystem can allow deletion of an open file, whereas that won't be allowed on the xbox. Cheers.
Post Reply