incremental
authorAnas Nashif <nashif@planux.com>
Sat, 9 Feb 2013 14:43:16 +0000 (09:43 -0500)
committerAnas Nashif <nashif@planux.com>
Sat, 9 Feb 2013 14:43:16 +0000 (09:43 -0500)
repo/data/3bbecd52af1119a9c16fbd7952b44f01dea518b1c31b297509a499bacf9b07ec-updates.xml [deleted file]
repo/data/updatemd.xml
swup.py

diff --git a/repo/data/3bbecd52af1119a9c16fbd7952b44f01dea518b1c31b297509a499bacf9b07ec-updates.xml b/repo/data/3bbecd52af1119a9c16fbd7952b44f01dea518b1c31b297509a499bacf9b07ec-updates.xml
deleted file mode 100644 (file)
index f40143d..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<updates >
-    <update id="TZUP-2013-001-000">
-        <location href="TZUP-2013-001-000.zip" />
-        <checksum>d1d44afba88cabf44cccd8d9fde2daacba31e09e9b7e46526ba9c1e3b41c0a3b</checksum>
-        <type>incremental</type>
-        <reboot>yes</reboot>
-        <security>no</security>
-        <standalone>no</standalone>
-        <title>Tizen 3.0.1 Update</title>
-        <version>3.0.1</version>
-
-        <description><![CDATA[
-        <p>This Update will solve all your problems</p>
-        <p>For more information, see http://updates.tizen.org</p>
-        ]]>
-        </description>
-    </update>
-</updates>
index 4ba9ed8..74443e1 100644 (file)
@@ -2,8 +2,8 @@
 <updatemd>
   <revision>1360101688</revision>
   <data type="update">
-    <location href="data/3bbecd52af1119a9c16fbd7952b44f01dea518b1c31b297509a499bacf9b07ec-updates.xml"/>
-    <checksum type="sha256">3bbecd52af1119a9c16fbd7952b44f01dea518b1c31b297509a499bacf9b07ec</checksum>
+    <location href="data/26bff4f6eecbac4790f4a4dd1eb7b27bc854135800de59851030f20d858053a1-updates.xml"/>
+    <checksum type="sha256">26bff4f6eecbac4790f4a4dd1eb7b27bc854135800de59851030f20d858053a1</checksum>
     <timestamp>1360101689.12</timestamp>
     <size>65544</size>
   </data>
diff --git a/swup.py b/swup.py
index 1b75e65..094b0da 100755 (executable)
--- a/swup.py
+++ b/swup.py
@@ -31,7 +31,7 @@ def get_current_version():
     return dict(config.items('os-release'))
 
  
-def checksum(fileName, checksum_type="sha256" excludeLine="", includeLine=""):
+def checksum(fileName, checksum_type="sha256", excludeLine="", includeLine=""):
     """Compute sha256 hash of the specified file"""
     m = hashlib.sha256()
     if checksum_type == "md5":
@@ -52,40 +52,49 @@ def checksum(fileName, checksum_type="sha256" excludeLine="", includeLine=""):
     return m.hexdigest()
 
 
-def list_updates():
+def probe_updates():
     print "Checking for new updates..."
     response = urllib2.urlopen("%s/data/updatemd.xml" % update_repo )
     updatemd = response.read()
     if not os.path.exists("%s/data" %update_cache):
         os.mkdir("%s/data" %update_cache)
+
     fp = open("%s/data/updatemd.xml" % update_cache , "w")
     fp.write(updatemd)
     fp.close()
 
-    updatemd_local = open("%s/updatemd.xml" % update_cache )
+    updatemd_local = open("%s/data/updatemd.xml" % update_cache )
     root = etree.XML(updatemd_local.read())
-    d = root.xpath("//data")
-    for i in d:
-        typ = i.attrib['type']
-        if typ == 'update':
-            loc = i.xpath("location")[0]
-            href = loc.attrib['href']
-            get_updates(href)
-            break
-
-
-def get_updates(location):
-
+    data = root.xpath("//data[@type='update']")[0]
+    loc = data.xpath("location")[0]
+    href = loc.attrib['href']
+    chksum = data.xpath("checksum")[0]
+    chksum_type = chksum.attrib['type']
+    
     if os.path.exists("%s/data/updates.xml" % update_cache):
-        print md5("%s/data/updates.xml" % update_cache)
-        print sha256("%s/data/updates.xml" % update_cache)
+        cur_sum = checksum("%s/data/updates.xml" % update_cache, checksum_type=chksum_type) 
+        if cur_sum ==  chksum.text:
+            print "Using file from cache, no new updates on server."
+        else:
+            print "Fetching new updates..."
+            get_new_update_list(href)
+    else:
+        get_new_update_list(href)
+
+    
+
+def get_new_update_list(location):
     up = urllib2.urlopen("%s/%s" % (update_repo, location) )
     update_raw = up.read()
     fp = open("%s/data/updates.xml" % update_cache , "w")
     fp.write(update_raw)
     fp.close()
-    up_root = etree.XML(update_raw)
-    updates = up_root.xpath("//update")
+
+
+def list_updates():
+    fp = open("%s/data/updates.xml" % update_cache , "r")
+    updates_root = etree.XML(fp.read())
+    updates = updates_root.xpath("//update")
     for update in updates:
         attr = update.attrib
         print "  %s:" %attr['id']
@@ -116,4 +125,5 @@ if options.osver:
     print os_release['version_id'].strip('"')
 
 if options.listupdates:
+    probe_updates()
     list_updates()