From 3e38f992b51e85328e03f97e6976db0822f5eb47 Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Fri, 26 Jun 2015 15:32:22 -0500 Subject: [PATCH] added extractor progress bar and additional progress info --- resources/language/English/strings.xml | 2 + resources/lib/backup.py | 73 +++++++------------------- resources/lib/extractor.py | 33 ++++++++++++ resources/lib/progressbar.py | 53 +++++++++++++++++++ resources/lib/vfs.py | 7 ++- 5 files changed, 112 insertions(+), 56 deletions(-) create mode 100644 resources/lib/extractor.py create mode 100644 resources/lib/progressbar.py diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 8b925c4..c6d4e5e 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -91,4 +91,6 @@ This needs to happen before a backup can run Google Drive Open Settings + Extracting Archive + Error extracting the zip archive diff --git a/resources/lib/backup.py b/resources/lib/backup.py index c465095..4da5965 100644 --- a/resources/lib/backup.py +++ b/resources/lib/backup.py @@ -5,7 +5,9 @@ import utils as utils import time import json from vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem,GoogleDriveFilesystem +from progressbar import BackupProgressBar from resources.lib.guisettings import GuiSettingsManager +from resources.lib.extractor import ZipExtractor def folderSort(aKey): result = aKey[0] @@ -307,9 +309,19 @@ class XbmcBackup: #extract the zip file zip_vfs = ZipFileSystem(xbmc.translatePath("special://temp/"+ self.restore_point),'r') - zip_vfs.extract(xbmc.translatePath("special://temp/")) + extractor = ZipExtractor() + + if(not extractor.extract(zip_vfs, xbmc.translatePath("special://temp/"), self.progressBar)): + #we had a problem extracting the archive, delete everything + zip_vfs.cleanup() + self.xbmc_vfs.rmfile(xbmc.translatePath("special://temp/" + self.restore_point)) + + xbmcgui.Dialog.ok(utils.getSetting(30010),utils.getString(30101)) + return + zip_vfs.cleanup() + self.progressBar.updateProgress(0,utils.getString(30049) + "......") #set the new remote vfs and fix xbmc path self.remote_vfs = XBMCFileSystem(xbmc.translatePath("special://temp/" + self.restore_point.split(".")[0] + "/")) self.xbmc_vfs.set_root(xbmc.translatePath("special://home/")) @@ -397,23 +409,25 @@ class XbmcBackup: if(utils.getSetting('custom_dir_1_enable') == 'true' and utils.getSetting('backup_custom_dir_1') != ''): self.xbmc_vfs.set_root(utils.getSetting('backup_custom_dir_1')) - if(self.remote_vfs.exists(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path))): + if(self.remote_vfs.exists(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path) + "/")): #index files to restore fileManager.walkTree(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path)) self.filesTotal = self.filesTotal + fileManager.size() allFiles.append({"source":self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path),"dest":self.xbmc_vfs.root_path,"files":fileManager.getFiles()}) else: + utils.log("error path not found: " + self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path)) xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045),self.remote_vfs.root_path + "custom_" + self._createCRC(utils.getSetting('backup_custom_dir_1'))) if(utils.getSetting('custom_dir_2_enable') == 'true' and utils.getSetting('backup_custom_dir_2') != ''): self.xbmc_vfs.set_root(utils.getSetting('backup_custom_dir_2')) - if(self.remote_vfs.exists(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path))): + if(self.remote_vfs.exists(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path) + "/")): #index files to restore fileManager.walkTree(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path)) self.filesTotal = self.filesTotal + fileManager.size() allFiles.append({"source":self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path),"dest":self.xbmc_vfs.root_path,"files":fileManager.getFiles()}) else: + utils.log("error path not found: " + self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path)) xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045),self.remote_vfs.root_path + "custom_" + self._createCRC(utils.getSetting('backup_custom_dir_2'))) @@ -424,6 +438,8 @@ class XbmcBackup: self.xbmc_vfs.set_root(fileGroup['dest']) self.backupFiles(fileGroup['files'],self.remote_vfs,self.xbmc_vfs) + self.progressBar.updateProgress(99,"Clean up operations .....") + if(self.restore_point.split('.')[-1] == 'zip'): #delete the zip file and the extracted directory self.xbmc_vfs.rmfile(xbmc.translatePath("special://temp/" + self.restore_point)) @@ -616,54 +632,3 @@ class FileManager: def size(self): return len(self.fileArray) - -class BackupProgressBar: - NONE = 2 - DIALOG = 0 - BACKGROUND = 1 - - mode = 2 - progressBar = None - override = False - - def __init__(self,progressOverride): - self.override = progressOverride - - #check if we should use the progress bar - if(int(utils.getSetting('progress_mode')) != 2): - #check if background or normal - if(int(utils.getSetting('progress_mode')) == 0 and not self.override): - self.mode = self.DIALOG - self.progressBar = xbmcgui.DialogProgress() - else: - self.mode = self.BACKGROUND - self.progressBar = xbmcgui.DialogProgressBG() - - def create(self,heading,message): - if(self.mode != self.NONE): - self.progressBar.create(heading,message) - - def updateProgress(self,percent,message=None): - - #update the progress bar - if(self.mode != self.NONE): - if(message != None): - #need different calls for dialog and background bars - if(self.mode == self.DIALOG): - self.progressBar.update(percent,message) - else: - self.progressBar.update(percent,message=message) - else: - self.progressBar.update(percent) - - def checkCancel(self): - result = False - - if(self.mode == self.DIALOG): - result = self.progressBar.iscanceled() - - return result - - def close(self): - if(self.mode != self.NONE): - self.progressBar.close() diff --git a/resources/lib/extractor.py b/resources/lib/extractor.py new file mode 100644 index 0000000..2eff708 --- /dev/null +++ b/resources/lib/extractor.py @@ -0,0 +1,33 @@ +import xbmc +import utils as utils + +class ZipExtractor: + + def extract(self,zipFile,outLoc,progressBar): + utils.log("extracting zip archive") + + result = True #result is true unless we fail + + #update the progress bar + progressBar.updateProgress(0,utils.getString(30100)) + + #list the files + fileCount = float(len(zipFile.listFiles())) + currentFile = 0 + + try: + for aFile in zipFile.listFiles(): + #update the progress bar + currentFile += 1 + progressBar.updateProgress(int((currentFile/fileCount) * 100),utils.getString(30100)) + + #extract the file + zipFile.extract(aFile,outLoc) + + except Exception,e: + print str(e) + utils.log("Error extracting file", xbmc.LOGDEBUG) + result = False + + return result + \ No newline at end of file diff --git a/resources/lib/progressbar.py b/resources/lib/progressbar.py new file mode 100644 index 0000000..e6fd381 --- /dev/null +++ b/resources/lib/progressbar.py @@ -0,0 +1,53 @@ +import utils as utils +import xbmcgui + +class BackupProgressBar: + NONE = 2 + DIALOG = 0 + BACKGROUND = 1 + + mode = 2 + progressBar = None + override = False + + def __init__(self,progressOverride): + self.override = progressOverride + + #check if we should use the progress bar + if(int(utils.getSetting('progress_mode')) != 2): + #check if background or normal + if(int(utils.getSetting('progress_mode')) == 0 and not self.override): + self.mode = self.DIALOG + self.progressBar = xbmcgui.DialogProgress() + else: + self.mode = self.BACKGROUND + self.progressBar = xbmcgui.DialogProgressBG() + + def create(self,heading,message): + if(self.mode != self.NONE): + self.progressBar.create(heading,message) + + def updateProgress(self,percent,message=None): + + #update the progress bar + if(self.mode != self.NONE): + if(message != None): + #need different calls for dialog and background bars + if(self.mode == self.DIALOG): + self.progressBar.update(percent,message) + else: + self.progressBar.update(percent,message=message) + else: + self.progressBar.update(percent) + + def checkCancel(self): + result = False + + if(self.mode == self.DIALOG): + result = self.progressBar.iscanceled() + + return result + + def close(self): + if(self.mode != self.NONE): + self.progressBar.close() diff --git a/resources/lib/vfs.py b/resources/lib/vfs.py index e21bf18..36ab2ba 100644 --- a/resources/lib/vfs.py +++ b/resources/lib/vfs.py @@ -107,9 +107,12 @@ class ZipFileSystem(Vfs): def cleanup(self): self.zip.close() - def extract(self,path): + def extract(self,aFile,path): #extract zip file to path - self.zip.extractall(path) + self.zip.extract(aFile,path) + + def listFiles(self): + return self.zip.infolist() class DropboxFileSystem(Vfs): client = None