started on VFS files

This commit is contained in:
robweber 2012-11-02 15:59:40 -05:00
parent 9eb857396a
commit 6c20e3a3ad
2 changed files with 64 additions and 30 deletions

View File

@ -1,22 +1,21 @@
import xbmc
import xbmcgui
import xbmcvfs
from dropbox import client, rest, session
import utils as utils
import os
import time
APP_KEY = 'f5wlmek6aoriqax'
APP_SECRET = 'b1461sje1kxgzet'
from vfs import XBMCFilesystem,DropboxFilesystem
class FileManager:
walk_path = ''
fileArray = None
verbose_log = False
not_dir = ['.zip','.xsp','.rar']
vfs = None
def __init__(self,path):
def __init__(self,path,vfs):
self.walk_path = path
self.vfs = vfs
def createFileList(self):
self.fileArray = []
@ -53,13 +52,13 @@ class FileManager:
self.walkTree(self.walk_path + "userdata/peripheral_data")
#this part is an oddity
dirs,configFiles = xbmcvfs.listdir(self.walk_path + "userdata/")
dirs,configFiles = self.vfs.listdir(self.walk_path + "userdata/")
for aFile in configFiles:
if(aFile.endswith(".xml")):
self.addFile("userdata/" + aFile)
def walkTree(self,directory):
dirs,files = xbmcvfs.listdir(directory)
dirs,files = self.vfs.listdir(directory)
#create all the subdirs first
for aDir in dirs:
@ -89,6 +88,9 @@ class XbmcBackup:
Backup = 0
Restore = 1
#remote file system
vfs = None
local_path = ''
remote_root = ''
remote_path = ''
@ -104,11 +106,20 @@ class XbmcBackup:
def __init__(self):
self.local_path = xbmc.makeLegalFilename(xbmc.translatePath("special://home"),False);
self.configureVFS()
utils.log(utils.getString(30046))
def configureVFS(self):
if(utils.getSetting('remote_selection') == '1'):
self.remote_root = utils.getSetting('remote_path_2')
utils.setSetting("remote_path","")
self.vfs = XBMCFilesystem()
elif(utils.getSetting('remote_selection') == '0'):
self.remote_root = utils.getSetting("remote_path")
self.vfs = XBMCFilesystem()
elif(utils.getSetting('remote_selection') == '2'):
self.remote_root = '/xbmc'
#fix slashes
self.remote_root = self.remote_root.replace("\\","/")
@ -117,7 +128,6 @@ class XbmcBackup:
if(self.remote_root[-1:] != "/"):
self.remote_root = self.remote_root + "/"
utils.log(utils.getString(30046))
def run(self,mode=-1,runSilent=False):
#check if we should use the progress bar
@ -131,12 +141,6 @@ class XbmcBackup:
#append backup folder name
if(mode == self.Backup and self.remote_root != ''):
#check here if we're using Dropbox or not
if(utils.getSetting('remote_selection') == 2):
session = session.DropboxSession(APP_KEY,APP_SECRET,"app_folder")
token = session.obtain_request_token()
access_token = session.obtain_access_token(token)
else:
self.remote_path = self.remote_root + time.strftime("%Y%m%d") + "/"
elif(mode == self.Restore and utils.getSetting("backup_name") != '' and self.remote_root != ''):
self.remote_path = self.remote_root + utils.getSetting("backup_name") + "/"
@ -146,13 +150,15 @@ class XbmcBackup:
utils.log(utils.getString(30047) + ": " + self.local_path)
utils.log(utils.getString(30048) + ": " + self.remote_path)
#run the correct mode
if(mode == self.Backup):
utils.log(utils.getString(30023) + " - " + utils.getString(30016))
self.fileManager = FileManager(self.local_path)
self.fileManager = FileManager(self.local_path,XBMCFileSystem())
#for backups check if remote path exists
if(xbmcvfs.exists(self.remote_path)):
if(self.vfs.exists(self.remote_path)):
#this will fail - need a disclaimer here
utils.log(utils.getString(30050))
@ -162,7 +168,7 @@ class XbmcBackup:
total_backups = int(utils.getSetting('backup_rotation'))
if(total_backups > 0):
dirs,files = xbmcvfs.listdir(self.remote_root)
dirs,files = self.vfs.listdir(self.remote_root)
if(len(dirs) > total_backups):
#remove backups to equal total wanted
remove_num = len(dirs) - total_backups - 1
@ -172,16 +178,16 @@ class XbmcBackup:
while(remove_num >= 0 and not self.checkCancel()):
self.updateProgress(utils.getString(30054) + " " + dirs[remove_num])
utils.log("Removing backup " + dirs[remove_num])
xbmcvfs.rmdir(self.remote_root + dirs[remove_num] + "/",True)
self.vfs.rmdir(self.remote_root + dirs[remove_num] + "/")
remove_num = remove_num - 1
else:
utils.log(utils.getString(30023) + " - " + utils.getString(30017))
self.fileManager = FileManager(self.remote_path)
self.fileManager = FileManager(self.remote_path,self.vfs)
#for restores remote path must exist
if(xbmcvfs.exists(self.remote_path)):
if(self.vfs.exists(self.remote_path)):
self.restoreFiles()
else:
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045),self.remote_path)
@ -192,7 +198,7 @@ class XbmcBackup:
def syncFiles(self):
#make the remote directory
xbmcvfs.mkdir(self.remote_path)
self.vfs.mkdir(self.remote_path)
utils.log(utils.getString(30051))
self.fileManager.createFileList()

View File

@ -1,11 +1,13 @@
import utils as utils
import xbmcvfs
from dropbox import client, rest, session
APP_KEY = 'f5wlmek6aoriqax'
APP_SECRET = 'b1461sje1kxgzet'
class Vfs:
type = 'none'
def __init__(type):
self.type = type
def listdir(directory):
return {}
@ -15,3 +17,29 @@ class Vfs:
def copy(source,dest):
return True
def rmdir(directory):
return True
def exists(aFile):
return True
class XBMCFileSystem(Vfs):
self.root_path
def listdir(directory):
return xbmcvfs.listdir(directory)
def mkdir(directory):
return xbmcvfs.mkdir(directory)
def rmdir(directory):
return xbmcvfs.rmdir(directory,True)
def exists(aFile):
return xbmcvfs.exists(aFile)
class DropboxFilesystem(Vfs):
def __init__(self):
session = session.DropboxSession(APP_KEY,APP_SECRET,"app_folder")
token = session.obtain_request_token()
access_token = session.obtain_access_token(token)