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"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.xbmcbackup" <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> <requires>
<import addon="xbmc.python" version="2.0"/> <import addon="xbmc.python" version="2.0"/>
</requires> </requires>

View File

@ -47,3 +47,12 @@ added check for key in vfs.py - Thanks Martijn!
added French language translation - thanks mikebzh44 added French language translation - thanks mikebzh44
added some utf-8 encoding tags to filenames 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): def addFile(self,filename):
#write the full remote path name of this file #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) self.fileArray.append(filename)
def getFileList(self): def getFileList(self):
@ -95,12 +95,12 @@ class XbmcBackup:
def __init__(self,__Addon): def __init__(self,__Addon):
self.addon = __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.remote_path = self.addon.getSetting('remote_path_2')
self.addon.setSetting("remote_path","") 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") self.remote_path = self.addon.getSetting("remote_path")
if(self.addon.getSetting("backup_name") != '' and self.remote_path != ''): if(self.addon.getSetting("backup_name") != '' and self.remote_path != ''):
@ -108,11 +108,9 @@ class XbmcBackup:
else: else:
self.remote_path = "" self.remote_path = ""
self.remote_path = self.remote_path.encode("utf-8"); log(self.addon.getLocalizedString(30046))
log(self.addon.getLocalizedString(30047) + ": " + self.local_path)
self.log(self.addon.getLocalizedString(30046)) log(self.addon.getLocalizedString(30048) + ": " + self.remote_path)
self.log(self.addon.getLocalizedString(30047) + " :" + self.local_path)
self.log(self.addon.getLocalizedString(30048) + " :" + self.remote_path)
def run(self): def run(self):
#check if we should use the progress bar #check if we should use the progress bar
@ -131,12 +129,12 @@ class XbmcBackup:
def syncFiles(self): def syncFiles(self):
if(vfs.exists(self.remote_path)): if(vfs.exists(self.remote_path)):
#this will fail - need a disclaimer here #this will fail - need a disclaimer here
self.log(self.addon.getLocalizedString(30050)) log(self.addon.getLocalizedString(30050))
#make the remote directory #make the remote directory
vfs.mkdir(self.remote_path) vfs.mkdir(self.remote_path)
self.log(self.addon.getLocalizedString(30051)) log(self.addon.getLocalizedString(30051))
self.fileManager.createFileList(self.addon) self.fileManager.createFileList(self.addon)
allFiles = self.fileManager.getFileList() allFiles = self.fileManager.getFileList()
@ -147,7 +145,7 @@ class XbmcBackup:
def restoreFiles(self): def restoreFiles(self):
self.fileManager.createFileList(self.addon) self.fileManager.createFileList(self.addon)
self.log(self.addon.getLocalizedString(30051)) log(self.addon.getLocalizedString(30051))
allFiles = self.fileManager.getFileList() allFiles = self.fileManager.getFileList()
#write list from remote to local #write list from remote to local
@ -157,19 +155,19 @@ class XbmcBackup:
xbmc.executebuiltin('UpdateLocalAddons') xbmc.executebuiltin('UpdateLocalAddons')
def writeFiles(self,fileList,source,dest): def writeFiles(self,fileList,source,dest):
self.log("Writing files to: " + dest) log("Writing files to: " + dest)
self.filesTotal = len(fileList) self.filesTotal = len(fileList)
self.filesLeft = self.filesTotal self.filesLeft = self.filesTotal
#write each file from source to destination #write each file from source to destination
for aFile in fileList: for aFile in fileList:
if(not self.checkCancel()): 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) self.updateProgress(aFile)
if (aFile.startswith("-")): if (aFile.startswith("-")):
vfs.mkdir(dest + aFile[1:]) vfs.mkdir(xbmc.makeLegalFilename(dest + aFile[1:],False))
else: 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'): if(self.addon.getSetting('run_silent') == 'false'):
self.progressBar.close() self.progressBar.close()
@ -189,12 +187,17 @@ class XbmcBackup:
return result return result
def log(self,message):
xbmc.log(self.addon.getLocalizedString(30010) + ": " + message)
def isReady(self): def isReady(self):
return True if self.remote_path != '' else False 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 #run the profile backup
backup = XbmcBackup(__Addon) backup = XbmcBackup(__Addon)

View File

@ -4,10 +4,10 @@
<string id="30011">Général</string> <string id="30011">Général</string>
<string id="30012">Sélection des fichiers</string> <string id="30012">Sélection des fichiers</string>
<string id="30016">Sauvegarde</string> <string id="30016">Sauvegarde</string>
<string id="30017">Restauration</string> <string id="30017">Restauration</string>
<string id="30018">Parcourir</string> <string id="30018">Parcourir</string>
<string id="30019">Saisir</string> <string id="30019">Saisir</string>
<string id="30020">Parcourir le chemin de sauvegarde</string> <string id="30020">Parcourir le chemin de sauvegarde</string>
<string id="30021">Nom du répertoire de sauvegarde</string> <string id="30021">Nom du répertoire de sauvegarde</string>
<string id="30022">Mode silencieux</string> <string id="30022">Mode silencieux</string>
@ -22,7 +22,7 @@
<string id="30034">Miniatures / Fanart</string> <string id="30034">Miniatures / Fanart</string>
<string id="30035">Fichiers de configuration</string> <string id="30035">Fichiers de configuration</string>
<string id="30045">Erreur : Le chemin distant ne peut pas être vide.</string> <string id="30045">Erreur : Le chemin distant ne peut pas être vide.</string>
<string id="30046">Démarrage</string> <string id="30046">Démarrage</string>
<string id="30047">Dossier Local</string> <string id="30047">Dossier Local</string>
<string id="30048">Dossier Distant</string> <string id="30048">Dossier Distant</string>