From: Anas Nashif
Date: Sat, 9 Feb 2013 14:43:16 +0000 (-0500)
Subject: incremental
X-Git-Tag: accepted/trunk/20130225.214136~12
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09a1f0a7f210ac52e5aa7db26301148ffb6fe4d5;p=platform%2Fupstream%2Fswup.git
incremental
---
diff --git a/repo/data/3bbecd52af1119a9c16fbd7952b44f01dea518b1c31b297509a499bacf9b07ec-updates.xml b/repo/data/3bbecd52af1119a9c16fbd7952b44f01dea518b1c31b297509a499bacf9b07ec-updates.xml
deleted file mode 100644
index f40143d..0000000
--- a/repo/data/3bbecd52af1119a9c16fbd7952b44f01dea518b1c31b297509a499bacf9b07ec-updates.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
- d1d44afba88cabf44cccd8d9fde2daacba31e09e9b7e46526ba9c1e3b41c0a3b
- incremental
- yes
- no
- no
- Tizen 3.0.1 Update
- 3.0.1
-
- This Update will solve all your problems
- For more information, see http://updates.tizen.org
- ]]>
-
-
-
diff --git a/repo/data/updatemd.xml b/repo/data/updatemd.xml
index 4ba9ed8..74443e1 100644
--- a/repo/data/updatemd.xml
+++ b/repo/data/updatemd.xml
@@ -2,8 +2,8 @@
1360101688
-
- 3bbecd52af1119a9c16fbd7952b44f01dea518b1c31b297509a499bacf9b07ec
+
+ 26bff4f6eecbac4790f4a4dd1eb7b27bc854135800de59851030f20d858053a1
1360101689.12
65544
diff --git a/swup.py b/swup.py
index 1b75e65..094b0da 100755
--- 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()