pep8 commas

This commit is contained in:
Rob Weber 2019-11-25 15:45:41 -06:00
parent 0c79aef4e7
commit 92ec8bf25c
11 changed files with 203 additions and 203 deletions

View File

@ -32,14 +32,14 @@ if("mode" in params):
# if mode wasn't passed in as arg, get from user
if(mode == -1):
# by default, Backup,Restore,Open Settings
options = [utils.getString(30016),utils.getString(30017),utils.getString(30099)]
options = [utils.getString(30016), utils.getString(30017), utils.getString(30099)]
# find out if we're using the advanced editor
if(int(utils.getSetting('backup_selection_type')) == 1):
options.append(utils.getString(30125))
# figure out if this is a backup or a restore from the user
mode = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30023),options)
mode = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30023), options)
# check if program should be run
if(mode != -1):
@ -51,7 +51,7 @@ if(mode != -1):
utils.openSettings()
elif(mode == 3 and int(utils.getSetting('backup_selection_type')) == 1):
# open the advanced editor
xbmc.executebuiltin('RunScript(special://home/addons/script.xbmcbackup/launcher.py,action=advanced_editor)')
xbmc.executebuiltin('RunScript(special://home/addons/script.xbmcbackup/launcher.py, action=advanced_editor)')
elif(backup.remoteConfigured()):
if(mode == backup.Restore):
@ -77,7 +77,7 @@ if(mode != -1):
utils.log(params['archive'] + ' is not a valid restore point')
else:
# allow user to select the backup to restore from
selectedRestore = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30021),pointNames)
selectedRestore = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30021), pointNames)
if(selectedRestore != -1):
backup.selectRestore(restorePoints[selectedRestore][0])
@ -90,5 +90,5 @@ if(mode != -1):
backup.backup()
else:
# can't go any further
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045))
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30045))
utils.openSettings()

View File

@ -12,13 +12,13 @@ def authorize_cloud(cloudProvider):
authorizer = DropboxAuthorizer()
if(authorizer.authorize()):
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30027) + ' ' + utils.getString(30106))
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30027) + ' ' + utils.getString(30106))
else:
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30107) + ' ' + utils.getString(30027))
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30107) + ' ' + utils.getString(30027))
def remove_auth():
# triggered from settings.xml - asks if user wants to delete OAuth token information
shouldDelete = xbmcgui.Dialog().yesno(utils.getString(30093),utils.getString(30094),utils.getString(30095),autoclose=7000)
shouldDelete = xbmcgui.Dialog().yesno(utils.getString(30093), utils.getString(30094), utils.getString(30095), autoclose=7000)
if(shouldDelete):
# delete any of the known token file types

View File

