From 46cd3c673171bebfc7abb64fd147b7ae851ff29c Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Thu, 13 Dec 2012 14:18:14 -0600 Subject: [PATCH 1/9] remove token file if Dropbox authorization revoked --- changelog.txt | 2 ++ resources/lib/vfs.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index ad8af4f..68c22b6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,8 @@ Version 0.3.1 added try/except for multiple character encodings +remove token.txt file if Dropbox Authorization is revoked + Version 0.3.0 major vfs rewrite diff --git a/resources/lib/vfs.py b/resources/lib/vfs.py index 059e53f..ea6b7cf 100644 --- a/resources/lib/vfs.py +++ b/resources/lib/vfs.py @@ -84,7 +84,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 +156,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 +173,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")) From e40e6c685d33343f360ce5539b2d840d51bdefb2 Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Thu, 13 Dec 2012 15:11:25 -0600 Subject: [PATCH 2/9] support for quitting xbmc after scheduled backup --- resources/language/English/strings.xml | 1 + resources/settings.xml | 1 + scheduler.py | 10 +++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index f709e70..d49614e 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -54,4 +54,5 @@ Every Week First Day of Month Custom Schedule + Shutdown After Backup diff --git a/resources/settings.xml b/resources/settings.xml index 4774662..8a81b6f 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -21,5 +21,6 @@ + diff --git a/scheduler.py b/scheduler.py index 42f00c7..8b9e990 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('Quit()') + else: + #find the next run time like normal + self.findNextRun(now,True) else: self.findNextRun(now) From e32383c9edf8e989dcd5ab258a4bc85e7e534f2c Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Fri, 28 Dec 2012 19:03:24 -0600 Subject: [PATCH 3/9] added dropbox key/secret settings --- addon.xml | 2 +- changelog.txt | 4 ++++ resources/language/English/strings.xml | 2 ++ resources/settings.xml | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 2123d24..93c967c 100644 --- a/addon.xml +++ b/addon.xml @@ -1,6 +1,6 @@  + name="XBMC Backup" version="0.3.2" provider-name="robweber"> diff --git a/changelog.txt b/changelog.txt index 68c22b6..8c3a9ea 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +Version 0.3.2 + +added settings for Dropbox key code + Version 0.3.1 added try/except for multiple character encodings diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index d49614e..0525bd6 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 diff --git a/resources/settings.xml b/resources/settings.xml index 8a81b6f..e8ba762 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -4,6 +4,8 @@ + + From 361be97e34a81cf510c1a3a051b3d9e4f7e623ed Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Fri, 28 Dec 2012 19:06:12 -0600 Subject: [PATCH 4/9] vfs.py should pull dropbox info from settings --- resources/lib/vfs.py | 4 ++-- resources/settings.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/lib/vfs.py b/resources/lib/vfs.py index ea6b7cf..a86247b 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 diff --git a/resources/settings.xml b/resources/settings.xml index e8ba762..0816027 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -4,8 +4,8 @@ - - + + From e582be4c7b6c637b3dd3c801bc46663e437023f4 Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Sun, 30 Dec 2012 15:18:59 -0600 Subject: [PATCH 5/9] added message to create Dropbox key/secret --- resources/language/English/strings.xml | 2 ++ resources/lib/vfs.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 0525bd6..4848aed 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -39,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 diff --git a/resources/lib/vfs.py b/resources/lib/vfs.py index a86247b..2d7a1d0 100644 --- a/resources/lib/vfs.py +++ b/resources/lib/vfs.py @@ -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") From 6eb5b7f986466eb3eb1367f72880850215db50c0 Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Sun, 30 Dec 2012 15:19:17 -0600 Subject: [PATCH 6/9] fixed shutdown function in scheduler.py --- scheduler.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scheduler.py b/scheduler.py index 8b9e990..a4dcd26 100644 --- a/scheduler.py +++ b/scheduler.py @@ -49,7 +49,7 @@ class BackupScheduler: if(utils.getSetting("cron_shutdown") == 'true'): #wait 10 seconds to make sure all backup processes and files are completed time.sleep(10) - xbmc.executebuiltin('Quit()') + xbmc.executebuiltin('ShutDown()') else: #find the next run time like normal self.findNextRun(now,True) @@ -90,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 From 8e7aacca4fd3463a9c5df0bbacc79502394292fd Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Sun, 30 Dec 2012 15:19:27 -0600 Subject: [PATCH 7/9] updated readme and changelog --- README.txt | 6 +++++- changelog.txt | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.txt b/README.txt index e934a58..3a3856a 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,9 @@ 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. What this Addon Will Not Do: diff --git a/changelog.txt b/changelog.txt index 8c3a9ea..9f83c38 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,6 @@ Version 0.3.2 -added settings for Dropbox key code +added settings for user provided Dropbox key and secret Version 0.3.1 @@ -8,6 +8,8 @@ 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 From 3cd1ae32470ceb66a394f06f91619d58aceb9331 Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Mon, 31 Dec 2012 08:31:48 -0600 Subject: [PATCH 8/9] updated xbmc python version --- addon.xml | 4 ++-- changelog.txt | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/addon.xml b/addon.xml index 93c967c..1d4bbc1 100644 --- a/addon.xml +++ b/addon.xml @@ -1,8 +1,8 @@  + name="XBMC Backup" version="0.3.3" provider-name="robweber"> - + executable diff --git a/changelog.txt b/changelog.txt index 9f83c38..a486694 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +Version 0.3.3 + +updated xbmc python version (2.1.0) + Version 0.3.2 added settings for user provided Dropbox key and secret From 36332f20b8bf8b97361974bf068cfc57af4fc285 Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Fri, 4 Jan 2013 10:29:00 -0600 Subject: [PATCH 9/9] will now check for arguments "backup" or "restore" to bypass dialog prompt --- README.txt | 8 ++++++++ addon.xml | 2 +- changelog.txt | 4 ++++ default.py | 15 +++++++++++++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index 3a3856a..370fac2 100644 --- a/README.txt +++ b/README.txt @@ -26,6 +26,14 @@ Using Dropbox as a storage target adds a few steps the first time you wish to ru 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: This is not meant as an XBMC file sync solution. If you have multiple frontends you want to keep in sync this addon may work in a "poor man's" sort of way but it is not intended for that. diff --git a/addon.xml b/addon.xml index 1d4bbc1..3a0f316 100644 --- a/addon.xml +++ b/addon.xml @@ -1,6 +1,6 @@  + name="XBMC Backup" version="0.3.4" provider-name="robweber"> diff --git a/changelog.txt b/changelog.txt index a486694..d2f9ded 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +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) 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