The branch, eden-pre has been updated
       via  f98f15fe7922d5f0f7d869742bbe00fcc4795158 (commit)
      from  d3f28d57f42b6b733ec60bacd4dbb34c99de1bd9 (commit)

- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/scripts;a=commit;h=f98f15fe7922d5f0f7d869742bbe00fcc4795158

commit f98f15fe7922d5f0f7d869742bbe00fcc4795158
Author: spiff <[email protected]>
Date:   Fri Feb 3 18:35:11 2012 +0100

    [service.libraryautoupdate] -v0.4.2

diff --git a/service.libraryautoupdate/README.txt 
b/service.libraryautoupdate/README.txt
index acd6f09..d30cadb 100644
--- a/service.libraryautoupdate/README.txt
+++ b/service.libraryautoupdate/README.txt
@@ -1 +1,4 @@
-Using the new xbmc services extension point this script should now run as 
needed once configured. Enjoy. 
\ No newline at end of file
+The XBMC Library Updater will update your music and/or video libraries 
according to times specified by you. 

+

+Things to keep in mind:

+       Restarting XBMC will no longer automatically start a library update. 
The timer now keeps track of the last time it updated via a written file so 
restarts that happen in between updates may not necessarily trigger an update 
unless it is needed. 
\ No newline at end of file
diff --git a/service.libraryautoupdate/addon.xml 
b/service.libraryautoupdate/addon.xml
index c842808..b118818 100644
--- a/service.libraryautoupdate/addon.xml
+++ b/service.libraryautoupdate/addon.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

 <addon id="service.libraryautoupdate"

-    name="XBMC Library Auto Update" version="0.4.0" provider-name="robweber">

+    name="XBMC Library Auto Update" version="0.4.2" provider-name="robweber">

   <requires>

     <import addon="xbmc.python" version="2.0"/>

   </requires>

diff --git a/service.libraryautoupdate/changelog.txt 
b/service.libraryautoupdate/changelog.txt
index 4f73d9a..d9f3aa0 100644
--- a/service.libraryautoupdate/changelog.txt
+++ b/service.libraryautoupdate/changelog.txt
@@ -19,4 +19,9 @@
 

 [B]Version 0.4.0[/B]

 

-- Had a user suggestion to allow for a manual launch of the process as well as 
the service. Since the service point will ALWAYS launch on startup the manual 
option will kick off the library update process. 
\ No newline at end of file
+- Had a user suggestion to allow for a manual launch of the process as well as 
the service. Since the service point will ALWAYS launch on startup the manual 
option will kick off the library update process. 

+

+[B]Version 0.4.1[/B]

+

+-added extra setting for a "startup delay" timer. This will only affect the 
addon when xbmc starts. 

+-the last running time is now set to a variable so that manual updates will 
reset the timer, and system resets will start the service where it left off
\ No newline at end of file
diff --git a/service.libraryautoupdate/resources/language/English/strings.xml 
b/service.libraryautoupdate/resources/language/English/strings.xml
index 7bf5b34..12899c1 100644
--- a/service.libraryautoupdate/resources/language/English/strings.xml
+++ b/service.libraryautoupdate/resources/language/English/strings.xml
@@ -4,4 +4,5 @@
     <string id="30000">Amount of time between updates (hours)</string>
     <string id="30001">Update Video Library</string>
     <string id="30002">Update Music Library</string>
+       <string id="30003">Startup Delay (minutes)</string>
 </strings>
diff --git a/service.libraryautoupdate/resources/settings.xml 
b/service.libraryautoupdate/resources/settings.xml
index 373c73f..8927523 100644
--- a/service.libraryautoupdate/resources/settings.xml
+++ b/service.libraryautoupdate/resources/settings.xml
@@ -3,4 +3,5 @@
     <setting id="timer_amount" type="enum" values="1|2|5|10|15|24" 
label="30000" default="2" />
     <setting id="update_video" type="bool" label="30001" default="true" />
     <setting id="update_music" type="bool" label="30002" default="false" />
+       <setting id="startup_delay" type="enum" values="0|1|2|3|4|5" 
label="30003" default="0" />
 </settings>