@ -12,19 +12,19 @@ class BackupSetManager:
# try and read in the custom file
self._readFile()
def addSet(self,aSet):
self.paths[aSet['name']] = {'root':aSet['root'],'dirs':[{"type":"include","path":aSet['root'],'recurse':True}]}
def addSet(self, aSet):
self.paths[aSet['name']] = {'root':aSet['root'], 'dirs':[{"type":"include", "path":aSet['root'], 'recurse':True}]}
# save the file
self._writeFile()
def updateSet(self,name,aSet):
def updateSet(self, name, aSet):
self.paths[name] = aSet
# save the file
self._writeFile()
def deleteSet(self,index):
def deleteSet(self, index):
# match the index to a key
keys = self.getSets()
@ -41,18 +41,18 @@ class BackupSetManager:
return keys
def getSet(self,index):
def getSet(self, index):
keys = self.getSets();
# return the set at this index
return {'name':keys[index],'set':self.paths[keys[index]]}
return {'name':keys[index], 'set':self.paths[keys[index]]}
def validateSetName(self,name):
def validateSetName(self, name):
return (name not in self.getSets())
def _writeFile(self):
# create the custom file
aFile = xbmcvfs.File(self.jsonFile,'w')
aFile = xbmcvfs.File(self.jsonFile, 'w')
aFile.write(json.dumps(self.paths))
aFile.close()
@ -76,25 +76,25 @@ class AdvancedBackupEditor:
def __init__(self):
self.dialog = xbmcgui.Dialog()
def _cleanPath(self,root,path):
def _cleanPath(self, root, path):
return path[len(root)-1:]
def _validatePath(self,root,path):
def _validatePath(self, root, path):
return path.startswith(root)
def createSet(self):
backupSet = None
name = self.dialog.input(utils.getString(30110),defaultt='Backup Set')
name = self.dialog.input(utils.getString(30110), defaultt='Backup Set')
if(name != None):
# give a choice to start in home or enter a root path
enterHome = self.dialog.yesno(utils.getString(30111),line1=utils.getString(30112) + " - " + utils.getString(30114),line2=utils.getString(30113) + " - " + utils.getString(30115),nolabel=utils.getString(30112),yeslabel=utils.getString(30113))
enterHome = self.dialog.yesno(utils.getString(30111), line1=utils.getString(30112) + " - " + utils.getString(30114), line2=utils.getString(30113) + " - " + utils.getString(30115), nolabel=utils.getString(30112), yeslabel=utils.getString(30113))
rootFolder = 'special://home'
if(enterHome):
rootFolder = self.dialog.input(utils.getString(30116),defaultt=rootFolder)
rootFolder = self.dialog.input(utils.getString(30116), defaultt=rootFolder)
# direcotry has to end in slash
if(rootFolder[:-1] != '/'):
@ -102,52 +102,52 @@ class AdvancedBackupEditor:
# check that this path even exists
if(not xbmcvfs.exists(xbmc.translatePath(rootFolder))):
self.dialog.ok(utils.getString(30117),utils.getString(30118),rootFolder)
self.dialog.ok(utils.getString(30117), utils.getString(30118), rootFolder)
return None
else:
# select path to start set
rootFolder = self.dialog.browse(type=0,heading=utils.getString(30119),shares='files',defaultt=rootFolder)
rootFolder = self.dialog.browse(type=0, heading=utils.getString(30119), shares='files', defaultt=rootFolder)
backupSet = {'name':name,'root':rootFolder}
backupSet = {'name':name, 'root':rootFolder}
return backupSet
def editSet(self,name,backupSet):
def editSet(self ,name, backupSet):
optionSelected = ''
rootPath = backupSet['root']
utils.log(rootPath)
while(optionSelected != -1):
options = [xbmcgui.ListItem(utils.getString(30120),"Exclude a specific folder from this backup set"),xbmcgui.ListItem(utils.getString(30135),"Include a specific folder to this backup set"),xbmcgui.ListItem(rootPath,utils.getString(30121))]
options = [xbmcgui.ListItem(utils.getString(30120), "Exclude a specific folder from this backup set"), xbmcgui.ListItem(utils.getString(30135), "Include a specific folder to this backup set"), xbmcgui.ListItem(rootPath, utils.getString(30121))]
for aDir in backupSet['dirs']:
if(aDir['type'] == 'exclude'):
options.append(xbmcgui.ListItem(self._cleanPath(rootPath,aDir['path']),"%s: %s" % ("Type",utils.getString(30129))))
options.append(xbmcgui.ListItem(self._cleanPath(rootPath, aDir['path']),"%s: %s" % ("Type", utils.getString(30129))))
elif(aDir['type'] == 'include'):
options.append(xbmcgui.ListItem(self._cleanPath(rootPath,aDir['path']),"%s: %s | %s: %s" % ("Type",utils.getString(30134),"Include Sub Folders",str(aDir['recurse']))))
options.append(xbmcgui.ListItem(self._cleanPath(rootPath, aDir['path']),"%s: %s | %s: %s" % ("Type", utils.getString(30134), "Include Sub Folders", str(aDir['recurse']))))
optionSelected = self.dialog.select(utils.getString(30122) + ' ' + name,options,useDetails=True)
optionSelected = self.dialog.select(utils.getString(30122) + ' ' + name, options, useDetails=True)
if(optionSelected == 0 or optionSelected == 1):
# add a folder, will equal root if cancel is hit
addFolder = self.dialog.browse(type=0,heading=utils.getString(30120),shares='files',defaultt=backupSet['root'])
addFolder = self.dialog.browse(type=0, heading=utils.getString(30120), shares='files', defaultt=backupSet['root'])
if(addFolder.startswith(rootPath)):
if(not any(addFolder == aDir['path'] for aDir in backupSet['dirs'])):
# cannot add root as an exclusion
if(optionSelected == 0 and addFolder != backupSet['root']):
backupSet['dirs'].append({"path":addFolder,"type":"exclude"})
backupSet['dirs'].append({"path":addFolder, "type":"exclude"})
elif(optionSelected == 1):
# can add root as inclusion
backupSet['dirs'].append({"path":addFolder,"type":"include","recurse":True})
backupSet['dirs'].append({"path":addFolder, "type":"include", "recurse":True})
else:
# this path is already part of another include/exclude rule
self.dialog.ok(utils.getString(30117),utils.getString(30137),addFolder)
self.dialog.ok(utils.getString(30117), utils.getString(30137), addFolder)
else:
# folder must be under root folder
self.dialog.ok(utils.getString(30117), utils.getString(30136),rootPath)
self.dialog.ok(utils.getString(30117), utils.getString(30136), rootPath)
elif(optionSelected == 2):
self.dialog.ok(utils.getString(30121),utils.getString(30130),backupSet['root'])
self.dialog.ok(utils.getString(30121), utils.getString(30130), backupSet['root'])
elif(optionSelected > 2):
cOptions = ['Delete']
@ -157,7 +157,7 @@ class AdvancedBackupEditor:
contextOption = self.dialog.contextmenu(cOptions)
if(contextOption == 0):
if(self.dialog.yesno(heading=utils.getString(30123),line1=utils.getString(30128))):
if(self.dialog.yesno(heading=utils.getString(30123), line1=utils.getString(30128))):
# remove folder
del backupSet['dirs'][optionSelected - 3]
elif(contextOption == 1 and backupSet['dirs'][optionSelected - 3]['type'] == 'include'):
@ -171,18 +171,18 @@ class AdvancedBackupEditor:
customPaths = BackupSetManager()
# show this every time
self.dialog.ok(utils.getString(30036),utils.getString(30037))
self.dialog.ok(utils.getString(30036), utils.getString(30037))
while(exitCondition != -1):
# load the custom paths
options = [xbmcgui.ListItem(utils.getString(30126),'',utils.addon_dir() + '/resources/images/plus-icon.png')]
options = [xbmcgui.ListItem(utils.getString(30126), '', utils.addon_dir() + '/resources/images/plus-icon.png')]
for index in range(0,len(customPaths.getSets())):
for index in range(0, len(customPaths.getSets())):
aSet = customPaths.getSet(index)
options.append(xbmcgui.ListItem(aSet['name'],utils.getString(30121) + ': ' + aSet['set']['root'],utils.addon_dir() + '/resources/images/folder-icon.png'))
options.append(xbmcgui.ListItem(aSet['name'], utils.getString(30121) + ': ' + aSet['set']['root'], utils.addon_dir() + '/resources/images/folder-icon.png'))
# show the gui
exitCondition = self.dialog.select(utils.getString(30125),options,useDetails=True)
exitCondition = self.dialog.select(utils.getString(30125), options, useDetails=True)
if(exitCondition >= 0):
if(exitCondition == 0):
@ -192,34 +192,34 @@ class AdvancedBackupEditor:
if(customPaths.validateSetName(newSet['name'])):
customPaths.addSet(newSet)
else:
self.dialog.ok(utils.getString(30117), utils.getString(30138),newSet['name'])
self.dialog.ok(utils.getString(30117), utils.getString(30138), newSet['name'])
else:
# bring up a context menu
menuOption = self.dialog.contextmenu([utils.getString(30122),utils.getString(30123)])
menuOption = self.dialog.contextmenu([utils.getString(30122), utils.getString(30123)])
if(menuOption == 0):
# get the set
aSet = customPaths.getSet(exitCondition -1)
# edit the set
updatedSet = self.editSet(aSet['name'],aSet['set'])
updatedSet = self.editSet(aSet['name'], aSet['set'])
# save it
customPaths.updateSet(aSet['name'],updatedSet)
customPaths.updateSet(aSet['name'], updatedSet)
elif(menuOption == 1):
if(self.dialog.yesno(heading=utils.getString(30127),line1=utils.getString(30128))):
if(self.dialog.yesno(heading=utils.getString(30127), line1=utils.getString(30128))):
# delete this path - subtract one because of "add" item
customPaths.deleteSet(exitCondition -1)
def copySimpleConfig(self):
# disclaimer in case the user hit this on accident
shouldContinue = self.dialog.yesno(utils.getString(30139),utils.getString(30140),utils.getString(30141))
shouldContinue = self.dialog.yesno(utils.getString(30139), utils.getString(30140), utils.getString(30141))
if(shouldContinue):
source = xbmc.translatePath(utils.addon_dir() + "/resources/data/default_files.json")
dest = xbmc.translatePath(utils.data_dir() + "/custom_paths.json")
xbmcvfs.copy(source,dest)
xbmcvfs.copy(source, dest)

