+++ /dev/null
-<?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>
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":
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']
print os_release['version_id'].strip('"')
if options.listupdates:
+ probe_updates()
list_updates()