pep8 styling round 2

This commit is contained in:
Rob Weber 2019-11-26 10:43:38 -06:00
parent 3e9de429dd
commit 95649c2b3f
7 changed files with 49 additions and 50 deletions

View File

@ -12,7 +12,7 @@ def get_params():
args = i
if('=' in args):
if(args.startswith('?')):
args = args[1:] # legacy in case of url params
args = args[1:] # legacy in case of url params
splitString = args.split('=')
param[splitString[0]] = splitString[1]
except:

View File

@ -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)
@ -174,7 +175,7 @@ class AdvancedBackupEditor:
# show this every time
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')]
@ -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)

View File

@ -10,10 +10,11 @@ try:
except ImportError:
pass
class DropboxAuthorizer:
APP_KEY = ""
APP_SECRET = ""
def __init__(self):
self.APP_KEY = utils.getSetting('dropbox_key')
self.APP_SECRET = utils.getSetting('dropbox_secret')
@ -32,7 +33,7 @@ class DropboxAuthorizer:
def isAuthorized(self):
user_token = self._getToken()
return user_token != ''
return user_token != ''
def authorize(self):
result = True
@ -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

View File

@ -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'):
@ -70,7 +71,7 @@ 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
@ -78,7 +79,7 @@ class XbmcBackup:
for aDir in dirs:
if(self.remote_vfs.exists(self.remote_base_path + aDir + "/xbmcbackup.val")):
# format the name according to regional settings
folderName = self._dateFormat(aDir)
@ -89,7 +90,7 @@ class XbmcBackup:
folderName = aFile.split('.')[0]
if(file_ext == 'zip' and len(folderName) == 12 and folderName.isdigit()):
# format the name according to regional settings
folderName = self._dateFormat(folderName)
@ -183,7 +184,7 @@ class XbmcBackup:
self.xbmc_vfs.rename(xbmc.translatePath("special://temp/xbmc_backup_temp.zip"), xbmc.translatePath("special://temp/" + zip_name))
fileManager.addFile(xbmc.translatePath("special://temp/" + zip_name))
# set root to data dir home
# set root to data dir home
self.xbmc_vfs.set_root(xbmc.translatePath("special://temp/"))
self.remote_vfs = self.saved_remote_vfs
@ -214,7 +215,7 @@ class XbmcBackup:
self.progressBar.updateProgress(2, utils.getString(30088))
utils.log("copying zip file: " + self.restore_point)
# set root to data dir home
# set root to data dir home
self.xbmc_vfs.set_root(xbmc.translatePath("special://temp/"))
if(not self.xbmc_vfs.exists(xbmc.translatePath("special://temp/" + self.restore_point))):
@ -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
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')
@ -513,7 +513,7 @@ class XbmcBackup:
if(not shouldContinue):
result = None
except ValueError:
# may fail on older archives
result = None
@ -531,6 +531,7 @@ class XbmcBackup:
jFile.close()
return json.loads(jsonString)
class FileManager:
not_dir = ['.zip', '.xsp', '.rar']
exclude_dir = []
@ -565,7 +566,7 @@ class FileManager:
# check if directory is excluded
if(not any(dirPath.startswith(exDir) for exDir in self.exclude_dir)):
self.addFile("-" + dirPath)
# catch for "non directory" type files
@ -576,7 +577,7 @@ class FileManager:
shouldWalk = False
if(shouldWalk):
self.walkTree(dirPath)
self.walkTree(dirPath)
# copy all the files
for aFile in files:
@ -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']))

View File

@ -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
@ -60,7 +60,7 @@ class GuiSettingsManager:
nodeValue = False
result[node.getAttribute('id')] = nodeValue
return result
def _readFile(self, fileLoc):
@ -70,4 +70,3 @@ class GuiSettingsManager:
self.doc = minidom.parse(fileLoc)
except ExpatError:
utils.log("Can't read " + fileLoc)

View File

@ -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()

View File

@ -137,7 +137,7 @@ class BackupScheduler:
fh.close()
# only show when not in silent mode
if(progress_mode != 2):
if(progress_mode != 2):
utils.showNotification(utils.getString(30081) + " " + utils.getRegionalTimestamp(datetime.fromtimestamp(self.next_run), ['dateshort', 'time']))
def settingsChanged(self):