Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #27 from robweber/master

update testing
  • Loading branch information...
commit f2d61ed19d1639cfd9d76c98a2df7b2692041e3b 2 parents 9fe364e + 36332f2
robweber authored
14  README.txt
@@ -13,6 +13,8 @@ Scheduling:
13 13
 
14 14
 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. 
15 15
 
  16
+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. 
  17
+
16 18
 Running the Program:
17 19
 
18 20
 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
20 22
 
21 23
 Using Dropbox:
22 24
 
23  
-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. 
  25
+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. 
  26
+
  27
+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. 
  28
+
  29
+
  30
+Scripting XBMC Backup: 
  31
+
  32
+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: 
  33
+
  34
+RunScript(script.xbmcbackup,backup)
  35
+
24 36
 
25 37
 What this Addon Will Not Do:
26 38
 
4  addon.xml
... ...
@@ -1,8 +1,8 @@
1 1
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 2
 <addon id="script.xbmcbackup"
3  
-    name="XBMC Backup" version="0.3.1" provider-name="robweber">
  3
+    name="XBMC Backup" version="0.3.4" provider-name="robweber">
4 4
   <requires>
5  
-    <import addon="xbmc.python" version="2.0"/>
  5
+    <import addon="xbmc.python" version="2.1.0"/>
6 6
   </requires>
7 7
   <extension point="xbmc.python.script" library="default.py"> 
8 8
      <provides>executable</provides> 
16  changelog.txt
... ...
@@ -1,7 +1,23 @@
  1
+Version 0.3.4
  2
+
  3
+added ability to take parameters via RunScript() or JSONRPC.Addons.ExecuteAddon()
  4
+
  5
+Version 0.3.3
  6
+
  7
+updated xbmc python version (2.1.0)
  8
+
  9
+Version 0.3.2
  10
+
  11
+added settings for user provided Dropbox key and secret
  12
+
1 13
 Version 0.3.1
2 14
 
3 15
 added try/except for multiple character encodings
4 16
 
  17
+remove token.txt file if Dropbox Authorization is revoked
  18
+
  19
+can shutdown xbmc after scheduled backup
  20
+
5 21
 Version 0.3.0
6 22
 
7 23
 major vfs rewrite 
15  default.py
@@ -2,8 +2,19 @@
2 2
 import resources.lib.utils as utils
3 3
 from resources.lib.backup import XbmcBackup
4 4
 
5  
-#figure out if this is a backup or a restore
6  
-mode = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30023),[utils.getString(30016),utils.getString(30017)])
  5
+#the program mode
  6
+mode = -1
  7
+
  8
+#check if mode was passed in as an argument
  9
+if(len(sys.argv) > 1):
  10
+    if(sys.argv[1].lower() == 'backup'):
  11
+        mode = 0
  12
+    elif(sys.argv[1].lower() == 'restore'):
  13
+        mode = 1
  14
+
  15
+if(mode == -1):
  16
+    #figure out if this is a backup or a restore from the user
  17
+    mode = xbmcgui.Dialog().select(utils.getString(30010) + " - " + utils.getString(30023),[utils.getString(30016),utils.getString(30017)])
7 18
 
8 19
 if(mode != -1):
9 20
     #run the profile backup
5  resources/language/English/strings.xml
@@ -17,6 +17,8 @@
17 17
 	<string id="30025">Remote Path Type</string>
18 18
 	<string id="30026">Backups to keep (0 for all)</string>
19 19
 	<string id="30027">Dropbox</string>
  20
+	<string id="30028">Dropbox Key</string>
  21
+	<string id="30029">Dropbox Secret</string>
20 22
 	
21 23
 	<string id="30030">User Addons</string>
22 24
 	<string id="30031">Addon Data</string>
@@ -37,6 +39,8 @@
37 39
 	<string id="30054">Removing backup</string>
38 40
 	<string id="30056">Check log for Dropbox authorize URL</string>
39 41
 	<string id="30057">Click OK when authorized</string>
  42
+	<string id="30058">Dropbox Developer Code Needed</string>
  43
+	<string id="30059">Visit https://www.dropbox.com/developers</string>
40 44
 	
41 45
 	<string id="30060">Enable Scheduler</string>
42 46
     <string id="30061">Schedule</string>
@@ -54,4 +58,5 @@
54 58
 	<string id="30073">Every Week</string>
55 59
 	<string id="30074">First Day of Month</string>
56 60
 	<string id="30075">Custom Schedule</string>
  61
+	<string id="30076">Shutdown After Backup</string>
57 62
 </strings>
21  resources/lib/vfs.py
@@ -5,8 +5,8 @@
5 5
 import sys
6 6
 from dropbox import client, rest, session
7 7
 
8  
-APP_KEY = 'f5wlmek6aoriqax'
9  
-APP_SECRET = 'b1461sje1kxgzet'
  8
+APP_KEY = utils.getSetting('dropbox_key')
  9
+APP_SECRET = utils.getSetting('dropbox_secret')
10 10
 
