added global log and encode functions to combat ascii encoding errors

This commit is contained in:
robweber 2012-08-17 14:18:08 -05:00
parent 6059612001
commit 26c99723bf
4 changed files with 38 additions and 26 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.xbmcbackup"
name="XBMC Backup" version="0.1.2" provider-name="robweber">
name="XBMC Backup" version="0.1.3" provider-name="robweber">
<requires>
<import addon="xbmc.python" version="2.0"/>
</requires>

View File

@ -47,3 +47,12 @@ added check for key in vfs.py - Thanks Martijn!
added French language translation - thanks mikebzh44
added some utf-8 encoding tags to filenames
[b]Version 0.1.3[/b]
added German translations - thanks dersphere
removed need for separate verbose logging setting
updated utf-8 encoding for all logging

View File

@ -74,7 +74,7 @@ class FileManager:
def addFile(self,filename):
#write the full remote path name of this file
xbmc.log("Add File: " + filename.encode("utf-8"),level=xbmc.LOGDEBUG)
log("Add File: " + filename,xbmc.LOGDEBUG)
self.fileArray.append(filename)
def getFileList(self):
@ -95,12 +95,12 @@ class XbmcBackup:
def __init__(self,__Addon):
self.addon = __Addon
self.local_path = xbmc.translatePath("special://home").encode("utf-8");
self.local_path = xbmc.makeLegalFilename(xbmc.translatePath("special://home"),False);
if(self.addon.getSetting('remote_selection') == '1' and vfs.exists(self.addon.getSetting('remote_path_2'))):
if(self.addon.getSetting('remote_selection') == '1'):
self.remote_path = self.addon.getSetting('remote_path_2')
self.addon.setSetting("remote_path","")
elif(self.addon.getSetting('remote_selection') == '0' and vfs.exists(self.addon.getSetting("remote_path"))):
elif(self.addon.getSetting('remote_selection') == '0'):
self.remote_path = self.addon.getSetting("remote_path")
if(self.addon.getSetting("backup_name") != '' and self.remote_path != ''):
@ -108,11 +108,9 @@ class XbmcBackup:
else:
self.remote_path = ""
self.remote_path = self.remote_path.encode("utf-8");
self.log(self.addon.getLocalizedString(30046))
self.log(self.addon.getLocalizedString(30047) + " :" + self.local_path)
self.log(self.addon.getLocalizedString(30048) + " :" + self.remote_path)
log(self.addon.getLocalizedString(30046))
log(self.addon.getLocalizedString(30047) + ": " + self.local_path)
log(self.addon.getLocalizedString(30048) + ": " + self.remote_path)
def run(self):
#check if we should use the progress bar
@ -131,12 +129,12 @@ class XbmcBackup:
def syncFiles(self):
if(vfs.exists(self.remote_path)):
#this will fail - need a disclaimer here
self.log(self.addon.getLocalizedString(30050))
log(self.addon.getLocalizedString(30050))
#make the remote directory
vfs.mkdir(self.remote_path)
self.log(self.addon.getLocalizedString(30051))
log(self.addon.getLocalizedString(30051))
self.fileManager.createFileList(self.addon)
allFiles = self.fileManager.getFileList()
@ -147,7 +145,7 @@ class XbmcBackup:
def restoreFiles(self):
self.fileManager.createFileList(self.addon)
self.log(self.addon.getLocalizedString(30051))
log(self.addon.getLocalizedString(30051))
allFiles = self.fileManager.getFileList()
#write list from remote to local
@ -157,19 +155,19 @@ class XbmcBackup:
xbmc.executebuiltin('UpdateLocalAddons')
def writeFiles(self,fileList,source,dest):
self.log("Writing files to: " + dest)
log("Writing files to: " + dest)
self.filesTotal = len(fileList)
self.filesLeft = self.filesTotal
#write each file from source to destination
for aFile in fileList:
if(not self.checkCancel()):
xbmc.log(self.addon.getLocalizedString(30052) + ": " + source + aFile, level=xbmc.LOGDEBUG)
log('Writing file: ' + source + aFile,xbmc.LOGDEBUG)
self.updateProgress(aFile)
if (aFile.startswith("-")):
vfs.mkdir(dest + aFile[1:])
vfs.mkdir(xbmc.makeLegalFilename(dest + aFile[1:],False))
else:
vfs.copy(source + aFile,dest + aFile)
vfs.copy(xbmc.makeLegalFilename(source + aFile),xbmc.makeLegalFilename(dest + aFile,False))
if(self.addon.getSetting('run_silent') == 'false'):
self.progressBar.close()
@ -189,12 +187,17 @@ class XbmcBackup:
return result
def log(self,message):
xbmc.log(self.addon.getLocalizedString(30010) + ": " + message)
def isReady(self):
return True if self.remote_path != '' else False
#global functions for logging and encoding
def log(message,loglevel=xbmc.LOGNOTICE):
xbmc.log(encode(__Addon.getLocalizedString(30010) + ": " + message),level=loglevel)
def encode(string):
return string.encode('UTF-8','replace')
#run the profile backup
backup = XbmcBackup(__Addon)