diff --git a/README.txt b/README.txt index e934a58..370fac2 100644 --- a/README.txt +++ b/README.txt @@ -13,6 +13,8 @@ Scheduling: You can also schedule backups to be completed on a set interval via the scheduling area. When it is time for the backup to run it will be executed in the background. +When using the "Shutdown" function this will call XBMC's Shutdown method as defined in System Settings -> Power Saving -> Shutdown Function. This can be simply exiting xbmc, hibernating, or shutting down your htpc. + Running the Program: Running the program will allow you to select Backup or Restore as a running mode. Selecting Backup will push files to your remote store using the addon settings you defined. Selecting Restore will give you a list of restore points currently in your remote destination. Selecting one will pull the files matching your selection criteria from the restore point to your local XBMC folders. @@ -20,7 +22,17 @@ Running the program will allow you to select Backup or Restore as a running mode Using Dropbox: -Using Dropbox as a storage target adds a few steps the first time you wish to run a backup. XBMC Backup needs to have permission to access your Dropbox account. When you see the prompt regarding the Dropbox URL Authorization DO NOT click OK. Check your XBMC log file for a line from "script.xbmcbackup" containing the authorization URL. Cut/paste this into a browser and click Allow. Once this is done you can click "OK" in XBMC and proceed as normal. XBMC Backup will cache the authorization code so you only have to do this once, or if you revoke the Dropbox permissions. +Using Dropbox as a storage target adds a few steps the first time you wish to run a backup. First you will need to sign-up for you own developer app key and secret by visiting https://www.dropbox.com/developers. Name your app whatevery you want, and make it an "App Folder" type application. Your app can run in developer mode and you should never need to apply for production status. This is to get around Dropbox's rule not allow distribution of production key/secret pairs. + +Once you have your app key and secret add them to the settings. XBMC Backup now needs to have permission to access your Dropbox account. When you see the prompt regarding the Dropbox URL Authorization DO NOT click OK. Check your XBMC log file for a line from "script.xbmcbackup" containing the authorization URL. Cut/paste this into a browser and click Allow. Once this is done you can click "OK" in XBMC and proceed as normal. XBMC Backup will cache the authorization code so you only have to do this once, or if you revoke the Dropbox permissions. + + +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: + +RunScript(script.xbmcbackup,backup) + What this Addon Will Not Do: diff --git a/addon.xml b/addon.xml index 2123d24..3a0f316 100644 --- a/addon.xml +++ b/addon.xml @@ -1,8 +1,8 @@  + name="XBMC Backup" version="0.3.4" provider-name="robweber"> - + executable diff --git a/changelog.txt b/changelog.txt index ad8af4f..d2f9ded 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,7 +1,23 @@ +Version 0.3.4 + +added ability to take parameters via RunScript() or JSONRPC.Addons.ExecuteAddon() + +Version 0.3.3 + +updated xbmc python version (2.1.0) + +Version 0.3.2 + +added settings for user provided Dropbox key and secret + Version 0.3.1 added try/except for multiple character encodings +remove token.txt file if Dropbox Authorization is revoked + +can shutdown xbmc after scheduled backup + Version 0.3.0 major vfs rewrite diff --git a/default.py b/default.py index 0c1e9cf..e4ef6dd 100644 --- a/default.py +++ b/default.py @@ -2,8 +2,19 @@ import xbmcgui import resources.lib.utils as utils from resources.lib.backup import XbmcBackup -#figure out if this is a backup or a restore -mode = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30023),[utils.getString(30016),utils.getString(30017)]) +#the program mode +mode = -1 + +#check if mode was passed in as an argument +if(len(sys.argv) > 1): + if(sys.argv[1].lower() == 'backup'): + mode = 0 + elif(sys.argv[1].lower() == 'restore'): + mode = 1 + +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)]) if(mode != -1): #run the profile backup diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index f709e70..4848aed 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -17,6 +17,8 @@ Remote Path Type Backups to keep (0 for all) Dropbox + Dropbox Key + Dropbox Secret User Addons Addon Data @@ -37,6 +39,8 @@ Removing backup Check log for Dropbox authorize URL Click OK when authorized + Dropbox Developer Code Needed + Visit https://www.dropbox.com/developers Enable Scheduler Schedule @@ -54,4 +58,5 @@ Every Week First Day of Month Custom Schedule + Shutdown After Backup diff --git a/resources/lib/vfs.py b/resources/lib/vfs.py index 059e53f..2d7a1d0 100644 --- a/resources/lib/vfs.py +++ b/resources/lib/vfs.py @@ -5,8 +5,8 @@ import xbmcgui import sys from dropbox import client, rest, session -APP_KEY = 'f5wlmek6aoriqax' -APP_SECRET = 'b1461sje1kxgzet' +APP_KEY = utils.getSetting('dropbox_key') +APP_SECRET = utils.getSetting('dropbox_secret') class Vfs: root_path = None @@ -64,6 +64,10 @@ class DropboxFileSystem(Vfs): client = None def __init__(self): + if(APP_KEY == '' or APP_SECRET == ''): + xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30058),utils.getString(30059)) + return + user_token_key,user_token_secret = self.getToken() sess = session.DropboxSession(APP_KEY,APP_SECRET,"app_folder") @@ -84,7 +88,13 @@ class DropboxFileSystem(Vfs): sess.set_token(user_token_key,user_token_secret) self.client = client.DropboxClient(sess) - utils.log(str(self.client.account_info())) + + try: + utils.log(str(self.client.account_info())) + except: + #this didn't work, delete the token file + self.deleteToken() + def listdir(self,directory): if(self.client != None and self.exists(directory)): @@ -150,6 +160,7 @@ class DropboxFileSystem(Vfs): out.close() else: return False + def setToken(self,key,secret): #write the token files token_file = open(xbmc.translatePath(utils.data_dir() + "tokens.txt"),'w') @@ -166,6 +177,10 @@ class DropboxFileSystem(Vfs): return [key,secret] else: return ["",""] + + def deleteToken(self): + if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "tokens.txt"))): + xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt")) diff --git a/resources/settings.xml b/resources/settings.xml index 8f167e2..c2162fd 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -4,6 +4,8 @@ + + @@ -22,5 +24,6 @@ + diff --git a/scheduler.py b/scheduler.py index 42f00c7..a4dcd26 100644 --- a/scheduler.py +++ b/scheduler.py @@ -44,7 +44,15 @@ class BackupScheduler: #run the job in backup mode, hiding the dialog box backup = XbmcBackup() backup.run(XbmcBackup.Backup,True) - self.findNextRun(now,True) + + #check if we should shut the computer down + if(utils.getSetting("cron_shutdown") == 'true'): + #wait 10 seconds to make sure all backup processes and files are completed + time.sleep(10) + xbmc.executebuiltin('ShutDown()') + else: + #find the next run time like normal + self.findNextRun(now,True) else: self.findNextRun(now) @@ -82,7 +90,6 @@ class BackupScheduler: hour_of_day = int(hour_of_day[0:2]) if(schedule_type == 0): #every day - cron_exp = "0 " + str(hour_of_day) + " * * *" elif(schedule_type == 1): #once a week