pep8 style fixes - round 1

This commit is contained in:
Rob Weber
2019-11-25 15:56:59 -06:00
parent 35e05acaf2
commit db18c6a7b4
8 changed files with 54 additions and 29 deletions

View File

@ -1,11 +1,12 @@
from . import utils as utils
class ZipExtractor:
def extract(self, zipFile, outLoc, progressBar):
utils.log("extracting zip archive")
result = True # result is true unless we fail
result = True # result is true unless we fail
# update the progress bar
progressBar.updateProgress(0, utils.getString(30100))

View File

@ -1,6 +1,7 @@
import xbmcgui
from . import utils as utils
class BackupProgressBar:
NONE = 2
DIALOG = 0
@ -31,7 +32,7 @@ class BackupProgressBar:
# update the progress bar
if(self.mode != self.NONE):
if(message != None):
if(message is not None):
# need different calls for dialog and background bars
if(self.mode == self.DIALOG):
self.progressBar.update(percent, message)

View File

@ -1,7 +1,8 @@
from future.moves.urllib.request import urlopen
# this is duplicated in snipppets of code from all over the web, credit to no one
# in particular - to all those that have gone before me!
from future.moves.urllib.request import urlopen
def shorten(aUrl):
tinyurl = 'http://tinyurl.com/api-create.php?url='
req = urlopen(tinyurl + aUrl)

View File

@ -5,30 +5,39 @@ import xbmcaddon
__addon_id__= 'script.xbmcbackup'
__Addon = xbmcaddon.Addon(__addon_id__)
def data_dir():
return __Addon.getAddonInfo('profile')
def addon_dir():
return __Addon.getAddonInfo('path')
def openSettings():
__Addon.openSettings()
def log(message, loglevel=xbmc.LOGDEBUG):
xbmc.log(__addon_id__ + "-" + __Addon.getAddonInfo('version') + ": " + message, level=loglevel)
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"))
def getSetting(name):
return __Addon.getSetting(name)
def setSetting(name, value):
__Addon.setSetting(name, value)
def getString(string_id):
return __Addon.getLocalizedString(string_id)
def getRegionalTimestamp(date_time, dateformat=['dateshort']):
result = ''

View File

@ -10,6 +10,7 @@ from . import utils as utils
from .dropbox.files import WriteMode, CommitInfo, UploadSessionCursor
from . authorizers import DropboxAuthorizer
class Vfs:
root_path = None
@ -54,6 +55,7 @@ class Vfs:
def cleanup(self):
return True
class XBMCFileSystem(Vfs):
def listdir(self, directory):
@ -77,6 +79,7 @@ class XBMCFileSystem(Vfs):
def exists(self, aFile):
return xbmcvfs.exists(aFile)
class ZipFileSystem(Vfs):
zip = None
@ -115,8 +118,9 @@ class ZipFileSystem(Vfs):
def listFiles(self):
return self.zip.infolist()
class DropboxFileSystem(Vfs):
MAX_CHUNK = 50 * 1000 * 1000 # dropbox uses 150, reduced to 50 for small mem systems
MAX_CHUNK = 50 * 1000 * 1000 # dropbox uses 150, reduced to 50 for small mem systems
client = None
APP_KEY = ''
APP_SECRET = ''
@ -136,7 +140,7 @@ class DropboxFileSystem(Vfs):
def listdir(self, directory):
directory = self._fix_slashes(directory)
if(self.client != None and self.exists(directory)):
if(self.client is not None and self.exists(directory)):
files = []
dirs = []
metadata = self.client.files_list_folder(directory)
@ -153,7 +157,7 @@ class DropboxFileSystem(Vfs):
def mkdir(self, directory):
directory = self._fix_slashes(directory)
if(self.client != None):
if(self.client is not None):
# sort of odd but always return true, folder create is implicit with file upload
return True
else:
@ -161,7 +165,7 @@ class DropboxFileSystem(Vfs):
def rmdir(self, directory):
directory = self._fix_slashes(directory)
if(self.client != None and self.exists(directory)):
if(self.client is not None and self.exists(directory)):
# dropbox is stupid and will refuse to do this sometimes, need to delete recursively
dirs, files = self.listdir(directory)
@ -178,7 +182,7 @@ class DropboxFileSystem(Vfs):
def rmfile(self, aFile):
aFile = self._fix_slashes(aFile)
if(self.client != None and self.exists(aFile)):
if(self.client is not None and self.exists(aFile)):
self.client.files_delete(aFile)
return True
else:
@ -187,13 +191,13 @@ class DropboxFileSystem(Vfs):
def exists(self, aFile):
aFile = self._fix_slashes(aFile)
if(self.client != None):
if(self.client is not None):
# can't list root metadata
if(aFile == ''):
return True
try:
meta_data = self.client.files_get_metadata(aFile)
self.client.files_get_metadata(aFile)
# if we make it here the file does exist
return True
except:
@ -204,7 +208,7 @@ class DropboxFileSystem(Vfs):
def put(self, source, dest, retry=True):
dest = self._fix_slashes(dest)
if(self.client != None):
if(self.client is not None):
# open the file and get its size
f = open(source, 'rb')
f_size = os.path.getsize(source)
@ -212,7 +216,7 @@ class DropboxFileSystem(Vfs):
try:
if(f_size < self.MAX_CHUNK):
# use the regular upload
response = self.client.files_upload(f.read(), dest, mode=WriteMode('overwrite'))
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))
@ -228,7 +232,7 @@ class DropboxFileSystem(Vfs):
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!
# if no errors we're good!
return True
except Exception as anError:
utils.log(str(anError))
@ -243,9 +247,9 @@ class DropboxFileSystem(Vfs):
return False
def get_file(self, source, dest):
if(self.client != None):
if(self.client is not None):
# write the file locally
f = self.client.files_download_to_file(dest, source)
self.client.files_download_to_file(dest, source)
return True
else:
return False