View File

@ -21,7 +21,7 @@ class DropboxAuthorizer:
if(self.APP_KEY == '' and self.APP_SECRET == ''):
# we can't go any farther, need these for sure
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30027) + ' ' + utils.getString(30058),utils.getString(30059))
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30027) + ' ' + utils.getString(30058), utils.getString(30059))
result = False
@ -43,13 +43,13 @@ class DropboxAuthorizer:
self._deleteToken()
# copied flow from http://dropbox-sdk-python.readthedocs.io/en/latest/moduledoc.html#dropbox.oauth.DropboxOAuth2FlowNoRedirect
flow = dropbox.oauth.DropboxOAuth2FlowNoRedirect(self.APP_KEY,self.APP_SECRET)
flow = dropbox.oauth.DropboxOAuth2FlowNoRedirect(self.APP_KEY, self.APP_SECRET)
url = flow.start()
# print url in log
utils.log("Authorize URL: " + url)
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30056),utils.getString(30057),tinyurl.shorten(url))
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30056), utils.getString(30057), tinyurl.shorten(url))
# get the auth code
code = xbmcgui.Dialog().input(utils.getString(30027) + ' ' + utils.getString(30103))
@ -84,9 +84,9 @@ class DropboxAuthorizer:
return result
def _setToken(self,token):
def _setToken(self, token):
# write the token files
token_file = open(xbmc.translatePath(utils.data_dir() + "tokens.txt"),'w')
token_file = open(xbmc.translatePath(utils.data_dir() + "tokens.txt"), 'w')
token_file.write(token)
token_file.close()

View File