diff --git a/service.libraryautoupdate/service.py 
b/service.libraryautoupdate/service.py
index 817d196..fd018db 100644
--- a/service.libraryautoupdate/service.py
+++ b/service.libraryautoupdate/service.py
@@ -3,26 +3,38 @@ import xbmc
 import xbmcaddon
                 
 class AutoUpdater:
-    Addon = xbmcaddon.Addon(id='service.libraryautoupdate')
+    addon_id = "service.libraryautoupdate"
+    Addon = xbmcaddon.Addon(addon_id)
+    datadir = "special://userdata/addon_data/" + addon_id + "/"
     
     def runProgram(self):
-        #set last run to 0 so it will run the first time
-        self.last_run = 0
-        
+        #setup the timer amounts
+        timer_amounts = {}
+        timer_amounts['0'] = 1
+        timer_amounts['1'] = 2
+        timer_amounts['2'] = 5
+        timer_amounts['3'] = 10
+        timer_amounts['4'] = 15
+        timer_amounts['5'] = 24
+           
+        #check if we should delay the first run
+        if(int(self.Addon.getSetting("startup_delay")) != 0):
+            self.readLastRun()
+            
+            #check if we would have run an update anyway
+            if(time.time() >= self.last_run + 
(timer_amounts[self.Addon.getSetting('timer_amount')] * 60 * 60)):
+                #trick system by subtracting the timer amount then adding a 
delay (now - timer + delay = nextrun)
+                self.last_run = time.time() - 
(timer_amounts[self.Addon.getSetting('timer_amount')] * 60 *60) + 
(int(self.Addon.getSetting("startup_delay")) * 60)
+                self.writeLastRun()
+                xbmc.log("Setting delay at " + 
self.Addon.getSetting("startup_delay") + " minute")
+            
         while(not xbmc.abortRequested):
             now = time.time()
             sleep_time = 10
-            
-            timer_amounts = {}
-            timer_amounts['0'] = 1
-            timer_amounts['1'] = 2
-            timer_amounts['2'] = 5
-            timer_amounts['3'] = 10
-            timer_amounts['4'] = 15
-            timer_amounts['5'] = 24
+            self.readLastRun()
 
             #check if we should run an update
-            if(now > self.last_run + 
(timer_amounts[self.Addon.getSetting('timer_amount')] * 60 * 60)):
+            if(now >= self.last_run + 
(timer_amounts[self.Addon.getSetting('timer_amount')] * 60 * 60)):
 
                 #make sure player isn't running
                 if(xbmc.Player().isPlaying() == False):
@@ -31,8 +43,6 @@ class AutoUpdater:
 
                         self.runUpdates()
 
-                        #reset the last run timer    
-                        self.last_run = now
                         xbmc.log("Update Library will run again in " + 
str(timer_amounts[self.Addon.getSetting("timer_amount")]) + " hours")
                         
                 else:
@@ -62,5 +72,26 @@ class AutoUpdater:
                             
             xbmc.log('Update Music')
             xbmc.executebuiltin('UpdateLibrary(music)')
-           
+
+        #reset the last run timer    
+        self.last_run = time.time()
+        self.writeLastRun()
+
+    def readLastRun(self):
+        
+        try:
+            f = open(xbmc.translatePath(self.datadir + "last_run.txt"),"r")
+            self.last_run = float(f.read())
+            f.close()
+        except IOError:
+            #the file doesn't exist, most likely first time running
+            self.last_run = 0
+        
+
+    def writeLastRun(self):
+        f = open(xbmc.translatePath(self.datadir + "last_run.txt"),"w")
+        
+        #write out the value for the last time the program ran
+        f.write(str(self.last_run));
+        f.close();
 

-----------------------------------------------------------------------

Summary of changes:
 service.libraryautoupdate/README.txt               |    5 +-
 service.libraryautoupdate/addon.xml                |    2 +-
 service.libraryautoupdate/changelog.txt            |    7 ++-
 .../resources/language/English/strings.xml         |    1 +
 service.libraryautoupdate/resources/settings.xml   |    1 +
 service.libraryautoupdate/service.py               |   63 +++++++++++++++-----
 6 files changed, 60 insertions(+), 19 deletions(-)


hooks/post-receive
-- 
Scripts

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons

Reply via email to