added extractor progress bar and additional progress info

This commit is contained in:
Rob Weber 2015-06-26 15:32:22 -05:00
parent 032a772a81
commit 3e38f992b5
5 changed files with 112 additions and 56 deletions

View File

@ -91,4 +91,6 @@
<string id="30097">This needs to happen before a backup can run</string> <string id="30097">This needs to happen before a backup can run</string>
<string id="30098">Google Drive</string> <string id="30098">Google Drive</string>
<string id="30099">Open Settings</string> <string id="30099">Open Settings</string>
<string id="30100">Extracting Archive</string>
<string id="30101">Error extracting the zip archive</string>
</strings> </strings>

View File

@ -5,7 +5,9 @@ import utils as utils
import time import time
import json import json
from vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem,GoogleDriveFilesystem from vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem,GoogleDriveFilesystem
from progressbar import BackupProgressBar
from resources.lib.guisettings import GuiSettingsManager from resources.lib.guisettings import GuiSettingsManager
from resources.lib.extractor import ZipExtractor
def folderSort(aKey): def folderSort(aKey):
result = aKey[0] result = aKey[0]
@ -307,9 +309,19 @@ class XbmcBackup:
#extract the zip file #extract the zip file
zip_vfs = ZipFileSystem(xbmc.translatePath("special://temp/"+ self.restore_point),'r') 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() zip_vfs.cleanup()
self.progressBar.updateProgress(0,utils.getString(30049) + "......")
#set the new remote vfs and fix xbmc path #set the new remote vfs and fix xbmc path
self.remote_vfs = XBMCFileSystem(xbmc.translatePath("special://temp/" + self.restore_point.split(".")[0] + "/")) self.remote_vfs = XBMCFileSystem(xbmc.translatePath("special://temp/" + self.restore_point.split(".")[0] + "/"))
self.xbmc_vfs.set_root(xbmc.translatePath("special://home/")) 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') != ''): 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')) 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 #index files to restore
fileManager.walkTree(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path)) fileManager.walkTree(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path))
self.filesTotal = self.filesTotal + fileManager.size() 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()}) 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: 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'))) 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') != ''): 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')) 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 #index files to restore
fileManager.walkTree(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path)) fileManager.walkTree(self.remote_vfs.root_path + "custom_" + self._createCRC(self.xbmc_vfs.root_path))
self.filesTotal = self.filesTotal + fileManager.size() 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()}) 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: 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'))) 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.xbmc_vfs.set_root(fileGroup['dest'])
self.backupFiles(fileGroup['files'],self.remote_vfs,self.xbmc_vfs) self.backupFiles(fileGroup['files'],self.remote_vfs,self.xbmc_vfs)
self.progressBar.updateProgress(99,"Clean up operations .....")
if(self.restore_point.split('.')[-1] == 'zip'): if(self.restore_point.split('.')[-1] == 'zip'):
#delete the zip file and the extracted directory #delete the zip file and the extracted directory
self.xbmc_vfs.rmfile(xbmc.translatePath("special://temp/" + self.restore_point)) self.xbmc_vfs.rmfile(xbmc.translatePath("special://temp/" + self.restore_point))
@ -616,54 +632,3 @@ class FileManager:
def size(self): def size(self):
return len(self.fileArray) 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()

View File

@ -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

View File

@ -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()

View File

@ -107,9 +107,12 @@ class ZipFileSystem(Vfs):
def cleanup(self): def cleanup(self):
self.zip.close() self.zip.close()
def extract(self,path): def extract(self,aFile,path):
#extract zip file to 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): class DropboxFileSystem(Vfs):
client = None client = None