@ -4,7 +4,7 @@ import json
import xbmc, xbmcgui, xbmcvfs
from . import utils as utils
from datetime import datetime
from . vfs import XBMCFileSystem,DropboxFileSystem,ZipFileSystem
from . vfs import XBMCFileSystem, DropboxFileSystem, ZipFileSystem
from . progressbar import BackupProgressBar
from resources.lib.guisettings import GuiSettingsManager
from resources.lib.extractor import ZipExtractor
@ -23,7 +23,7 @@ class XbmcBackup:
Restore = 1
# list of dirs for the "simple" file selection
simple_directory_list = ['addons','addon_data','database','game_saves','playlists','profiles','thumbnails','config']
simple_directory_list = ['addons', 'addon_data', 'database', 'game_saves', 'playlists', 'profiles', 'thumbnails', 'config']
# file systems
xbmc_vfs = None
@ -51,7 +51,7 @@ class XbmcBackup:
if(utils.getSetting('remote_selection') == '1'):
self.remote_base_path = utils.getSetting('remote_path_2');
self.remote_vfs = XBMCFileSystem(utils.getSetting('remote_path_2'))
utils.setSetting("remote_path","")
utils.setSetting("remote_path", "")
elif(utils.getSetting('remote_selection') == '0'):
self.remote_base_path = utils.getSetting('remote_path');
self.remote_vfs = XBMCFileSystem(utils.getSetting("remote_path"))
@ -68,11 +68,11 @@ class XbmcBackup:
return result
# reverse - should reverse the resulting, default is true - newest to oldest
def listBackups(self, reverse=True):
def listBackups(self, reverse=True):
result = []
# get all the folders in the current root path
dirs,files = self.remote_vfs.listdir(self.remote_base_path)
dirs, files = self.remote_vfs.listdir(self.remote_base_path)
for aDir in dirs:
if(self.remote_vfs.exists(self.remote_base_path + aDir + "/xbmcbackup.val")):
@ -80,7 +80,7 @@ class XbmcBackup:
# format the name according to regional settings
folderName = self._dateFormat(aDir)
result.append((aDir,folderName))
result.append((aDir, folderName))
for aFile in files:
file_ext = aFile.split('.')[-1]
@ -93,7 +93,7 @@ class XbmcBackup:
result.append((aFile, folderName))
result.sort(key=folderSort,reverse=reverse)
result.sort(key=folderSort, reverse=reverse)
return result
@ -129,7 +129,7 @@ class XbmcBackup:
# if this dir enabled
if(utils.getSetting('backup_' + aDir) == 'true'):
# get a file listing and append it to the allfiles array
allFiles.append(self._addBackupDir(aDir,selectedDirs[aDir]['root'],selectedDirs[aDir]['dirs']))
allFiles.append(self._addBackupDir(aDir, selectedDirs[aDir]['root'], selectedDirs[aDir]['dirs']))
else:
# advanced mode - load custom paths
selectedDirs = self._readBackupConfig(utils.data_dir() + "/custom_paths.json")
@ -143,14 +143,14 @@ class XbmcBackup:
aSet = selectedDirs[aKey]
# get file listing and append
allFiles.append(self._addBackupDir(aKey,aSet['root'],aSet['dirs']))
allFiles.append(self._addBackupDir(aKey, aSet['root'], aSet['dirs']))
# create a validation file for backup rotation
writeCheck = self._createValidationFile(allFiles)
if(not writeCheck):
# we may not be able to write to this destination for some reason
shouldContinue = xbmcgui.Dialog().yesno(utils.getString(30089),utils.getString(30090), utils.getString(30044),autoclose=25000)
shouldContinue = xbmcgui.Dialog().yesno(utils.getString(30089), utils.getString(30090), utils.getString(30044), autoclose=25000)
if(not shouldContinue):
return
@ -162,7 +162,7 @@ class XbmcBackup:
for fileGroup in allFiles:
self.xbmc_vfs.set_root(xbmc.translatePath(fileGroup['source']))
self.remote_vfs.set_root(fileGroup['dest'] + fileGroup['name'])
filesCopied = self._copyFiles(fileGroup['files'],self.xbmc_vfs,self.remote_vfs)
filesCopied = self._copyFiles(fileGroup['files'], self.xbmc_vfs, self.remote_vfs)
if(not filesCopied):
utils.showNotification(utils.getString(30092))
@ -186,11 +186,11 @@ class XbmcBackup:
self.remote_vfs = self.saved_remote_vfs
self.progressBar.updateProgress(98, utils.getString(30088))
fileCopied = self._copyFiles(fileManager.getFiles(),self.xbmc_vfs, self.remote_vfs)
fileCopied = self._copyFiles(fileManager.getFiles(), self.xbmc_vfs, self.remote_vfs)
if(not fileCopied):
# zip archive copy filed, inform the user
shouldContinue = xbmcgui.Dialog().ok(utils.getString(30089),utils.getString(30090), utils.getString(30091))
shouldContinue = xbmcgui.Dialog().ok(utils.getString(30089), utils.getString(30090), utils.getString(30091))
# delete the temp zip file
self.xbmc_vfs.rmfile(xbmc.translatePath("special://temp/" + zip_name))
@ -201,7 +201,7 @@ class XbmcBackup:
# close any files
self._closeVFS()
def restore(self,progressOverride=False,selectedSets=None):
def restore(self, progressOverride=False, selectedSets=None):
shouldContinue = self._setupVFS(self.Restore, progressOverride)
if(shouldContinue):
@ -220,12 +220,12 @@ class XbmcBackup:
zipFile = []
zipFile.append(self.remote_base_path + self.restore_point)
self._copyFiles(zipFile,self.remote_vfs, self.xbmc_vfs)
self._copyFiles(zipFile, self.remote_vfs, self.xbmc_vfs)
else:
utils.log("zip file exists already")
# extract the zip file
zip_vfs = ZipFileSystem(xbmc.translatePath("special://temp/"+ self.restore_point),'r')
zip_vfs = ZipFileSystem(xbmc.translatePath("special://temp/"+ self.restore_point), 'r')
extractor = ZipExtractor()
if(not extractor.extract(zip_vfs, xbmc.translatePath("special://temp/"), self.progressBar)):
@ -233,19 +233,19 @@ class XbmcBackup:
zip_vfs.cleanup()
self.xbmc_vfs.rmfile(xbmc.translatePath("special://temp/" + self.restore_point))
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30101))
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30101))
return
zip_vfs.cleanup()
self.progressBar.updateProgress(0,utils.getString(30049) + "......")
self.progressBar.updateProgress(0, utils.getString(30049) + "......")
# set the new remote vfs and fix xbmc path
self.remote_vfs = XBMCFileSystem(xbmc.translatePath("special://temp/" + self.restore_point.split(".")[0] + "/"))
self.xbmc_vfs.set_root(xbmc.translatePath("special://home/"))
# for restores remote path must exist
if(not self.remote_vfs.exists(self.remote_vfs.root_path)):
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045),self.remote_vfs.root_path)
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30045), self.remote_vfs.root_path)
return
valFile = self._checkValidationFile(self.remote_vfs.root_path)
@ -260,18 +260,18 @@ class XbmcBackup:
# check for the existance of an advancedsettings file
if(self.remote_vfs.exists(self.remote_vfs.root_path + "config/advancedsettings.xml") and not self.skip_advanced):
# let the user know there is an advanced settings file present
restartXbmc = xbmcgui.Dialog().yesno(utils.getString(30038),utils.getString(30039),utils.getString(30040), utils.getString(30041))
restartXbmc = xbmcgui.Dialog().yesno(utils.getString(30038), utils.getString(30039), utils.getString(30040), utils.getString(30041))
if(restartXbmc):
# add only this file to the file list
fileManager.addFile(self.remote_vfs.root_path + "config/advancedsettings.xml")
self._copyFiles(fileManager.getFiles(),self.remote_vfs,self.xbmc_vfs)
self._copyFiles(fileManager.getFiles(), self.remote_vfs, self.xbmc_vfs)
# let the service know to resume this backup on startup
self._createResumeBackupFile()
# do not continue running
xbmcgui.Dialog().ok(utils.getString(30077),utils.getString(30078))
xbmcgui.Dialog().ok(utils.getString(30077), utils.getString(30078))
return
# use a multiselect dialog to select sets to restore
@ -279,7 +279,7 @@ class XbmcBackup:
# if passed in list, skip selection
if(selectedSets == None):
selectedSets = xbmcgui.Dialog().multiselect(utils.getString(30131),restoreSets)
selectedSets = xbmcgui.Dialog().multiselect(utils.getString(30131), restoreSets)
else:
selectedSets = [restoreSets.index(n) for n in selectedSets if n in restoreSets] # if set name not found just skip it
@ -295,19 +295,19 @@ class XbmcBackup:
# walk the directory
fileManager.walkTree(self.remote_vfs.root_path + aDir['name'] + '/')
self.filesTotal = self.filesTotal + fileManager.size()
allFiles.append({"source":self.remote_vfs.root_path + aDir['name'],"dest":self.xbmc_vfs.root_path,"files":fileManager.getFiles()})
allFiles.append({"source":self.remote_vfs.root_path + aDir['name'], "dest":self.xbmc_vfs.root_path, "files":fileManager.getFiles()})
else:
utils.log("error path not found: " + self.remote_vfs.root_path + aDir['name'])
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30045),self.remote_vfs.root_path + aDir['name'])
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30045), self.remote_vfs.root_path + aDir['name'])
# restore all the files
self.filesLeft = self.filesTotal
for fileGroup in allFiles:
self.remote_vfs.set_root(fileGroup['source'])
self.xbmc_vfs.set_root(fileGroup['dest'])
self._copyFiles(fileGroup['files'],self.remote_vfs,self.xbmc_vfs)
self._copyFiles(fileGroup['files'], self.remote_vfs, self.xbmc_vfs)
self.progressBar.updateProgress(99,"Clean up operations .....")
self.progressBar.updateProgress(99, "Clean up operations .....")
if(self.restore_point.split('.')[-1] == 'zip'):
# delete the zip file and the extracted directory
@ -321,10 +321,10 @@ class XbmcBackup:
# call update addons to refresh everything
xbmc.executebuiltin('UpdateLocalAddons')
def _setupVFS(self,mode=-1,progressOverride=False):
def _setupVFS(self, mode=-1, progressOverride=False):
# set windows setting to true
window = xbmcgui.Window(10000)
window.setProperty(utils.__addon_id__ + ".running","true")
window.setProperty(utils.__addon_id__ + ".running", "true")
# append backup folder name
progressBarTitle = utils.getString(30010) + " - "
@ -334,12 +334,12 @@ class XbmcBackup:
if(self.xbmc_vfs.exists(xbmc.translatePath('special://temp/xbmc_backup_temp.zip'))):
if(not self.xbmc_vfs.rmfile(xbmc.translatePath('special://temp/xbmc_backup_temp.zip'))):
# we had some kind of error deleting the old file
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30096),utils.getString(30097))
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30096), utils.getString(30097))
return False
# save the remote file system and use the zip vfs
self.saved_remote_vfs = self.remote_vfs
self.remote_vfs = ZipFileSystem(xbmc.translatePath("special://temp/xbmc_backup_temp.zip"),"w")
self.remote_vfs = ZipFileSystem(xbmc.translatePath("special://temp/xbmc_backup_temp.zip"), "w")
self.remote_vfs.set_root(self.remote_vfs.root_path + time.strftime("%Y%m%d%H%M") + "/")
progressBarTitle = progressBarTitle + utils.getString(30023) + ": " + utils.getString(30016)
@ -358,7 +358,7 @@ class XbmcBackup:
# setup the progress bar
self.progressBar = BackupProgressBar(progressOverride)
self.progressBar.create(progressBarTitle,utils.getString(30049) + "......")
self.progressBar.create(progressBarTitle, utils.getString(30049) + "......")
# if we made it this far we're good
return True
@ -370,9 +370,9 @@ class XbmcBackup:
# reset the window setting
window = xbmcgui.Window(10000)
window.setProperty(utils.__addon_id__ + ".running","")
window.setProperty(utils.__addon_id__ + ".running", "")
def _copyFiles(self,fileList,source,dest):
def _copyFiles(self, fileList, source, dest):
result = True
utils.log("Source: " + source.root_path)
@ -384,7 +384,7 @@ class XbmcBackup:
for aFile in fileList:
if(not self.progressBar.checkCancel()):
utils.log('Writing file: ' + aFile,xbmc.LOGDEBUG)
utils.log('Writing file: ' + aFile, xbmc.LOGDEBUG)
if(aFile.startswith("-")):
self._updateProgress(aFile[len(source.root_path) + 1:])
dest.mkdir(dest.root_path + aFile[len(source.root_path) + 1:])
@ -393,12 +393,12 @@ class XbmcBackup:
wroteFile = True
destFile = dest.root_path + aFile[len(source.root_path):]
if(isinstance(source,DropboxFileSystem)):
if(isinstance(source, DropboxFileSystem)):
# if copying from cloud storage we need the file handle, use get_file
wroteFile = source.get_file(aFile,destFile)
wroteFile = source.get_file(aFile, destFile)
else:
# copy using normal method
wroteFile = dest.put(aFile,destFile)
wroteFile = dest.put(aFile, destFile)
# if result is still true but this file failed
if(not wroteFile and result):
@ -406,7 +406,7 @@ class XbmcBackup:
return result
def _addBackupDir(self,folder_name,root_path,dirList):
def _addBackupDir(self, folder_name, root_path, dirList):
utils.log('Backup set: ' + folder_name)
fileManager = FileManager(self.xbmc_vfs)
@ -419,20 +419,20 @@ class XbmcBackup:
# update total files
self.filesTotal = self.filesTotal + fileManager.size()
return {"name":folder_name,"source":root_path,"dest":self.remote_vfs.root_path,"files":fileManager.getFiles()}
return {"name":folder_name, "source":root_path, "dest":self.remote_vfs.root_path, "files":fileManager.getFiles()}
def _dateFormat(self,dirName):
def _dateFormat(self, dirName):
# create date_time object from foldername YYYYMMDDHHmm
date_time = datetime(int(dirName[0:4]),int(dirName[4:6]),int(dirName[6:8]),int(dirName[8:10]),int(dirName[10:12]))
date_time = datetime(int(dirName[0:4]), int(dirName[4:6]), int(dirName[6:8]), int(dirName[8:10]), int(dirName[10:12]))
# format the string based on region settings
result = utils.getRegionalTimestamp(date_time, ['dateshort','time'])
result = utils.getRegionalTimestamp(date_time, ['dateshort', 'time'])
return result
def _updateProgress(self,message=None):
def _updateProgress(self, message=None):
self.filesLeft = self.filesLeft - 1
self.progressBar.updateProgress(int((float(self.filesTotal - self.filesLeft)/float(self.filesTotal)) * 100),message)
self.progressBar.updateProgress(int((float(self.filesTotal - self.filesLeft)/float(self.filesTotal)) * 100), message)
def _rotateBackups(self):
total_backups = int(utils.getSetting('backup_rotation'))
@ -459,20 +459,20 @@ class XbmcBackup:
remove_num = remove_num + 1
def _createValidationFile(self,dirList):
valInfo = {"name":"XBMC Backup Validation File","xbmc_version":xbmc.getInfoLabel('System.BuildVersion'),"type":0}
def _createValidationFile(self, dirList):
valInfo = {"name":"XBMC Backup Validation File", "xbmc_version":xbmc.getInfoLabel('System.BuildVersion'), "type":0}
valDirs = []
for aDir in dirList:
valDirs.append({"name":aDir['name'],"path":aDir['source']})
valDirs.append({"name":aDir['name'], "path":aDir['source']})
valInfo['directories'] = valDirs
vFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),'w')
vFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"), 'w')
vFile.write(json.dumps(valInfo))
vFile.write("")
vFile.close()
success = self.remote_vfs.put(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),self.remote_vfs.root_path + "xbmcbackup.val")
success = self.remote_vfs.put(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"), self.remote_vfs.root_path + "xbmcbackup.val")
# remove the validation file
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"))
@ -480,23 +480,23 @@ class XbmcBackup:
if(success):
# android requires a .nomedia file to not index the directory as media
if(not xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + ".nomedia"))):
nmFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + ".nomedia"),'w')
nmFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + ".nomedia"), 'w')
nmFile.close()
success = self.remote_vfs.put(xbmc.translatePath(utils.data_dir() + ".nomedia"),self.remote_vfs.root_path + ".nomedia")
success = self.remote_vfs.put(xbmc.translatePath(utils.data_dir() + ".nomedia"), self.remote_vfs.root_path + ".nomedia")
return success
def _checkValidationFile(self,path):
def _checkValidationFile(self, path):
result = None
# copy the file and open it
if(isinstance(self.remote_vfs,DropboxFileSystem)):
if(isinstance(self.remote_vfs, DropboxFileSystem)):
self.remote_vfs.get_file(path + "xbmcbackup.val", xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"))
else:
self.xbmc_vfs.put(path + "xbmcbackup.val",xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"))
self.xbmc_vfs.put(path + "xbmcbackup.val", xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"))
vFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"),'r')
vFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"), 'r')
jsonString = vFile.read()
vFile.close()
@ -507,7 +507,7 @@ class XbmcBackup:
result = json.loads(jsonString)
if(xbmc.getInfoLabel('System.BuildVersion') != result['xbmc_version']):
shouldContinue = xbmcgui.Dialog().yesno(utils.getString(30085),utils.getString(30086),utils.getString(30044))
shouldContinue = xbmcgui.Dialog().yesno(utils.getString(30085), utils.getString(30086), utils.getString(30044))
if(not shouldContinue):
result = None
@ -519,23 +519,23 @@ class XbmcBackup:
return result
def _createResumeBackupFile(self):
rFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "resume.txt"),'w')
rFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "resume.txt"), 'w')
rFile.write(self.restore_point)
rFile.close()
def _readBackupConfig(self,aFile):
jFile = xbmcvfs.File(xbmc.translatePath(aFile),'r')
def _readBackupConfig(self, aFile):
jFile = xbmcvfs.File(xbmc.translatePath(aFile), 'r')
jsonString = jFile.read()
jFile.close()
return json.loads(jsonString)
class FileManager:
not_dir = ['.zip','.xsp','.rar']
not_dir = ['.zip', '.xsp', '.rar']
exclude_dir = []
root_dirs = []
pathSep = '/'
def __init__(self,vfs):
def __init__(self, vfs):
self.vfs = vfs
self.fileArray = []
self.exclude_dir = []
@ -545,15 +545,15 @@ class FileManager:
for aDir in self.root_dirs:
self.addFile('-' + xbmc.translatePath(aDir['path']))
self.walkTree(xbmc.translatePath(aDir['path']),aDir['recurse'])
self.walkTree(xbmc.translatePath(aDir['path']), aDir['recurse'])
def walkTree(self,directory,recurse=True):
def walkTree(self, directory, recurse=True):
utils.log('walking ' + directory + ', recurse: ' + str(recurse))
if(directory[-1:] == '/' or directory[-1:] == '\\'):
directory = directory[:-1]
if(self.vfs.exists(directory + self.pathSep)):
dirs,files = self.vfs.listdir(directory)
dirs, files = self.vfs.listdir(directory)
if(recurse):
# create all the subdirs first
@ -581,18 +581,18 @@ class FileManager:
filePath = xbmc.translatePath(directory + self.pathSep + aFile)
self.addFile(filePath)
def addDir(self,dirMeta):
def addDir(self, dirMeta):
if(dirMeta['type'] == 'include'):
self.root_dirs.append({'path':dirMeta['path'],'recurse':dirMeta['recurse']})
self.root_dirs.append({'path':dirMeta['path'], 'recurse':dirMeta['recurse']})
else:
self.excludeFile(xbmc.translatePath(dirMeta['path']))
def addFile(self,filename):
def addFile(self, filename):
# write the full remote path name of this file
utils.log("Add File: " + filename)
self.fileArray.append(filename)
def excludeFile(self,filename):
def excludeFile(self, filename):
# remove trailing slash
if(filename[-1] == '/' or filename[-1] == '\\'):

