mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-15 04:45:49 +01:00
pep8 style fixes - round 1
This commit is contained in:
parent
35e05acaf2
commit
db18c6a7b4
@ -4,6 +4,7 @@ import xbmcgui
|
|||||||
import resources.lib.utils as utils
|
import resources.lib.utils as utils
|
||||||
from resources.lib.backup import XbmcBackup
|
from resources.lib.backup import XbmcBackup
|
||||||
|
|
||||||
|
|
||||||
def get_params():
|
def get_params():
|
||||||
param = {}
|
param = {}
|
||||||
try:
|
try:
|
||||||
@ -19,6 +20,7 @@ def get_params():
|
|||||||
|
|
||||||
return param
|
return param
|
||||||
|
|
||||||
|
|
||||||
# the program mode
|
# the program mode
|
||||||
mode = -1
|
mode = -1
|
||||||
params = get_params()
|
params = get_params()
|
||||||
@ -30,6 +32,7 @@ if("mode" in params):
|
|||||||
elif(params['mode'] == 'restore'):
|
elif(params['mode'] == 'restore'):
|
||||||
mode = 1
|
mode = 1
|
||||||
|
|
||||||
|
|
||||||
# if mode wasn't passed in as arg, get from user
|
# if mode wasn't passed in as arg, get from user
|
||||||
if(mode == -1):
|
if(mode == -1):
|
||||||
# by default, Backup,Restore,Open Settings
|
# by default, Backup,Restore,Open Settings
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# launcher for various helpful functions found in the settings.xml area
|
||||||
import sys
|
import sys
|
||||||
import xbmc
|
import xbmc
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
@ -6,7 +7,6 @@ import resources.lib.utils as utils
|
|||||||
from resources.lib.authorizers import DropboxAuthorizer
|
from resources.lib.authorizers import DropboxAuthorizer
|
||||||
from resources.lib.advanced_editor import AdvancedBackupEditor
|
from resources.lib.advanced_editor import AdvancedBackupEditor
|
||||||
|
|
||||||
# launcher for various helpful functions found in the settings.xml area
|
|
||||||
|
|
||||||
def authorize_cloud(cloudProvider):
|
def authorize_cloud(cloudProvider):
|
||||||
# drobpox
|
# drobpox
|
||||||
@ -18,6 +18,7 @@ def authorize_cloud(cloudProvider):
|
|||||||
else:
|
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():
|
def remove_auth():
|
||||||
# triggered from settings.xml - asks if user wants to delete OAuth token information
|
# 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)
|
||||||
@ -27,6 +28,7 @@ def remove_auth():
|
|||||||
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) # dropbox
|
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) # dropbox
|
||||||
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "google_drive.dat")) # google drive
|
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "google_drive.dat")) # google drive
|
||||||
|
|
||||||
|
|
||||||
def get_params():
|
def get_params():
|
||||||
param = {}
|
param = {}
|
||||||
try:
|
try:
|
||||||
@ -42,6 +44,7 @@ def get_params():
|
|||||||
|
|
||||||
return param
|
return param
|
||||||
|
|
||||||
|
|
||||||
params = get_params()
|
params = get_params()
|
||||||
|
|
||||||
if(params['action'] == 'authorize_cloud'):
|
if(params['action'] == 'authorize_cloud'):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from . import utils as utils
|
from . import utils as utils
|
||||||
|
|
||||||
|
|
||||||
class ZipExtractor:
|
class ZipExtractor:
|
||||||
|
|
||||||
def extract(self, zipFile, outLoc, progressBar):
|
def extract(self, zipFile, outLoc, progressBar):
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import xbmcgui
|
import xbmcgui
|
||||||
from . import utils as utils
|
from . import utils as utils
|
||||||
|
|
||||||
|
|
||||||
class BackupProgressBar:
|
class BackupProgressBar:
|
||||||
NONE = 2
|
NONE = 2
|
||||||
DIALOG = 0
|
DIALOG = 0
|
||||||
@ -31,7 +32,7 @@ class BackupProgressBar:
|
|||||||
|
|
||||||
# update the progress bar
|
# update the progress bar
|
||||||
if(self.mode != self.NONE):
|
if(self.mode != self.NONE):
|
||||||
if(message != None):
|
if(message is not None):
|
||||||
# need different calls for dialog and background bars
|
# need different calls for dialog and background bars
|
||||||
if(self.mode == self.DIALOG):
|
if(self.mode == self.DIALOG):
|
||||||
self.progressBar.update(percent, message)
|
self.progressBar.update(percent, message)
|
||||||
|
@ -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
|
# 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!
|
# in particular - to all those that have gone before me!
|
||||||
|
from future.moves.urllib.request import urlopen
|
||||||
|
|
||||||
|
|
||||||
def shorten(aUrl):
|
def shorten(aUrl):
|
||||||
tinyurl = 'http://tinyurl.com/api-create.php?url='
|
tinyurl = 'http://tinyurl.com/api-create.php?url='
|
||||||
req = urlopen(tinyurl + aUrl)
|
req = urlopen(tinyurl + aUrl)
|
||||||
|
@ -5,30 +5,39 @@ import xbmcaddon
|
|||||||
__addon_id__= 'script.xbmcbackup'
|
__addon_id__= 'script.xbmcbackup'
|
||||||
__Addon = xbmcaddon.Addon(__addon_id__)
|
__Addon = xbmcaddon.Addon(__addon_id__)
|
||||||
|
|
||||||
|
|
||||||
def data_dir():
|
def data_dir():
|
||||||
return __Addon.getAddonInfo('profile')
|
return __Addon.getAddonInfo('profile')
|
||||||
|
|
||||||
|
|
||||||
def addon_dir():
|
def addon_dir():
|
||||||
return __Addon.getAddonInfo('path')
|
return __Addon.getAddonInfo('path')
|
||||||
|
|
||||||
|
|
||||||
def openSettings():
|
def openSettings():
|
||||||
__Addon.openSettings()
|
__Addon.openSettings()
|
||||||
|
|
||||||
|
|
||||||
def log(message, loglevel=xbmc.LOGDEBUG):
|
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):
|
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):
|
def getSetting(name):
|
||||||
return __Addon.getSetting(name)
|
return __Addon.getSetting(name)
|
||||||
|
|
||||||
|
|
||||||
def setSetting(name, value):
|
def setSetting(name, value):
|
||||||
__Addon.setSetting(name, value)
|
__Addon.setSetting(name, value)
|
||||||
|
|
||||||
|
|
||||||
def getString(string_id):
|
def getString(string_id):
|
||||||
return __Addon.getLocalizedString(string_id)
|
return __Addon.getLocalizedString(string_id)
|
||||||
|
|
||||||
|
|
||||||
def getRegionalTimestamp(date_time, dateformat=['dateshort']):
|
def getRegionalTimestamp(date_time, dateformat=['dateshort']):
|
||||||
result = ''
|
result = ''
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ from . import utils as utils
|
|||||||
from .dropbox.files import WriteMode, CommitInfo, UploadSessionCursor
|
from .dropbox.files import WriteMode, CommitInfo, UploadSessionCursor
|
||||||
from . authorizers import DropboxAuthorizer
|
from . authorizers import DropboxAuthorizer
|
||||||
|
|
||||||
|
|
||||||
class Vfs:
|
class Vfs:
|
||||||
root_path = None
|
root_path = None
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ class Vfs:
|
|||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class XBMCFileSystem(Vfs):
|
class XBMCFileSystem(Vfs):
|
||||||
|
|
||||||
def listdir(self, directory):
|
def listdir(self, directory):
|
||||||
@ -77,6 +79,7 @@ class XBMCFileSystem(Vfs):
|
|||||||
def exists(self, aFile):
|
def exists(self, aFile):
|
||||||
return xbmcvfs.exists(aFile)
|
return xbmcvfs.exists(aFile)
|
||||||
|
|
||||||
|
|
||||||
class ZipFileSystem(Vfs):
|
class ZipFileSystem(Vfs):
|
||||||
zip = None
|
zip = None
|
||||||
|
|
||||||
@ -115,6 +118,7 @@ class ZipFileSystem(Vfs):
|
|||||||
def listFiles(self):
|
def listFiles(self):
|
||||||
return self.zip.infolist()
|
return self.zip.infolist()
|
||||||
|
|
||||||
|
|
||||||
class DropboxFileSystem(Vfs):
|
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
|
client = None
|
||||||
@ -136,7 +140,7 @@ class DropboxFileSystem(Vfs):
|
|||||||
def listdir(self, directory):
|
def listdir(self, directory):
|
||||||
directory = self._fix_slashes(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 = []
|
files = []
|
||||||
dirs = []
|
dirs = []
|
||||||
metadata = self.client.files_list_folder(directory)
|
metadata = self.client.files_list_folder(directory)
|
||||||
@ -153,7 +157,7 @@ class DropboxFileSystem(Vfs):
|
|||||||
|
|
||||||
def mkdir(self, directory):
|
def mkdir(self, directory):
|
||||||
directory = self._fix_slashes(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
|
# sort of odd but always return true, folder create is implicit with file upload
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@ -161,7 +165,7 @@ class DropboxFileSystem(Vfs):
|
|||||||
|
|
||||||
def rmdir(self, directory):
|
def rmdir(self, directory):
|
||||||
directory = self._fix_slashes(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
|
# dropbox is stupid and will refuse to do this sometimes, need to delete recursively
|
||||||
dirs, files = self.listdir(directory)
|
dirs, files = self.listdir(directory)
|
||||||
|
|
||||||
@ -178,7 +182,7 @@ class DropboxFileSystem(Vfs):
|
|||||||
def rmfile(self, aFile):
|
def rmfile(self, aFile):
|
||||||
aFile = self._fix_slashes(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)
|
self.client.files_delete(aFile)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@ -187,13 +191,13 @@ class DropboxFileSystem(Vfs):
|
|||||||
def exists(self, aFile):
|
def exists(self, aFile):
|
||||||
aFile = self._fix_slashes(aFile)
|
aFile = self._fix_slashes(aFile)
|
||||||
|
|
||||||
if(self.client != None):
|
if(self.client is not None):
|
||||||
# can't list root metadata
|
# can't list root metadata
|
||||||
if(aFile == ''):
|
if(aFile == ''):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
meta_data = self.client.files_get_metadata(aFile)
|
self.client.files_get_metadata(aFile)
|
||||||
# if we make it here the file does exist
|
# if we make it here the file does exist
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
@ -204,7 +208,7 @@ class DropboxFileSystem(Vfs):
|
|||||||
def put(self, source, dest, retry=True):
|
def put(self, source, dest, retry=True):
|
||||||
dest = self._fix_slashes(dest)
|
dest = self._fix_slashes(dest)
|
||||||
|
|
||||||
if(self.client != None):
|
if(self.client is not None):
|
||||||
# open the file and get its size
|
# open the file and get its size
|
||||||
f = open(source, 'rb')
|
f = open(source, 'rb')
|
||||||
f_size = os.path.getsize(source)
|
f_size = os.path.getsize(source)
|
||||||
@ -212,7 +216,7 @@ class DropboxFileSystem(Vfs):
|
|||||||
try:
|
try:
|
||||||
if(f_size < self.MAX_CHUNK):
|
if(f_size < self.MAX_CHUNK):
|
||||||
# use the regular upload
|
# 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:
|
else:
|
||||||
# start the upload session
|
# start the upload session
|
||||||
upload_session = self.client.files_upload_session_start(f.read(self.MAX_CHUNK))
|
upload_session = self.client.files_upload_session_start(f.read(self.MAX_CHUNK))
|
||||||
@ -243,9 +247,9 @@ class DropboxFileSystem(Vfs):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def get_file(self, source, dest):
|
def get_file(self, source, dest):
|
||||||
if(self.client != None):
|
if(self.client is not None):
|
||||||
# write the file locally
|
# write the file locally
|
||||||
f = self.client.files_download_to_file(dest, source)
|
self.client.files_download_to_file(dest, source)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -9,6 +9,7 @@ from resources.lib.backup import XbmcBackup
|
|||||||
|
|
||||||
UPGRADE_INT = 2 # to keep track of any upgrade notifications
|
UPGRADE_INT = 2 # to keep track of any upgrade notifications
|
||||||
|
|
||||||
|
|
||||||
class BackupScheduler:
|
class BackupScheduler:
|
||||||
monitor = None
|
monitor = None
|
||||||
enabled = "false"
|
enabled = "false"
|
||||||
@ -184,6 +185,7 @@ class BackupScheduler:
|
|||||||
|
|
||||||
return shouldContinue
|
return shouldContinue
|
||||||
|
|
||||||
|
|
||||||
class UpdateMonitor(xbmc.Monitor):
|
class UpdateMonitor(xbmc.Monitor):
|
||||||
update_method = None
|
update_method = None
|
||||||
|
|
||||||
@ -194,4 +196,5 @@ class UpdateMonitor(xbmc.Monitor):
|
|||||||
def onSettingsChanged(self):
|
def onSettingsChanged(self):
|
||||||
self.update_method()
|
self.update_method()
|
||||||
|
|
||||||
|
|
||||||
BackupScheduler().start()
|
BackupScheduler().start()
|
||||||
|
Loading…
Reference in New Issue
Block a user