match excluded with regex

This commit is contained in:
Rob Weber 2017-12-05 15:40:09 -06:00
parent 5fefbd286d
commit 756f50bba1

View File

@ -4,6 +4,7 @@ import xbmcvfs
import utils as utils import utils as utils
import time import time
import json import json
import re
from vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem,GoogleDriveFilesystem from vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem,GoogleDriveFilesystem
from progressbar import BackupProgressBar from progressbar import BackupProgressBar
from resources.lib.guisettings import GuiSettingsManager from resources.lib.guisettings import GuiSettingsManager
@ -390,6 +391,9 @@ class XbmcBackup:
for aDir in dirList: for aDir in dirList:
fileManager.addDir(aDir) fileManager.addDir(aDir)
#walk all the root trees
fileManager.walk()
#update total files
self.filesTotal = self.filesTotal + fileManager.size() self.filesTotal = self.filesTotal + fileManager.size()
return {"name":folder_name,"source":self.xbmc_vfs.root_path,"dest":self.remote_vfs.root_path,"files":fileManager.getFiles()} return {"name":folder_name,"source":self.xbmc_vfs.root_path,"dest":self.remote_vfs.root_path,"files":fileManager.getFiles()}
@ -502,11 +506,17 @@ class XbmcBackup:
class FileManager: class FileManager:
not_dir = ['.zip','.xsp','.rar'] not_dir = ['.zip','.xsp','.rar']
exclude_dir = [] exclude_dir = []
root_dirs = []
def __init__(self,vfs): def __init__(self,vfs):
self.vfs = vfs self.vfs = vfs
self.fileArray = [] self.fileArray = []
def walk(self):
for aDir in self.root_dirs:
self.addFile('-' + xbmc.translatePath(aDir['path']))
self.walkTree(xbmc.translatePath(aDir['path']),aDir['recurse'])
def walkTree(self,directory,recurse=True): def walkTree(self,directory,recurse=True):
if(directory[-1:] == '/' or directory[-1:] == '\\'): if(directory[-1:] == '/' or directory[-1:] == '\\'):
@ -521,7 +531,11 @@ class FileManager:
dirPath = xbmc.validatePath(xbmc.translatePath(directory + "/" + aDir)) dirPath = xbmc.validatePath(xbmc.translatePath(directory + "/" + aDir))
file_ext = aDir.split('.')[-1] file_ext = aDir.split('.')[-1]
if(not dirPath in self.exclude_dir): #check if directory is excluded
regex = re.compile(".*(" + aDir + ").*")
excludedCheck = [m.group(0) for l in self.exclude_dir for m in [regex.search(l)] if m]
if(len(excludedCheck) == 0):
self.addFile("-" + dirPath) self.addFile("-" + dirPath)
@ -542,10 +556,9 @@ class FileManager:
def addDir(self,dirMeta): def addDir(self,dirMeta):
if(dirMeta['type'] == 'include'): if(dirMeta['type'] == 'include'):
self.addFile('-' + xbmc.translatePath(dirMeta['path'])) self.root_dirs.append({'path':dirMeta['path'],'recurse':dirMeta['recurse']})
self.walkTree(xbmc.translatePath(dirMeta['path']),dirMeta['recurse'])
else: else:
self.excludeFile('-' + xbmc.translatePath(dirMeta['path'])) self.excludeFile(xbmc.translatePath(dirMeta['path']))
def addFile(self,filename): def addFile(self,filename):
try: try:
@ -564,12 +577,15 @@ class FileManager:
filename = filename.decode('ISO-8859-2') filename = filename.decode('ISO-8859-2')
#write the full remote path name of this file #write the full remote path name of this file
utils.log("Exclude File: " + filename,xbmc.LOGDEBUG) utils.log("Exclude File: " + filename)
self.exclude_dir.append(filename) self.exclude_dir.append(filename)
def getFiles(self): def getFiles(self):
result = self.fileArray result = self.fileArray
self.fileArray = [] self.fileArray = []
self.root_paths = []
self.exclude_dir = []
return result return result
def size(self): def size(self):