View File

@ -8,7 +8,7 @@ class ZipExtractor:
result = True # result is true unless we fail
# update the progress bar
progressBar.updateProgress(0,utils.getString(30100))
progressBar.updateProgress(0, utils.getString(30100))
# list the files
fileCount = float(len(zipFile.listFiles()))

View File

@ -33,7 +33,7 @@ class GuiSettingsManager:
updateSettings = {k: v for k, v in list(restoreSettings.items()) if (k in currentSettings and currentSettings[k] != v)}
# go through all the found settings and update them
jsonObj = {"jsonrpc":"2.0","id":1,"method":"Settings.SetSettingValue","params":{"setting":"","value":""}}
jsonObj = {"jsonrpc":"2.0", "id":1, "method":"Settings.SetSettingValue", "params":{"setting":"", "value":""}}
for anId, aValue in list(updateSettings.items()):
utils.log("updating: " + anId + ", value: " + str(aValue))
@ -42,7 +42,7 @@ class GuiSettingsManager:
xbmc.executeJSONRPC(json.dumps(jsonObj))
def __parseNodes(self,nodeList):
def __parseNodes(self, nodeList):
result = {}
for node in nodeList:
@ -62,7 +62,7 @@ class GuiSettingsManager:
return result
def _readFile(self,fileLoc):
def _readFile(self, fileLoc):
if(xbmcvfs.exists(fileLoc)):
try:

