diff --git a/README.txt b/README.txt index 4b345e3..9d57199 100644 --- a/README.txt +++ b/README.txt @@ -6,7 +6,7 @@ I've had to recover my database, thumbnails, and source configuration enough tim Remote Destination/File Selection: -In the addon settings you can define a remote path for the destination of your xbmc files. Each backup will create a folder named in a YYYYMMDD format so you can create multiple backups. You can keep a set number of backups by setting the integer value of the Backups to Keep setting greater than 0. +In the addon settings you can define a remote path for the destination of your xbmc files. Each backup will create a folder named in a YYYYMMDDHHmm format so you can create multiple backups. You can keep a set number of backups by setting the integer value of the Backups to Keep setting greater than 0. On the Backup Selection page you can select which items from your user profile folder will be sent to the backup location. By default all are turned on except the Addon Data directory. @@ -37,11 +37,38 @@ Once you have your app key and secret add them to the settings. XBMC Backup now Scripting XBMC Backup: -If you wish to script this addon using an outside scheduler or script it can be given parameters via the Xbmc.RunScript() or JsonRPC.Addons.ExecuteAddon() methods. Parameters given are either "backup" or "restore" to launch the correct program mode. An example would be: +If you wish to script this addon using an outside scheduler or script it can be given parameters via the Xbmc.RunScript() or JsonRPC.Addons.ExecuteAddon() methods. Parameters given are either "backup" or "restore" to launch the correct program mode. If mode is "restore", an additional "archive" parameter can be given to set the restore point to be used instead of prompting via the GUI. An example would be: -RunScript(script.xbmcbackup,backup) +Python code: +------------------------------------------- +RunScript(script.xbmcbackup,mode=backup) +------------------------------------------- +or +JSON Request: +------------------------------------------- +{ "jsonrpc": "2.0", "method": "Addons.ExecuteAddon","params":{"addonid":"script.xbmcbackup","params":{"mode":"restore","archive":"000000000000"}}, "id": 1 } +------------------------------------------- + +There is also a windows parameter that can be used to check if XBMC Backup is running within a skin or from another program. It is attached to the home window, an example of using it would be the following: + +Python code: +------------------------------------------- +#kick off the xbmc backup +xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Addons.ExecuteAddon","params":{"addonid":"script.xbmcbackup","params":{"mode":"backup"}}, "id": 1 }') + +#sleep for a few seconds to give it time to kick off +xbmc.sleep(10000) + +window = xbmcgui.Window(10000) + +while (window.getProperty('script.xbmcbackup.running') == 'true'): + #do something here, probably just sleep for a few seconds + xbmc.sleep(5000) + +#backup is now done, continue with script +------------------------------------------- FAQ: I can't see any restore points when choosing "Restore", what is the problem? diff --git a/addon.xml b/addon.xml index 1bac4e9..9a80d74 100644 --- a/addon.xml +++ b/addon.xml @@ -1,8 +1,8 @@  + name="XBMC Backup" version="0.5.2" provider-name="robweber"> - + executable diff --git a/changelog.txt b/changelog.txt index 9b2e7dd..5cf53f4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,16 @@ -Version 0.4.7 +Version 0.5.2 -fixed critical error in backup rotation +added additional script and window parameters, thanks Samu-rai + +critical error in backup rotation + +Version 0.5.1 + +updated for new Gotham xbmc python updates + +Version 0.5.0 + +New Version for Gotham Version 0.4.6 diff --git a/default.py b/default.py index b2bd2ad..a682c8a 100644 --- a/default.py +++ b/default.py @@ -1,21 +1,37 @@ +import urlparse import xbmcgui import resources.lib.utils as utils from resources.lib.backup import XbmcBackup +def get_params(): + param = {} + + if(len(sys.argv) > 1): + for i in sys.argv: + args = i + if(args.startswith('?')): + args = args[1:] + param.update(dict(urlparse.parse_qsl(args))) + + return param + #the program mode mode = -1 +params = get_params() -#check if mode was passed in as an argument -if(len(sys.argv) > 1): - if(sys.argv[1].lower() == 'backup'): + +if("mode" in params): + if(params['mode'] == 'backup'): mode = 0 - elif(sys.argv[1].lower() == 'restore'): + elif(params['mode'] == 'restore'): mode = 1 +#if mode wasn't passed in as arg, get from user if(mode == -1): #figure out if this is a backup or a restore from the user mode = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30023),[utils.getString(30016),utils.getString(30017)]) +#check if program should be run if(mode != -1): #run the profile backup backup = XbmcBackup() @@ -23,14 +39,29 @@ if(mode != -1): if(backup.remoteConfigured()): if(mode == backup.Restore): - #allow user to select the backup to restore from + #get list of valid restore points restorePoints = backup.listBackups() pointNames = [] - + folderNames = [] + for aDir in restorePoints: pointNames.append(aDir[1]) - - selectedRestore = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30021),pointNames) + folderNames.append(aDir[0]) + + selectedRestore = -1 + + if("archive" in params): + #check that the user give archive exists + if(params['archive'] in folderNames): + #set the index + selectedRestore = folderNames.index(params['archive']) + utils.log(str(selectedRestore) + " : " + params['archive']) + else: + utils.showNotification(utils.getString(30045)) + utils.log(params['archive'] + ' is not a valid restore point') + else: + #allow user to select the backup to restore from + selectedRestore = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30021),pointNames) if(selectedRestore != -1): backup.selectRestore(restorePoints[selectedRestore][0]) diff --git a/resources/language/Bulgarian/strings.xml b/resources/language/Bulgarian/strings.xml index 9c860bd..fd23b73 100644 --- a/resources/language/Bulgarian/strings.xml +++ b/resources/language/Bulgarian/strings.xml @@ -14,7 +14,7 @@ Въвеждане на път Прегледайте Име на папката за резервните копия - Изпълнявай "тихо" + Известяване за напредъка Режим Въведете отдалечения път Окажете пътя до папката с резервни копия @@ -73,4 +73,7 @@ Само днес Профили Планировчика ще стартира отново на + Лента за напредъка + Лента за напредъка на заден план + Без (тих режим) diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 4f04fa7..979df3c 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -14,7 +14,7 @@ Type Path Browse Remote Path Backup Folder Name - Run Silent + Progress Display Mode Type Remote Path Remote Path Type @@ -73,4 +73,7 @@ Just Today Profiles Scheduler will run again on + Progress Bar + Background Progress Bar + None (Silent) diff --git a/resources/lib/backup.py b/resources/lib/backup.py index ea2d90d..061fcef 100644 --- a/resources/lib/backup.py +++ b/resources/lib/backup.py @@ -89,7 +89,11 @@ class XbmcBackup: def skipAdvanced(self): self.skip_advanced = True - def run(self,mode=-1,runSilent=False): + def run(self,mode=-1,progressOverride=False): + #set windows setting to true + window = xbmcgui.Window(10000) + window.setProperty(utils.__addon_id__ + ".running","true") + #append backup folder name progressBarTitle = utils.getString(30010) + " - " if(mode == self.Backup and self.remote_vfs.root_path != ''): @@ -107,8 +111,13 @@ class XbmcBackup: utils.log(utils.getString(30048) + ": " + self.remote_vfs.root_path) #check if we should use the progress bar - if(utils.getSetting('run_silent') == 'false' and not runSilent): - self.progressBar = xbmcgui.DialogProgress() + if(int(utils.getSetting('progress_mode')) != 2): + #check if background or normal + if(int(utils.getSetting('progress_mode')) == 0 and not progressOverride): + self.progressBar = xbmcgui.DialogProgress() + else: + self.progressBar = xbmcgui.DialogProgressBG() + self.progressBar.create(progressBarTitle,utils.getString(30049) + "......") if(mode == self.Backup): @@ -315,9 +324,12 @@ class XbmcBackup: #call update addons to refresh everything xbmc.executebuiltin('UpdateLocalAddons') - if(utils.getSetting('run_silent') == 'false' and not runSilent): + if(self.progressBar != None): self.progressBar.close() + #reset the window setting + window.setProperty(utils.__addon_id__ + ".running","") + def backupFiles(self,fileList,source,dest): utils.log("Writing files to: " + dest.root_path) utils.log("Source: " + source.root_path) @@ -361,7 +373,7 @@ class XbmcBackup: def _checkCancel(self): result = False - if(self.progressBar != None): + if(self.progressBar != None and type(self.progressBar) is xbmcgui.DialogProgress): result = self.progressBar.iscanceled() return result diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 8d1d1c8..07f2551 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -1,4 +1,5 @@ import xbmc +import xbmcgui import xbmcaddon __addon_id__= 'script.xbmcbackup' @@ -17,7 +18,7 @@ def log(message,loglevel=xbmc.LOGNOTICE): xbmc.log(encode(__addon_id__ + "-" + __Addon.getAddonInfo('version') + ": " + message),level=loglevel) def showNotification(message): - xbmc.executebuiltin("Notification(" + encode(getString(30010)) + "," + encode(message) + ",4000," + xbmc.translatePath(__Addon.getAddonInfo('path') + "/icon.png") + ")") + xbmcgui.Dialog().notification(encode(getString(30010)),encode(message),time=4000,icon=xbmc.translatePath(__Addon.getAddonInfo('path') + "/icon.png")) def getSetting(name): return __Addon.getSetting(name) diff --git a/resources/settings.xml b/resources/settings.xml index e14e466..21d98d1 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -7,7 +7,7 @@ - + diff --git a/scheduler.py b/scheduler.py index d2df48e..4b978b5 100644 --- a/scheduler.py +++ b/scheduler.py @@ -25,7 +25,6 @@ class BackupScheduler: #scheduler was turned on, find next run time utils.log("scheduler enabled, finding next run time") self.findNextRun(time.time()) - utils.log("scheduler will run again on " + datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M')) def start(self): @@ -46,13 +45,18 @@ class BackupScheduler: now = time.time() if(self.next_run <= now): - if(utils.getSetting('run_silent') == 'false'): + progress_mode = int(utils.getSetting('progress_mode')) + if(progress_mode != 2): utils.showNotification(utils.getString(30053)) - #run the job in backup mode, hiding the dialog box + backup = XbmcBackup() if(backup.remoteConfigured()): - backup.run(XbmcBackup.Backup,True) + + if(int(utils.getSetting('progress_mode')) in [0,1]): + backup.run(XbmcBackup.Backup,True) + else: + backup.run(XbmcBackup.Backup,False) #check if this is a "one-off" if(int(utils.getSetting("schedule_interval")) == 0):