mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
pep8 styling round 2
This commit is contained in:
parent
3e9de429dd
commit
95649c2b3f
@ -4,6 +4,7 @@ import xbmcgui
|
||||
import xbmcvfs
|
||||
from . import utils as utils
|
||||
|
||||
|
||||
class BackupSetManager:
|
||||
jsonFile = xbmc.translatePath(utils.data_dir() + "custom_paths.json")
|
||||
paths = None
|
||||
@ -15,7 +16,7 @@ class BackupSetManager:
|
||||
self._readFile()
|
||||
|
||||
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
|
||||
self._writeFile()
|
||||
@ -33,7 +34,7 @@ class BackupSetManager:
|
||||
# delete this set
|
||||
del self.paths[keys[index]]
|
||||
|
||||
#save the file
|
||||
# save the file
|
||||
self._writeFile()
|
||||
|
||||
def getSets(self):
|
||||
@ -44,10 +45,10 @@ class BackupSetManager:
|
||||
return keys
|
||||
|
||||
def getSet(self, index):
|
||||
keys = self.getSets();
|
||||
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):
|
||||
return (name not in self.getSets())
|
||||
@ -79,7 +80,7 @@ class AdvancedBackupEditor:
|
||||
self.dialog = xbmcgui.Dialog()
|
||||
|
||||
def _cleanPath(self, root, path):
|
||||
return path[len(root)-1:]
|
||||
return path[len(root) - 1:]
|
||||
|
||||
def _validatePath(self, root, path):
|
||||
return path.startswith(root)
|
||||
@ -89,7 +90,7 @@ class AdvancedBackupEditor:
|
||||
|
||||
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
|
||||
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
|
||||
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)
|
||||
@ -123,9 +124,9 @@ class AdvancedBackupEditor:
|
||||
|
||||
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)
|
||||
|
||||
@ -138,10 +139,10 @@ class AdvancedBackupEditor:
|
||||
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)
|
||||
@ -201,7 +202,7 @@ class AdvancedBackupEditor:
|
||||
|
||||
if(menuOption == 0):
|
||||
# get the set
|
||||
aSet = customPaths.getSet(exitCondition -1)
|
||||
aSet = customPaths.getSet(exitCondition - 1)
|
||||
|
||||
# edit the set
|
||||
updatedSet = self.editSet(aSet['name'], aSet['set'])
|
||||
@ -212,7 +213,7 @@ class AdvancedBackupEditor:
|
||||
elif(menuOption == 1):
|
||||
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)
|
||||
customPaths.deleteSet(exitCondition - 1)
|
||||
|
||||
def copySimpleConfig(self):
|
||||
# disclaimer in case the user hit this on accident
|
||||
@ -223,5 +224,3 @@ class AdvancedBackupEditor:
|
||||
dest = xbmc.translatePath(utils.data_dir() + "/custom_paths.json")
|
||||
|
||||
xbmcvfs.copy(source, dest)
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@ try:
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class DropboxAuthorizer:
|
||||
APP_KEY = ""
|
||||
APP_SECRET = ""
|
||||
@ -56,7 +57,7 @@ class DropboxAuthorizer:
|
||||
# get the auth code
|
||||
code = xbmcgui.Dialog().input(utils.getString(30027) + ' ' + utils.getString(30103))
|
||||
|
||||
#if user authorized this will work
|
||||
# if user authorized this will work
|
||||
|
||||
try:
|
||||
user_token = flow.finish(code)
|
||||
@ -74,13 +75,13 @@ class DropboxAuthorizer:
|
||||
user_token = self._getToken()
|
||||
|
||||
if(user_token != ''):
|
||||
#create the client
|
||||
# create the client
|
||||
result = dropbox.Dropbox(user_token)
|
||||
|
||||
try:
|
||||
result.users_get_current_account()
|
||||
except:
|
||||
#this didn't work, delete the token file
|
||||
# this didn't work, delete the token file
|
||||
self._deleteToken()
|
||||
result = None
|
||||
|
||||
|
@ -19,6 +19,7 @@ def folderSort(aKey):
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class XbmcBackup:
|
||||
# constants for initiating a back or restore
|
||||
Backup = 0
|
||||
@ -51,7 +52,7 @@ class XbmcBackup:
|
||||
|
||||
def configureRemote(self):
|
||||
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'))
|
||||
utils.setSetting("remote_path", "")
|
||||
elif(utils.getSetting('remote_selection') == '0'):
|
||||
@ -227,7 +228,7 @@ class XbmcBackup:
|
||||
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)):
|
||||
@ -280,12 +281,12 @@ class XbmcBackup:
|
||||
restoreSets = [n['name'] for n in valFile['directories']]
|
||||
|
||||
# if passed in list, skip selection
|
||||
if(selectedSets == None):
|
||||
if(selectedSets is None):
|
||||
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
|
||||
|
||||
if(selectedSets != None):
|
||||
if(selectedSets is not None):
|
||||
# go through each of the directories in the backup and write them to the correct location
|
||||
for index in selectedSets:
|
||||
|
||||
@ -297,7 +298,7 @@ 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'])
|
||||
@ -357,7 +358,6 @@ class XbmcBackup:
|
||||
utils.log(utils.getString(30047) + ": " + self.xbmc_vfs.root_path)
|
||||
utils.log(utils.getString(30048) + ": " + self.remote_vfs.root_path)
|
||||
|
||||
|
||||
# setup the progress bar
|
||||
self.progressBar = BackupProgressBar(progressOverride)
|
||||
self.progressBar.create(progressBarTitle, utils.getString(30049) + "......")
|
||||
@ -421,7 +421,7 @@ 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):
|
||||
# create date_time object from foldername YYYYMMDDHHmm
|
||||
@ -434,7 +434,7 @@ class XbmcBackup:
|
||||
|
||||
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'))
|
||||
@ -462,11 +462,11 @@ 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}
|
||||
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')
|
||||
@ -531,6 +531,7 @@ class XbmcBackup:
|
||||
jFile.close()
|
||||
return json.loads(jsonString)
|
||||
|
||||
|
||||
class FileManager:
|
||||
not_dir = ['.zip', '.xsp', '.rar']
|
||||
exclude_dir = []
|
||||
@ -585,7 +586,7 @@ class FileManager:
|
||||
|
||||
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']))
|
||||
|
||||
|
@ -34,7 +34,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))
|
||||
|
||||
@ -48,7 +48,7 @@ class GuiSettingsManager:
|
||||
|
||||
for node in nodeList:
|
||||
nodeValue = ''
|
||||
if(node.firstChild != None):
|
||||
if(node.firstChild is not None):
|
||||
nodeValue = node.firstChild.nodeValue
|
||||
|
||||
# check for numbers and booleans
|
||||
@ -70,4 +70,3 @@ class GuiSettingsManager:
|
||||
self.doc = minidom.parse(fileLoc)
|
||||
except ExpatError:
|
||||
utils.log("Can't read " + fileLoc)
|
||||
|
||||
|
@ -2,7 +2,7 @@ import xbmc
|
||||
import xbmcgui
|
||||
import xbmcaddon
|
||||
|
||||
__addon_id__= 'script.xbmcbackup'
|
||||
__addon_id__ = 'script.xbmcbackup'
|
||||
__Addon = xbmcaddon.Addon(__addon_id__)
|
||||
|
||||
|
||||
@ -45,4 +45,3 @@ def getRegionalTimestamp(date_time, dateformat=['dateshort']):
|
||||
result = result + ("%s " % date_time.strftime(xbmc.getRegion(aFormat)))
|
||||
|
||||
return result.strip()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user