View File

@ -10,7 +10,7 @@ class BackupProgressBar:
progressBar = None
override = False
def __init__(self,progressOverride):
def __init__(self, progressOverride):
self.override = progressOverride
# check if we should use the progress bar
@ -23,20 +23,20 @@ class BackupProgressBar:
self.mode = self.BACKGROUND
self.progressBar = xbmcgui.DialogProgressBG()
def create(self,heading,message):
def create(self, heading, message):
if(self.mode != self.NONE):
self.progressBar.create(heading,message)
self.progressBar.create(heading, message)
def updateProgress(self,percent,message=None):
def updateProgress(self, percent, message=None):
# update the progress bar
if(self.mode != self.NONE):
if(message != None):
# need different calls for dialog and background bars
if(self.mode == self.DIALOG):
self.progressBar.update(percent,message)
self.progressBar.update(percent, message)
else:
self.progressBar.update(percent,message=message)
self.progressBar.update(percent, message=message)
else:
self.progressBar.update(percent)

View File

@ -12,22 +12,22 @@ def addon_dir():
def openSettings():
__Addon.openSettings()
def log(message,loglevel=xbmc.LOGDEBUG):
xbmc.log(__addon_id__ + "-" + __Addon.getAddonInfo('version') + ": " + message,level=loglevel)
def log(message, loglevel=xbmc.LOGDEBUG):
xbmc.log(__addon_id__ + "-" + __Addon.getAddonInfo('version') + ": " + message, level=loglevel)
def showNotification(message):
xbmcgui.Dialog().notification(getString(30010),message,time=4000,icon=xbmc.translatePath(__Addon.getAddonInfo('path') + "/resources/images/icon.png"))
xbmcgui.Dialog().notification(getString(30010), message, time=4000, icon=xbmc.translatePath(__Addon.getAddonInfo('path') + "/resources/images/icon.png"))
def getSetting(name):
return __Addon.getSetting(name)
def setSetting(name,value):
__Addon.setSetting(name,value)
def setSetting(name, value):
__Addon.setSetting(name, value)
def getString(string_id):
return __Addon.getLocalizedString(string_id)
def getRegionalTimestamp(date_time,dateformat=['dateshort']):
def getRegionalTimestamp(date_time, dateformat=['dateshort']):
result = ''
for aFormat in dateformat:

