created zip vfs, will create and copy directories to remote share

This commit is contained in:
Rob Weber 2014-07-30 15:16:58 -05:00
parent 24385a2c68
commit 19fcb8bd46
3 changed files with 78 additions and 14 deletions

View File

@ -2,10 +2,9 @@ import xbmc
import xbmcgui import xbmcgui
import xbmcvfs import xbmcvfs
import utils as utils import utils as utils
import os.path
import time import time
import json import json
from vfs import XBMCFileSystem,DropboxFileSystem from vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem
def folderSort(aKey): def folderSort(aKey):
result = aKey[0] result = aKey[0]
@ -21,9 +20,11 @@ class XbmcBackup:
Backup = 0 Backup = 0
Restore = 1 Restore = 1
#remote file system #file systems
xbmc_vfs = None xbmc_vfs = None
remote_vfs = None remote_vfs = None
saved_remote_vfs = None
restoreFile = None restoreFile = None
remote_base_path = None remote_base_path = None
@ -98,15 +99,20 @@ class XbmcBackup:
#append backup folder name #append backup folder name
progressBarTitle = utils.getString(30010) + " - " progressBarTitle = utils.getString(30010) + " - "
if(mode == self.Backup and self.remote_vfs.root_path != ''): if(mode == self.Backup and self.remote_vfs.root_path != ''):
if(utils.getSetting("compress_backups") == 'true'):
#save the remote file system and use the zip vfs
self.saved_remote_vfs = self.remote_vfs
self.remote_vfs = ZipFileSystem("","w")
self.remote_vfs.set_root(self.remote_vfs.root_path + time.strftime("%Y%m%d%H%M") + "/") self.remote_vfs.set_root(self.remote_vfs.root_path + time.strftime("%Y%m%d%H%M") + "/")
progressBarTitle = progressBarTitle + utils.getString(30016) progressBarTitle = progressBarTitle + utils.getString(30016)
elif(mode == self.Restore and self.restore_point != None and self.remote_vfs.root_path != ''): elif(mode == self.Restore and self.restore_point != None and self.remote_vfs.root_path != ''):
self.remote_vfs.set_root(self.remote_vfs.root_path + self.restore_point + "/") self.remote_vfs.set_root(self.remote_vfs.root_path + self.restore_point + "/")
progressBarTitle = progressBarTitle + utils.getString(30017) progressBarTitle = progressBarTitle + utils.getString(30017)
else: else:
#kill the program here #kill the program here
self.remote_vfs = None self.remote_vfs = None
return return
utils.log(utils.getString(30047) + ": " + self.xbmc_vfs.root_path) utils.log(utils.getString(30047) + ": " + self.xbmc_vfs.root_path)
utils.log(utils.getString(30048) + ": " + self.remote_vfs.root_path) utils.log(utils.getString(30048) + ": " + self.remote_vfs.root_path)
@ -208,6 +214,19 @@ class XbmcBackup:
self.remote_vfs.set_root(fileGroup['dest']) self.remote_vfs.set_root(fileGroup['dest'])
self.backupFiles(fileGroup['files'],self.xbmc_vfs,self.remote_vfs) self.backupFiles(fileGroup['files'],self.xbmc_vfs,self.remote_vfs)
if(utils.getSetting("compress_backups") == 'true'):
#send the zip file to the real remote vfs
self.remote_vfs.cleanup()
self.xbmc_vfs.rename(xbmc.translatePath(utils.data_dir() + "xbmc_backup_temp.zip"), xbmc.translatePath(utils.data_dir() + self.remote_vfs.root_path[:-1] + ".zip"))
fileManager.addFile(xbmc.translatePath(utils.data_dir() + self.remote_vfs.root_path[:-1] + ".zip"))
#set root to data dir home
self.xbmc_vfs.set_root(xbmc.translatePath(utils.data_dir()))
self.remote_vfs = self.saved_remote_vfs
self.progressBar.updateProgress(0, "Copying Zip Archive")
self.backupFiles(fileManager.getFiles(),self.xbmc_vfs, self.remote_vfs)
#remove old backups #remove old backups
self._rotateBackups() self._rotateBackups()
@ -324,6 +343,8 @@ class XbmcBackup:
#call update addons to refresh everything #call update addons to refresh everything
xbmc.executebuiltin('UpdateLocalAddons') xbmc.executebuiltin('UpdateLocalAddons')
self.xbmc_vfs.cleanup()
self.remote_vfs.cleanup()
self.progressBar.close() self.progressBar.close()
#reset the window setting #reset the window setting
@ -439,7 +460,10 @@ class FileManager:
for aDir in dirs: for aDir in dirs:
dirPath = xbmc.translatePath(directory + "/" + aDir) dirPath = xbmc.translatePath(directory + "/" + aDir)
file_ext = aDir.split('.')[-1] file_ext = aDir.split('.')[-1]
self.addFile("-" + dirPath)
#don't backup your own zip file
if(aDir != "xbmc_backup_temp.zip"):
self.addFile("-" + dirPath)
#catch for "non directory" type files #catch for "non directory" type files
shouldWalk = True shouldWalk = True
@ -453,9 +477,10 @@ class FileManager:
#copy all the files #copy all the files
for aFile in files: for aFile in files:
utils.log(aFile) if(aFile != 'xbmc_backup_temp.zip'):
filePath = xbmc.translatePath(directory + "/" + aFile) utils.log(aFile)
self.addFile(filePath) filePath = xbmc.translatePath(directory + "/" + aFile)
self.addFile(filePath)
def addFile(self,filename): def addFile(self,filename):
try: try:

