xbmcvfs.File modes
#1
How can you use xbmcvfs.File to open file for appending?
I tried 'a' but nothing happend. I also tried True as a third parameter (like the example in 13.0 python docs) and got error (only 2 parameters).
Also, am I to assume that 'b' doesn't work as well, and 'w' is the only mode?
Reply
#2
I'm also wondering about this.

What I understand is that xbmcvfs.File don't support append ("a") and you need to set it by default python and use io.open() but how do i do that?, with my example below i'm getting an IOError: [Errno 22] Invalid argument.

python:
import io

f = io.open('special://profile/addon_data/script.myscript/category_count.ini', "a")
    for c in sorted(category_count):
        s = "%s=%s\n" % (c, category_count[c])
        f.write(s)
    f.close()
Reply
#3
Open the file, read in the contents, close the file.

Open the file again for writing, write out the original contents then continue to write as required.

eg - Section from database-cleaner where it appends to it's original log file.

python:
if cleaning:
    if xbmcvfs.exists(cleaner_log):
        dbglog('database-cleaner.log exists - backing up to old.log')
        xbmcvfs.delete(old_cleaner_log)
        xbmcvfs.copy(cleaner_log, old_cleaner_log)
    old_log= xbmcvfs.File(cleaner_log)
    old_log_contents=old_log.read()
    old_log.close()
    
now = datetime.datetime.now()
logfile=xbmcvfs.File(cleaner_log, 'w')
if old_log_contents:
    logfile.write(old_log_contents)
date_long_format = xbmc.getRegion('datelong')
time_format = xbmc.getRegion('time')
date_long_format = date_long_format + ' '+time_format
logfile_header = 'Video Database Cleaner V' + addonversion+ ' - Running at ' +now.strftime(date_long_format) + '\n\n'
logfile.write(logfile_header)

That's how I did it anyway.
Learning Linux the hard way !!
Reply
#4
Great big thanks!
Reply

Logout Mark Read Team Forum Stats Members Help
xbmcvfs.File modes0