View File

@ -5,21 +5,21 @@ import sys
import xbmc, xbmcvfs, xbmcgui
from . import dropbox
from . import utils as utils
from .dropbox.files import WriteMode,CommitInfo,UploadSessionCursor
from .dropbox.files import WriteMode, CommitInfo, UploadSessionCursor
from . authorizers import DropboxAuthorizer
class Vfs:
root_path = None
def __init__(self,rootString):
def __init__(self, rootString):
self.set_root(rootString)
def set_root(self,rootString):
def set_root(self, rootString):
old_root = self.root_path
self.root_path = rootString
# fix slashes
self.root_path = self.root_path.replace("\\","/")
self.root_path = self.root_path.replace("\\", "/")
# check if trailing slash is included
if(self.root_path[-1:] != "/"):
@ -28,25 +28,25 @@ class Vfs:
# return the old root
return old_root
def listdir(self,directory):
def listdir(self, directory):
return {}
def mkdir(self,directory):
def mkdir(self, directory):
return True
def put(self,source,dest):
def put(self, source, dest):
return True
def rmdir(self,directory):
def rmdir(self, directory):
return True
def rmfile(self,aFile):
def rmfile(self, aFile):
return True
def exists(self,aFile):
def exists(self, aFile):
return True
def rename(self,aFile,newName):
def rename(self, aFile, newName):
return True
def cleanup(self):
@ -54,61 +54,61 @@ class Vfs:
class XBMCFileSystem(Vfs):
def listdir(self,directory):
def listdir(self, directory):
return xbmcvfs.listdir(directory)
def mkdir(self,directory):
def mkdir(self, directory):
return xbmcvfs.mkdir(xbmc.translatePath(directory))
def put(self,source,dest):
return xbmcvfs.copy(xbmc.translatePath(source),xbmc.translatePath(dest))
def put(self, source, dest):
return xbmcvfs.copy(xbmc.translatePath(source), xbmc.translatePath(dest))
def rmdir(self,directory):
return xbmcvfs.rmdir(directory,True)
def rmdir(self, directory):
return xbmcvfs.rmdir(directory, True)
def rmfile(self,aFile):
def rmfile(self, aFile):
return xbmcvfs.delete(aFile)
def rename(self,aFile,newName):
def rename(self, aFile, newName):
return xbmcvfs.rename(aFile, newName)
def exists(self,aFile):
def exists(self, aFile):
return xbmcvfs.exists(aFile)
class ZipFileSystem(Vfs):
zip = None
def __init__(self,rootString,mode):
def __init__(self, rootString, mode):
self.root_path = ""
self.zip = zipfile.ZipFile(rootString,mode=mode,compression=zipfile.ZIP_DEFLATED,allowZip64=True)
self.zip = zipfile.ZipFile(rootString, mode=mode, compression=zipfile.ZIP_DEFLATED, allowZip64=True)
def listdir(self,directory):
return [[],[]]
def listdir(self, directory):
return [[], []]
def mkdir(self,directory):
def mkdir(self, directory):
# self.zip.write(directory[len(self.root_path):])
return False
def put(self,source,dest):
def put(self, source, dest):
aFile = xbmcvfs.File(xbmc.translatePath(source),'r')
aFile = xbmcvfs.File(xbmc.translatePath(source), 'r')
self.zip.writestr(dest,aFile.readBytes())
self.zip.writestr(dest, aFile.readBytes())
return True
def rmdir(self,directory):
def rmdir(self, directory):
return False
def exists(self,aFile):
def exists(self, aFile):
return False
def cleanup(self):
self.zip.close()
def extract(self,aFile,path):
def extract(self, aFile, path):
# extract zip file to path
self.zip.extract(aFile,path)
self.zip.extract(aFile, path)
def listFiles(self):
return self.zip.infolist()
@ -119,7 +119,7 @@ class DropboxFileSystem(Vfs):
APP_KEY = ''
APP_SECRET = ''
def __init__(self,rootString):
def __init__(self, rootString):
self.set_root(rootString)
authorizer = DropboxAuthorizer()
@ -128,10 +128,10 @@ class DropboxFileSystem(Vfs):
self.client = authorizer.getClient()
else:
# tell the user to go back and run the authorizer
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30105))
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30105))
sys.exit()
def listdir(self,directory):
def listdir(self, directory):
directory = self._fix_slashes(directory)
if(self.client != None and self.exists(directory)):
@ -140,16 +140,16 @@ class DropboxFileSystem(Vfs):
metadata = self.client.files_list_folder(directory)
for aFile in metadata.entries:
if(isinstance(aFile,dropbox.files.FolderMetadata)):
if(isinstance(aFile, dropbox.files.FolderMetadata)):
dirs.append(aFile.name)
else:
files.append(aFile.name)
return [dirs,files]
return [dirs, files]
else:
return [[],[]]
return [[], []]
def mkdir(self,directory):
def mkdir(self, directory):
directory = self._fix_slashes(directory)
if(self.client != None):
# sort of odd but always return true, folder create is implicit with file upload
@ -157,11 +157,11 @@ class DropboxFileSystem(Vfs):
else:
return False
def rmdir(self,directory):
def rmdir(self, directory):
directory = self._fix_slashes(directory)
if(self.client != None and self.exists(directory)):
# dropbox is stupid and will refuse to do this sometimes, need to delete recursively
dirs,files = self.listdir(directory)
dirs, files = self.listdir(directory)
for aDir in dirs:
self.rmdir(aDir)
@ -173,7 +173,7 @@ class DropboxFileSystem(Vfs):
else:
return False
def rmfile(self,aFile):
def rmfile(self, aFile):
aFile = self._fix_slashes(aFile)
if(self.client != None and self.exists(aFile)):
@ -182,7 +182,7 @@ class DropboxFileSystem(Vfs):
else:
return False
def exists(self,aFile):
def exists(self, aFile):
aFile = self._fix_slashes(aFile)
if(self.client != None):
@ -199,31 +199,31 @@ class DropboxFileSystem(Vfs):
else:
return False
def put(self,source,dest,retry=True):
def put(self, source, dest, retry=True):
dest = self._fix_slashes(dest)
if(self.client != None):
# open the file and get its size
f = open(source,'rb')
f = open(source, 'rb')
f_size = os.path.getsize(source)
try:
if(f_size < self.MAX_CHUNK):
# use the regular upload
response = self.client.files_upload(f.read(),dest,mode=WriteMode('overwrite'))
response = self.client.files_upload(f.read(), dest, mode=WriteMode('overwrite'))
else:
# start the upload session
upload_session = self.client.files_upload_session_start(f.read(self.MAX_CHUNK))
upload_cursor = UploadSessionCursor(upload_session.session_id,f.tell())
upload_cursor = UploadSessionCursor(upload_session.session_id, f.tell())
while(f.tell() < f_size):
# check if we should finish the upload
if((f_size - f.tell()) <= self.MAX_CHUNK):
# upload and close
self.client.files_upload_session_finish(f.read(self.MAX_CHUNK),upload_cursor,CommitInfo(dest,mode=WriteMode('overwrite')))
self.client.files_upload_session_finish(f.read(self.MAX_CHUNK), upload_cursor, CommitInfo(dest, mode=WriteMode('overwrite')))
else:
# upload a part and store the offset
self.client.files_upload_session_append_v2(f.read(self.MAX_CHUNK),upload_cursor)
self.client.files_upload_session_append_v2(f.read(self.MAX_CHUNK), upload_cursor)
upload_cursor.offset = f.tell()
# if no errors we're good!
@ -233,23 +233,23 @@ class DropboxFileSystem(Vfs):
# if we have an exception retry
if(retry):
return self.put(source,dest,False)
return self.put(source, dest, False)
else:
# tried once already, just quit
return False
else:
return False
def get_file(self,source,dest):
def get_file(self, source, dest):
if(self.client != None):
# write the file locally
f = self.client.files_download_to_file(dest,source)
f = self.client.files_download_to_file(dest, source)
return True
else:
return False
def _fix_slashes(self,filename):
result = filename.replace('\\','/')
def _fix_slashes(self, filename):
result = filename.replace('\\', '/')
# root needs to be a blank string
if(result == '/'):

