fixed backup rotation

This commit is contained in:
robweber 2012-11-05 11:13:48 -06:00
parent 140610db5a
commit 33e10c2a61
2 changed files with 10 additions and 4 deletions

View File

@ -2,7 +2,7 @@ import xbmc
import xbmcgui import xbmcgui
import xbmcvfs import xbmcvfs
import utils as utils import utils as utils
import os import os.path
import time import time
from vfs import XBMCFileSystem,DropboxFileSystem from vfs import XBMCFileSystem,DropboxFileSystem
@ -131,8 +131,10 @@ class XbmcBackup:
mode = int(utils.getSetting('addon_mode')) mode = int(utils.getSetting('addon_mode'))
#append backup folder name #append backup folder name
remote_base_path = ""
if(mode == self.Backup and self.remote_vfs.root_path != ''): if(mode == self.Backup and self.remote_vfs.root_path != ''):
self.remote_vfs.set_root(self.remote_vfs.root_path + time.strftime("%Y%m%d") + "/") #capture base path for backup rotation
remote_base_path = self.remote_vfs.set_root(self.remote_vfs.root_path + time.strftime("%Y%m%d") + "/")
elif(mode == self.Restore and utils.getSetting("backup_name") != '' and self.remote_vfs.root_path != ''): elif(mode == self.Restore and utils.getSetting("backup_name") != '' and self.remote_vfs.root_path != ''):
self.remote_vfs.set_root(self.remote_vfs.root_path + utils.getSetting("backup_name") + "/") self.remote_vfs.set_root(self.remote_vfs.root_path + utils.getSetting("backup_name") + "/")
else: else:
@ -157,7 +159,7 @@ class XbmcBackup:
total_backups = int(utils.getSetting('backup_rotation')) total_backups = int(utils.getSetting('backup_rotation'))
if(total_backups > 0): if(total_backups > 0):
dirs,files = self.remote_vfs.listdir(self.remote_vfs.root_path) dirs,files = self.remote_vfs.listdir(remote_base_path)
if(len(dirs) > total_backups): if(len(dirs) > total_backups):
#remove backups to equal total wanted #remove backups to equal total wanted
dirs.sort() dirs.sort()
@ -168,7 +170,7 @@ class XbmcBackup:
while(remove_num >= 0 and not self.checkCancel()): while(remove_num >= 0 and not self.checkCancel()):
self.updateProgress(utils.getString(30054) + " " + dirs[remove_num]) self.updateProgress(utils.getString(30054) + " " + dirs[remove_num])
utils.log("Removing backup " + dirs[remove_num]) utils.log("Removing backup " + dirs[remove_num])
self.remote_vfs.rmdir(self.remote_vfs.root_path + dirs[remove_num] + "/") self.remote_vfs.rmdir(remote_base_path + dirs[remove_num] + "/")
remove_num = remove_num - 1 remove_num = remove_num - 1

View File

@ -10,6 +10,7 @@ class Vfs:
root_path = None root_path = None
def set_root(self,rootString): def set_root(self,rootString):
old_root = self.root_path
self.root_path = rootString self.root_path = rootString
#fix slashes #fix slashes
@ -19,6 +20,9 @@ class Vfs:
if(self.root_path[-1:] != "/"): if(self.root_path[-1:] != "/"):
self.root_path = self.root_path + "/" self.root_path = self.root_path + "/"
#return the old root
return old_root
def listdir(self,directory): def listdir(self,directory):
return {} return {}