View File

@ -2,7 +2,8 @@ import utils as utils
import xbmc import xbmc
import xbmcvfs import xbmcvfs
import xbmcgui import xbmcgui
import sys import zipfile
import zlib
from dropbox import client, rest, session from dropbox import client, rest, session
APP_KEY = utils.getSetting('dropbox_key') APP_KEY = utils.getSetting('dropbox_key')
@ -45,6 +46,12 @@ class Vfs:
def exists(self,aFile): def exists(self,aFile):
return True return True
def rename(self,aFile,newName):
return True
def cleanup(self):
return True
class XBMCFileSystem(Vfs): class XBMCFileSystem(Vfs):
@ -60,9 +67,40 @@ class XBMCFileSystem(Vfs):
def rmdir(self,directory): def rmdir(self,directory):
return xbmcvfs.rmdir(directory,True) return xbmcvfs.rmdir(directory,True)
def rename(self,aFile,newName):
return xbmcvfs.rename(aFile, newName)
def exists(self,aFile): def exists(self,aFile):
return xbmcvfs.exists(aFile) return xbmcvfs.exists(aFile)
class ZipFileSystem(Vfs):
zip = None
def __init__(self,rootString,mode):
self.root_path = ""
self.zip = zipfile.ZipFile(xbmc.translatePath(utils.data_dir() + "xbmc_backup_temp.zip"),mode=mode)
def listdir(self,directory):
return True
def mkdir(self,directory):
#self.zip.write(directory[len(self.root_path):])
return True
def put(self,source,dest):
self.zip.write(source,dest,compress_type=zipfile.ZIP_DEFLATED)
return True
def rmdir(self,directory):
return True
def exists(self,aFile):
return True
def cleanup(self):
self.zip.close()
class DropboxFileSystem(Vfs): class DropboxFileSystem(Vfs):
client = None client = None

View File

@ -6,6 +6,7 @@
<setting id="remote_path" type="folder" label="30020" visible="eq(-2,0)" /> <setting id="remote_path" type="folder" label="30020" visible="eq(-2,0)" />
<setting id="dropbox_key" type="text" label="30028" visible="eq(-3,2)" default="" /> <setting id="dropbox_key" type="text" label="30028" visible="eq(-3,2)" default="" />
<setting id="dropbox_secret" type="text" label="30029" visible="eq(-4,2)" default="" /> <setting id="dropbox_secret" type="text" label="30029" visible="eq(-4,2)" default="" />
<setting id="compress_backups" type="bool" label="Zip Archives" default="false" />
<setting id="backup_rotation" type="number" label="30026" default="0" /> <setting id="backup_rotation" type="number" label="30026" default="0" />
<setting id="progress_mode" type="enum" label="30022" lvalues="30082|30083|30084" default="0" /> <setting id="progress_mode" type="enum" label="30022" lvalues="30082|30083|30084" default="0" />
</category> </category>