View File

@ -57,8 +57,8 @@ class BackupScheduler:
# display upgrade messages if they exist
if(int(utils.getSetting('upgrade_notes')) < UPGRADE_INT):
xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30132))
utils.setSetting('upgrade_notes',str(UPGRADE_INT))
xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30132))
utils.setSetting('upgrade_notes', str(UPGRADE_INT))
# check if a backup should be resumed
resumeRestore = self._resumeCheck()
@ -94,7 +94,7 @@ class BackupScheduler:
# delete monitor to free up memory
del self.monitor
def doScheduledBackup(self,progress_mode):
def doScheduledBackup(self, progress_mode):
if(progress_mode != 2):
utils.showNotification(utils.getString(30053))
@ -111,22 +111,22 @@ class BackupScheduler:
if(int(utils.getSetting("schedule_interval")) == 0):
# disable the scheduler after this run
self.enabled = "false"
utils.setSetting('enable_scheduler','false')
utils.setSetting('enable_scheduler', 'false')
else:
utils.showNotification(utils.getString(30045))
def findNextRun(self,now):
def findNextRun(self, now):
progress_mode = int(utils.getSetting('progress_mode'))
# find the cron expression and get the next run time
cron_exp = self.parseSchedule()
cron_ob = croniter(cron_exp,datetime.fromtimestamp(now))
cron_ob = croniter(cron_exp, datetime.fromtimestamp(now))
new_run_time = cron_ob.get_next(float)
if(new_run_time != self.next_run):
self.next_run = new_run_time
utils.log("scheduler will run again on " + utils.getRegionalTimestamp(datetime.fromtimestamp(self.next_run),['dateshort','time']))
utils.log("scheduler will run again on " + utils.getRegionalTimestamp(datetime.fromtimestamp(self.next_run), ['dateshort', 'time']))
# write the next time to a file
fh = xbmcvfs.File(self.next_run_path, 'w')
@ -135,7 +135,7 @@ class BackupScheduler:
# only show when not in silent mode
if(progress_mode != 2):
utils.showNotification(utils.getString(30081) + " " + utils.getRegionalTimestamp(datetime.fromtimestamp(self.next_run),['dateshort','time']))
utils.showNotification(utils.getString(30081) + " " + utils.getRegionalTimestamp(datetime.fromtimestamp(self.next_run), ['dateshort', 'time']))
def settingsChanged(self):
current_enabled = utils.getSetting("enable_scheduler")
@ -174,18 +174,18 @@ class BackupScheduler:
def _resumeCheck(self):
shouldContinue = False
if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "resume.txt"))):
rFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "resume.txt"),'r')
rFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "resume.txt"), 'r')
self.restore_point = rFile.read()
rFile.close()
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "resume.txt"))
shouldContinue = xbmcgui.Dialog().yesno(utils.getString(30042),utils.getString(30043),utils.getString(30044))
shouldContinue = xbmcgui.Dialog().yesno(utils.getString(30042), utils.getString(30043), utils.getString(30044))
return shouldContinue
class UpdateMonitor(xbmc.Monitor):
update_method = None
def __init__(self,*args, **kwargs):
def __init__(self, *args, **kwargs):
xbmc.Monitor.__init__(self)
self.update_method = kwargs['update_method']