11 11
 class Vfs:
12 12
     root_path = None
@@ -64,6 +64,10 @@ class DropboxFileSystem(Vfs):
64 64
     client = None
65 65
     
66 66
     def __init__(self):
  67
+        if(APP_KEY == '' or APP_SECRET == ''):
  68
+            xbmcgui.Dialog().ok(utils.getString(30010),utils.getString(30058),utils.getString(30059))
  69
+            return
  70
+        
67 71
         user_token_key,user_token_secret = self.getToken()
68 72
         
69 73
         sess = session.DropboxSession(APP_KEY,APP_SECRET,"app_folder")
@@ -84,7 +88,13 @@ def __init__(self):
84 88
             sess.set_token(user_token_key,user_token_secret)
85 89
         
86 90
         self.client = client.DropboxClient(sess)
87  
-        utils.log(str(self.client.account_info()))
  91
+
  92
+        try:
  93
+            utils.log(str(self.client.account_info()))
  94
+        except:
  95
+            #this didn't work, delete the token file
  96
+            self.deleteToken()
  97
+            
88 98
 
89 99
     def listdir(self,directory):
90 100
         if(self.client != None and self.exists(directory)):
@@ -150,6 +160,7 @@ def get_file(self,source,dest):
150 160
             out.close()
151 161
         else:
152 162
             return False
  163
+        
153 164
     def setToken(self,key,secret):
154 165
         #write the token files
155 166
         token_file = open(xbmc.translatePath(utils.data_dir() + "tokens.txt"),'w')
@@ -166,6 +177,10 @@ def getToken(self):
166 177
             return [key,secret]
167 178
         else:
168 179
             return ["",""]
  180
+
  181
+    def deleteToken(self):
  182
+        if(xbmcvfs.exists(xbmc.translatePath(utils.data_dir() + "tokens.txt"))):
  183
+            xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "tokens.txt"))
169 184
             
170 185
 
171 186
 
3  resources/settings.xml
@@ -4,6 +4,8 @@
4 4
 		<setting id="remote_selection" type="enum" lvalues="30018|30019|30027" default="0" label="30025"/>
5 5
 		<setting id="remote_path_2" type="text" label="30024" default="" visible="eq(-1,1)" />
6 6
 		<setting id="remote_path" type="folder" label="30020" visible="eq(-2,0)" />
  7
+		<setting id="dropbox_key" type="text" label="30028" visible="eq(-3,2)" default="" />
  8
+		<setting id="dropbox_secret" type="text" label="30029" visible="eq(-4,2)" default="" />
7 9
 		<setting id="backup_rotation" type="number" label="30026" default="0" />
8 10
 		<setting id="run_silent" type="bool" label="30022" default="false" />
9 11
 	</category>
@@ -22,5 +24,6 @@
22 24
 		<setting id="schedule_time" type="labelenum" label="30062" values="00:00|01:00|02:00|03:00|04:00|05:00|06:00|07:00|08:00|09:00|10:00|11:00|12:00|13:00|14:00|15:00|16:00|17:00|18:00|19:00|20:00|21:00|22:00|23:00" default="00:00" visible="!eq(-1,3)"  enable="eq(-2,true)"/>
23 25
 		<setting id="day_of_week" type="enum" label="30063" lvalues="30065|30066|30067|30068|30069|30070|30071" default="0" visible="eq(-2,1)"  enable="eq(-3,true)"/>
24 26
 		<setting id="cron_schedule" type="text" label="30064" default="0 0 * * *" visible="eq(-3,3)"  enable="eq(-4,true)"/>
  27
+		<setting id="cron_shutdown" type="bool" label="30076" default="false" enable="eq(-5,true)" />
25 28
 	</category>
26 29
 </settings>
11  scheduler.py
@@ -44,7 +44,15 @@ def start(self):
44 44
                     #run the job in backup mode, hiding the dialog box
45 45
                     backup = XbmcBackup()
46 46
                     backup.run(XbmcBackup.Backup,True)
47  
-                    self.findNextRun(now,True)
  47
+
  48
+                    #check if we should shut the computer down
  49
+                    if(utils.getSetting("cron_shutdown") == 'true'):
  50
+                        #wait 10 seconds to make sure all backup processes and files are completed
  51
+                        time.sleep(10)
  52
+                        xbmc.executebuiltin('ShutDown()')
  53
+                    else:
  54
+                        #find the next run time like normal
  55
+                        self.findNextRun(now,True)
48 56
                 else:
49 57
                     self.findNextRun(now)
50 58
 
@@ -82,7 +90,6 @@ def parseSchedule(self):
82 90
         hour_of_day = int(hour_of_day[0:2])
83 91
         if(schedule_type == 0):
84 92
             #every day
85  
-           
86 93
             cron_exp = "0 " + str(hour_of_day) + " * * *"
87 94
         elif(schedule_type == 1):
88 95
             #once a week

0 notes on commit f2d61ed

Please sign in to comment.
Something went wrong with that request. Please try again.