mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-15 04:45:49 +01:00
created zip vfs, will create and copy directories to remote share
This commit is contained in:
parent
24385a2c68
commit
19fcb8bd46
@ -2,10 +2,9 @@ import xbmc
|
||||
import xbmcgui
|
||||
import xbmcvfs
|
||||
import utils as utils
|
||||
import os.path
|
||||
import time
|
||||
import json
|
||||
from vfs import XBMCFileSystem,DropboxFileSystem
|
||||
from vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem
|
||||
|
||||
def folderSort(aKey):
|
||||
result = aKey[0]
|
||||
@ -21,9 +20,11 @@ class XbmcBackup:
|
||||
Backup = 0
|
||||
Restore = 1
|
||||
|
||||
#remote file system
|
||||
#file systems
|
||||
xbmc_vfs = None
|
||||
remote_vfs = None
|
||||
saved_remote_vfs = None
|
||||
|
||||
restoreFile = None
|
||||
remote_base_path = None
|
||||
|
||||
@ -98,15 +99,20 @@ class XbmcBackup:
|
||||
#append backup folder name
|
||||
progressBarTitle = utils.getString(30010) + " - "
|
||||
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") + "/")
|
||||
progressBarTitle = progressBarTitle + utils.getString(30016)
|
||||
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 + "/")
|
||||
progressBarTitle = progressBarTitle + utils.getString(30017)
|
||||
else:
|
||||
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 + "/")
|
||||
progressBarTitle = progressBarTitle + utils.getString(30017)
|
||||
else:
|
||||
#kill the program here
|
||||
self.remote_vfs = None
|
||||
return
|
||||
self.remote_vfs = None
|
||||
return
|
||||
|
||||
utils.log(utils.getString(30047) + ": " + self.xbmc_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.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
|
||||
self._rotateBackups()
|
||||
|
||||
@ -324,6 +343,8 @@ class XbmcBackup:
|
||||
#call update addons to refresh everything
|
||||
xbmc.executebuiltin('UpdateLocalAddons')
|
||||
|
||||
self.xbmc_vfs.cleanup()
|
||||
self.remote_vfs.cleanup()
|
||||
self.progressBar.close()
|
||||
|
||||
#reset the window setting
|
||||
@ -439,7 +460,10 @@ class FileManager:
|
||||
for aDir in dirs:
|
||||
dirPath = xbmc.translatePath(directory + "/" + aDir)
|
||||
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
|
||||
shouldWalk = True
|
||||
@ -453,9 +477,10 @@ class FileManager:
|
||||
|
||||
#copy all the files
|
||||
for aFile in files:
|
||||
utils.log(aFile)
|
||||
filePath = xbmc.translatePath(directory + "/" + aFile)
|
||||
self.addFile(filePath)
|
||||
if(aFile != 'xbmc_backup_temp.zip'):
|
||||
utils.log(aFile)
|
||||
filePath = xbmc.translatePath(directory + "/" + aFile)
|
||||
self.addFile(filePath)
|
||||
|
||||
def addFile(self,filename):
|
||||
try:
|
||||
|
@ -2,7 +2,8 @@ import utils as utils
|
||||
import xbmc
|
||||
import xbmcvfs
|
||||
import xbmcgui
|
||||
import sys
|
||||
import zipfile
|
||||
import zlib
|
||||
from dropbox import client, rest, session
|
||||
|
||||
APP_KEY = utils.getSetting('dropbox_key')
|
||||
@ -45,6 +46,12 @@ class Vfs:
|
||||
|
||||
def exists(self,aFile):
|
||||
return True
|
||||
|
||||
def rename(self,aFile,newName):
|
||||
return True
|
||||
|
||||
def cleanup(self):
|
||||
return True
|
||||
|
||||
class XBMCFileSystem(Vfs):
|
||||
|
||||
@ -60,9 +67,40 @@ class XBMCFileSystem(Vfs):
|
||||
def rmdir(self,directory):
|
||||
return xbmcvfs.rmdir(directory,True)
|
||||
|
||||
def rename(self,aFile,newName):
|
||||
return xbmcvfs.rename(aFile, newName)
|
||||
|
||||
def exists(self,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):
|
||||
client = None
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
<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_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="progress_mode" type="enum" label="30022" lvalues="30082|30083|30084" default="0" />
|
||||
</category>
|
||||
|
Loading…
Reference in New Issue
Block a user