mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-15 04:45:49 +01:00
pep8 styling round 2
This commit is contained in:
parent
3e9de429dd
commit
95649c2b3f
@ -12,7 +12,7 @@ def get_params():
|
|||||||
args = i
|
args = i
|
||||||
if('=' in args):
|
if('=' in args):
|
||||||
if(args.startswith('?')):
|
if(args.startswith('?')):
|
||||||
args = args[1:] # legacy in case of url params
|
args = args[1:] # legacy in case of url params
|
||||||
splitString = args.split('=')
|
splitString = args.split('=')
|
||||||
param[splitString[0]] = splitString[1]
|
param[splitString[0]] = splitString[1]
|
||||||
except:
|
except:
|
||||||
|
@ -4,6 +4,7 @@ import xbmcgui
|
|||||||
import xbmcvfs
|
import xbmcvfs
|
||||||
from . import utils as utils
|
from . import utils as utils
|
||||||
|
|
||||||
|
|
||||||
class BackupSetManager:
|
class BackupSetManager:
|
||||||
jsonFile = xbmc.translatePath(utils.data_dir() + "custom_paths.json")
|
jsonFile = xbmc.translatePath(utils.data_dir() + "custom_paths.json")
|
||||||
paths = None
|
paths = None
|
||||||
@ -15,7 +16,7 @@ class BackupSetManager:
|
|||||||
self._readFile()
|
self._readFile()
|
||||||
|
|
||||||
def addSet(self, aSet):
|
def addSet(self, aSet):
|
||||||
self.paths[aSet['name']] = {'root':aSet['root'], 'dirs':[{"type":"include", "path":aSet['root'], 'recurse':True}]}
|
self.paths[aSet['name']] = {'root': aSet['root'], 'dirs': [{"type":"include", "path": aSet['root'], 'recurse': True}]}
|
||||||
|
|
||||||
# save the file
|
# save the file
|
||||||
self._writeFile()
|
self._writeFile()
|
||||||
@ -33,7 +34,7 @@ class BackupSetManager:
|
|||||||
# delete this set
|
# delete this set
|
||||||
del self.paths[keys[index]]
|
del self.paths[keys[index]]
|
||||||
|
|
||||||
#save the file
|
# save the file
|
||||||
self._writeFile()
|
self._writeFile()
|
||||||
|
|
||||||
def getSets(self):
|
def getSets(self):
|
||||||
@ -44,10 +45,10 @@ class BackupSetManager:
|
|||||||
return keys
|
return keys
|
||||||
|
|
||||||
def getSet(self, index):
|
def getSet(self, index):
|
||||||
keys = self.getSets();
|
keys = self.getSets()
|
||||||
|
|
||||||
# return the set at this index
|
# 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())
|
return (name not in self.getSets())
|
||||||
@ -79,7 +80,7 @@ class AdvancedBackupEditor:
|
|||||||
self.dialog = xbmcgui.Dialog()
|
self.dialog = xbmcgui.Dialog()
|
||||||
|
|
||||||
def _cleanPath(self, root, path):
|
def _cleanPath(self, root, path):
|
||||||
return path[len(root)-1:]
|
return path[len(root) - 1:]
|
||||||
|
|
||||||
def _validatePath(self, root, path):
|
def _validatePath(self, root, path):
|
||||||
return path.startswith(root)
|
return path.startswith(root)
|
||||||
@ -89,7 +90,7 @@ class AdvancedBackupEditor:
|
|||||||
|
|
||||||
name = self.dialog.input(utils.getString(30110), defaultt='Backup Set')
|
name = self.dialog.input(utils.getString(30110), defaultt='Backup Set')
|
||||||
|
|
||||||
if(name != None):
|
if(name is not None):
|
||||||
|
|
||||||
# give a choice to start in home or enter a root path
|
# 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))
|
||||||
@ -110,11 +111,11 @@ class AdvancedBackupEditor:
|
|||||||
# select path to start set
|
# 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
|
return backupSet
|
||||||
|
|
||||||
def editSet(self ,name, backupSet):
|
def editSet(self, name, backupSet):
|
||||||
optionSelected = ''
|
optionSelected = ''
|
||||||
rootPath = backupSet['root']
|
rootPath = backupSet['root']
|
||||||
utils.log(rootPath)
|
utils.log(rootPath)
|
||||||
@ -123,9 +124,9 @@ class AdvancedBackupEditor:
|
|||||||
|
|
||||||
for aDir in backupSet['dirs']:
|
for aDir in backupSet['dirs']:
|
||||||
if(aDir['type'] == 'exclude'):
|
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'):
|
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)
|
||||||
|
|
||||||
@ -138,10 +139,10 @@ class AdvancedBackupEditor:
|
|||||||
if(not any(addFolder == aDir['path'] for aDir in backupSet['dirs'])):
|
if(not any(addFolder == aDir['path'] for aDir in backupSet['dirs'])):
|
||||||
# cannot add root as an exclusion
|
# cannot add root as an exclusion
|
||||||
if(optionSelected == 0 and addFolder != backupSet['root']):
|
if(optionSelected == 0 and addFolder != backupSet['root']):
|
||||||
backupSet['dirs'].append({"path":addFolder, "type":"exclude"})
|
backupSet['dirs'].append({"path": addFolder, "type": "exclude"})
|
||||||
elif(optionSelected == 1):
|
elif(optionSelected == 1):
|
||||||
# can add root as inclusion
|
# can add root as inclusion
|
||||||
backupSet['dirs'].append({"path":addFolder, "type":"include", "recurse":True})
|
backupSet['dirs'].append({"path": addFolder, "type": "include", "recurse": True})
|
||||||
else:
|
else:
|
||||||
# this path is already part of another include/exclude rule
|
# 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)
|
||||||
@ -201,7 +202,7 @@ class AdvancedBackupEditor:
|
|||||||
|
|
||||||
if(menuOption == 0):
|
if(menuOption == 0):
|
||||||
# get the set
|
# get the set
|
||||||
aSet = customPaths.getSet(exitCondition -1)
|
aSet = customPaths.getSet(exitCondition - 1)
|
||||||
|
|
||||||
# edit the set
|
# edit the set
|
||||||
updatedSet = self.editSet(aSet['name'], aSet['set'])
|
updatedSet = self.editSet(aSet['name'], aSet['set'])
|
||||||
@ -212,7 +213,7 @@ class AdvancedBackupEditor:
|
|||||||
elif(menuOption == 1):
|
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
|
# delete this path - subtract one because of "add" item
|
||||||
customPaths.deleteSet(exitCondition -1)
|
customPaths.deleteSet(exitCondition - 1)
|
||||||
|
|
||||||
def copySimpleConfig(self):
|
def copySimpleConfig(self):
|
||||||
# disclaimer in case the user hit this on accident
|
# disclaimer in case the user hit this on accident
|
||||||
@ -223,5 +224,3 @@ class AdvancedBackupEditor:
|
|||||||
dest = xbmc.translatePath(utils.data_dir() + "/custom_paths.json")
|
dest = xbmc.translatePath(utils.data_dir() + "/custom_paths.json")
|
||||||
|
|
||||||
xbmcvfs.copy(source, dest)
|
xbmcvfs.copy(source, dest)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DropboxAuthorizer:
|
class DropboxAuthorizer:
|
||||||
APP_KEY = ""
|
APP_KEY = ""
|
||||||
APP_SECRET = ""
|
APP_SECRET = ""
|
||||||
@ -56,7 +57,7 @@ class DropboxAuthorizer:
|
|||||||
# get the auth code
|
# get the auth code
|
||||||
code = xbmcgui.Dialog().input(utils.getString(30027) + ' ' + utils.getString(30103))
|
code = xbmcgui.Dialog().input(utils.getString(30027) + ' ' + utils.getString(30103))
|
||||||
|
|
||||||
#if user authorized this will work
|
# if user authorized this will work
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_token = flow.finish(code)
|
user_token = flow.finish(code)
|
||||||
@ -74,13 +75,13 @@ class DropboxAuthorizer:
|
|||||||
user_token = self._getToken()
|
user_token = self._getToken()
|
||||||
|
|
||||||
if(user_token != ''):
|
if(user_token != ''):
|
||||||
#create the client
|
# create the client
|
||||||
result = dropbox.Dropbox(user_token)
|
result = dropbox.Dropbox(user_token)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result.users_get_current_account()
|
result.users_get_current_account()
|
||||||
except:
|
except:
|
||||||
#this didn't work, delete the token file
|
# this didn't work, delete the token file
|
||||||
self._deleteToken()
|
self._deleteToken()
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ def folderSort(aKey):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class XbmcBackup:
|
class XbmcBackup:
|
||||||
# constants for initiating a back or restore
|
# constants for initiating a back or restore
|
||||||
Backup = 0
|
Backup = 0
|
||||||
@ -51,7 +52,7 @@ class XbmcBackup:
|
|||||||
|
|
||||||
def configureRemote(self):
|
def configureRemote(self):
|
||||||
if(utils.getSetting('remote_selection') == '1'):
|
if(utils.getSetting('remote_selection') == '1'):
|
||||||
self.remote_base_path = utils.getSetting('remote_path_2');
|
self.remote_base_path = utils.getSetting('remote_path_2')
|
||||||
self.remote_vfs = XBMCFileSystem(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'):
|
elif(utils.getSetting('remote_selection') == '0'):
|
||||||
@ -70,7 +71,7 @@ class XbmcBackup:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
# reverse - should reverse the resulting, default is true - newest to oldest
|
# reverse - should reverse the resulting, default is true - newest to oldest
|
||||||
def listBackups(self, reverse=True):
|
def listBackups(self, reverse=True):
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
# get all the folders in the current root path
|
# get all the folders in the current root path
|
||||||
@ -227,7 +228,7 @@ class XbmcBackup:
|
|||||||
utils.log("zip file exists already")
|
utils.log("zip file exists already")
|
||||||
|
|
||||||
# extract the zip file
|
# 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()
|
extractor = ZipExtractor()
|
||||||
|
|
||||||
if(not extractor.extract(zip_vfs, xbmc.translatePath("special://temp/"), self.progressBar)):
|
if(not extractor.extract(zip_vfs, xbmc.translatePath("special://temp/"), self.progressBar)):
|
||||||
@ -280,12 +281,12 @@ class XbmcBackup:
|
|||||||
restoreSets = [n['name'] for n in valFile['directories']]
|
restoreSets = [n['name'] for n in valFile['directories']]
|
||||||
|
|
||||||
# if passed in list, skip selection
|
# if passed in list, skip selection
|
||||||
if(selectedSets == None):
|
if(selectedSets is None):
|
||||||
selectedSets = xbmcgui.Dialog().multiselect(utils.getString(30131), restoreSets)
|
selectedSets = xbmcgui.Dialog().multiselect(utils.getString(30131), restoreSets)
|
||||||
else:
|
else:
|
||||||
selectedSets = [restoreSets.index(n) for n in selectedSets if n in restoreSets] # if set name not found just skip it
|
selectedSets = [restoreSets.index(n) for n in selectedSets if n in restoreSets] # if set name not found just skip it
|
||||||
|
|
||||||
if(selectedSets != None):
|
if(selectedSets is not None):
|
||||||
# go through each of the directories in the backup and write them to the correct location
|
# go through each of the directories in the backup and write them to the correct location
|
||||||
for index in selectedSets:
|
for index in selectedSets:
|
||||||
|
|
||||||
@ -297,7 +298,7 @@ class XbmcBackup:
|
|||||||
# walk the directory
|
# walk the directory
|
||||||
fileManager.walkTree(self.remote_vfs.root_path + aDir['name'] + '/')
|
fileManager.walkTree(self.remote_vfs.root_path + aDir['name'] + '/')
|
||||||
self.filesTotal = self.filesTotal + fileManager.size()
|
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:
|
else:
|
||||||
utils.log("error path not found: " + self.remote_vfs.root_path + aDir['name'])
|
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'])
|
||||||
@ -357,7 +358,6 @@ class XbmcBackup:
|
|||||||
utils.log(utils.getString(30047) + ": " + self.xbmc_vfs.root_path)
|
utils.log(utils.getString(30047) + ": " + self.xbmc_vfs.root_path)
|
||||||
utils.log(utils.getString(30048) + ": " + self.remote_vfs.root_path)
|
utils.log(utils.getString(30048) + ": " + self.remote_vfs.root_path)
|
||||||
|
|
||||||
|
|
||||||
# setup the progress bar
|
# setup the progress bar
|
||||||
self.progressBar = BackupProgressBar(progressOverride)
|
self.progressBar = BackupProgressBar(progressOverride)
|
||||||
self.progressBar.create(progressBarTitle, utils.getString(30049) + "......")
|
self.progressBar.create(progressBarTitle, utils.getString(30049) + "......")
|
||||||
@ -421,7 +421,7 @@ class XbmcBackup:
|
|||||||
# update total files
|
# update total files
|
||||||
self.filesTotal = self.filesTotal + fileManager.size()
|
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
|
# create date_time object from foldername YYYYMMDDHHmm
|
||||||
@ -434,7 +434,7 @@ class XbmcBackup:
|
|||||||
|
|
||||||
def _updateProgress(self, message=None):
|
def _updateProgress(self, message=None):
|
||||||
self.filesLeft = self.filesLeft - 1
|
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):
|
def _rotateBackups(self):
|
||||||
total_backups = int(utils.getSetting('backup_rotation'))
|
total_backups = int(utils.getSetting('backup_rotation'))
|
||||||
@ -462,11 +462,11 @@ class XbmcBackup:
|
|||||||
remove_num = remove_num + 1
|
remove_num = remove_num + 1
|
||||||
|
|
||||||
def _createValidationFile(self, dirList):
|
def _createValidationFile(self, dirList):
|
||||||
valInfo = {"name":"XBMC Backup Validation File", "xbmc_version":xbmc.getInfoLabel('System.BuildVersion'), "type":0}
|
valInfo = {"name": "XBMC Backup Validation File", "xbmc_version": xbmc.getInfoLabel('System.BuildVersion'), "type": 0}
|
||||||
valDirs = []
|
valDirs = []
|
||||||
|
|
||||||
for aDir in dirList:
|
for aDir in dirList:
|
||||||
valDirs.append({"name":aDir['name'], "path":aDir['source']})
|
valDirs.append({"name": aDir['name'], "path": aDir['source']})
|
||||||
valInfo['directories'] = valDirs
|
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')
|
||||||
@ -531,6 +531,7 @@ class XbmcBackup:
|
|||||||
jFile.close()
|
jFile.close()
|
||||||
return json.loads(jsonString)
|
return json.loads(jsonString)
|
||||||
|
|
||||||
|
|
||||||
class FileManager:
|
class FileManager:
|
||||||
not_dir = ['.zip', '.xsp', '.rar']
|
not_dir = ['.zip', '.xsp', '.rar']
|
||||||
exclude_dir = []
|
exclude_dir = []
|
||||||
@ -585,7 +586,7 @@ class FileManager:
|
|||||||
|
|
||||||
def addDir(self, dirMeta):
|
def addDir(self, dirMeta):
|
||||||
if(dirMeta['type'] == 'include'):
|
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:
|
else:
|
||||||
self.excludeFile(xbmc.translatePath(dirMeta['path']))
|
self.excludeFile(xbmc.translatePath(dirMeta['path']))
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class GuiSettingsManager:
|
|||||||
updateSettings = {k: v for k, v in list(restoreSettings.items()) if (k in currentSettings and currentSettings[k] != v)}
|
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
|
# 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()):
|
for anId, aValue in list(updateSettings.items()):
|
||||||
utils.log("updating: " + anId + ", value: " + str(aValue))
|
utils.log("updating: " + anId + ", value: " + str(aValue))
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class GuiSettingsManager:
|
|||||||
|
|
||||||
for node in nodeList:
|
for node in nodeList:
|
||||||
nodeValue = ''
|
nodeValue = ''
|
||||||
if(node.firstChild != None):
|
if(node.firstChild is not None):
|
||||||
nodeValue = node.firstChild.nodeValue
|
nodeValue = node.firstChild.nodeValue
|
||||||
|
|
||||||
# check for numbers and booleans
|
# check for numbers and booleans
|
||||||
@ -70,4 +70,3 @@ class GuiSettingsManager:
|
|||||||
self.doc = minidom.parse(fileLoc)
|
self.doc = minidom.parse(fileLoc)
|
||||||
except ExpatError:
|
except ExpatError:
|
||||||
utils.log("Can't read " + fileLoc)
|
utils.log("Can't read " + fileLoc)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import xbmc
|
|||||||
import xbmcgui
|
import xbmcgui
|
||||||
import xbmcaddon
|
import xbmcaddon
|
||||||
|
|
||||||
__addon_id__= 'script.xbmcbackup'
|
__addon_id__ = 'script.xbmcbackup'
|
||||||
__Addon = xbmcaddon.Addon(__addon_id__)
|
__Addon = xbmcaddon.Addon(__addon_id__)
|
||||||
|
|
||||||
|
|
||||||
@ -45,4 +45,3 @@ def getRegionalTimestamp(date_time, dateformat=['dateshort']):
|
|||||||
result = result + ("%s " % date_time.strftime(xbmc.getRegion(aFormat)))
|
result = result + ("%s " % date_time.strftime(xbmc.getRegion(aFormat)))
|
||||||
|
|
||||||
return result.strip()
|
return result.strip()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user