add installation
authorAnas Nashif <nashif@planux.com>
Mon, 11 Feb 2013 05:19:59 +0000 (00:19 -0500)
committerAnas Nashif <nashif@planux.com>
Mon, 11 Feb 2013 05:19:59 +0000 (00:19 -0500)
repo/TZUP-2013-001-000.zip
repo/data/26bff4f6eecbac4790f4a4dd1eb7b27bc854135800de59851030f20d858053a1-updates.xml [deleted file]
repo/data/updatemd.xml
swup.py

index cadd5ee..b358c2b 100644 (file)
Binary files a/repo/TZUP-2013-001-000.zip and b/repo/TZUP-2013-001-000.zip differ
diff --git a/repo/data/26bff4f6eecbac4790f4a4dd1eb7b27bc854135800de59851030f20d858053a1-updates.xml b/repo/data/26bff4f6eecbac4790f4a4dd1eb7b27bc854135800de59851030f20d858053a1-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 74443e1..647412f 100644 (file)
@@ -2,8 +2,8 @@
 <updatemd>
   <revision>1360101688</revision>
   <data type="update">
-    <location href="data/26bff4f6eecbac4790f4a4dd1eb7b27bc854135800de59851030f20d858053a1-updates.xml"/>
-    <checksum type="sha256">26bff4f6eecbac4790f4a4dd1eb7b27bc854135800de59851030f20d858053a1</checksum>
+    <location href="data/215b71246acd76913ff734a37ec034978ad86bc599d1ae391c4290bb3c731311-updates.xml"/>
+    <checksum type="sha256">215b71246acd76913ff734a37ec034978ad86bc599d1ae391c4290bb3c731311</checksum>
     <timestamp>1360101689.12</timestamp>
     <size>65544</size>
   </data>
diff --git a/swup.py b/swup.py
index 094b0da..53ea8c0 100755 (executable)
--- a/swup.py
+++ b/swup.py
@@ -4,11 +4,14 @@ import ConfigParser
 from optparse import OptionParser
 import urllib2
 from lxml import etree
-from BeautifulSoup import *
+#from BeautifulSoup import *
 import hashlib
 import os
 import tempfile
 import shutil
+import sys
+import zipfile
+import rpm
 
 update_repo="file:///home/nashif/system-updates/repo"
 update_cache="/tmp/updates"
@@ -81,7 +84,57 @@ def probe_updates():
     else:
         get_new_update_list(href)
 
-    
+
+def parse_updates():
+
+    updates = {}
+
+    fp = open("%s/data/updates.xml" % update_cache , "r")
+    updates_root = etree.XML(fp.read())
+    updates_el = updates_root.xpath("//update")
+    for update in updates_el:
+        up = {}
+        attr = update.attrib
+        up['id'] = attr['id']
+        up['checksum'] = update.xpath("checksum")[0].text
+        up['title'] = update.xpath("title")[0].text 
+        loc = update.xpath("location")[0]
+        up['location'] = "%s" % ( loc.attrib['href'])
+        
+        updates[up['id']] = up
+    return updates
+
+
+def download_update(update_data):
+    u = update_data
+    location = u['location']
+    if not os.path.exists("%s/downloads/%s" % (update_cache,location)):
+        update_file = urllib2.urlopen("%s/%s" % (update_repo, location) )
+        location = os.path.basename(location)
+        announced_csum = u['checksum']
+        update_raw = update_file.read()
+        fp = open("%s/downloads/%s" % (update_cache,location) , "w")
+        fp.write(update_raw)
+        fp.close()
+        downloaded_csum = checksum("%s/downloads/%s" % (update_cache,location), "sha256")
+        # Verify Checksum
+        if downloaded_csum != announced_csum:
+            print "Error: Checksum mismatch"
+            os.remove("%s/downloads/%s" % (update_cache,location))
+    else:
+        print "%s already downloaded" % location    
+
+def download_all_updates(update_label=None):
+    updates = parse_updates()
+
+    if update_label is not None:
+        u = updates[update_label]
+        download_update(u)
+    else:
+        for k in updates.keys():
+            u = updates[k]
+            download_update(u)
+        
 
 def get_new_update_list(location):
     up = urllib2.urlopen("%s/%s" % (update_repo, location) )
@@ -91,17 +144,65 @@ def get_new_update_list(location):
     fp.close()
 
 
-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 "       %s" %update.xpath("title")[0].text
+def prepare_update(update_data):
+    u = update_data
+    location = u['location']
+    # unzip
+    if os.path.exists("%s/downloads/%s" % (update_cache,location)) and not os.path.exists("%s/downloads/%s" % (update_cache,u['id'])):    
+        zfile = zipfile.ZipFile("%s/downloads/%s" % (update_cache,location))
+        for name in zfile.namelist():            
+            (dirname, filename) = os.path.split(name)
+            print "Decompressing " + filename + " on " + dirname
+            if not os.path.exists("%s/downloads/%s" % (update_cache, dirname)):
+                os.mkdir("%s/downloads/%s" % (update_cache, dirname))            
+            if filename != "":
+                fd = open("%s/downloads/%s" % (update_cache, name),"w")
+                fd.write(zfile.read(name))
+                fd.close()
+    # apply deltas
+    print "Delta Packages:"
+    for delta in os.listdir("%s/downloads/%s/delta" % (update_cache,u['id'])):
+        
+
+        ts = rpm.TransactionSet()
+        fdno = os.open("%s/downloads/%s/delta/%s" % (update_cache, u['id'], delta), os.O_RDONLY)
+        hdr = ts.hdrFromFdno(fdno)
+        os.close(fdno)
+        target_rpm =  "%s-%s-%s.%s.rpm" % (hdr['name'], hdr['version'], hdr['release'], hdr['arch'])
+        version = "_%s.%s.drpm" % (hdr['release'], hdr['arch'])
+        
+        original_rpm = "%s.%s.rpm" %( delta.replace(version, ""), hdr['arch'] )
+        print "   %s" %original_rpm
+        print " + %s" %delta
+        print " = %s" %target_rpm
+
+        # Verify
+        
+        mi = ts.dbMatch("name", hdr['name'])
+        Found = False
+        for r in mi:
+            installed = "%s-%s-%s.%s.rpm" % (r.name, r.version, r.release, r.arch)
+            original = "%s-%s-%s.%s" % (hdr['name'], hdr['version'], hdr['release'], hdr['arch'])                
+            if installed == original:
+                found = True
+        if Found:
+            print "Original availale, delta can be applied. Applying now..."
+            # apply delta here
+        else:
+            print "Error: original not available, can't apply delta. We have %s instead of %s" % (installed, original_rpm)
 
 
 
+def apply_update(update_data):
+    pass
+
+def list_updates():
+    updates = parse_updates()
+    for k in updates.keys():
+        u = updates[k]
+        print "%s" %u['id']
+        print "    %s" %u['title']
+
 
 parser = OptionParser()
 parser.add_option("-V", "--os-version", action="store_true", dest="osver", default=False,
@@ -112,6 +213,8 @@ parser.add_option("-d", "--download-only", action="store_true", dest="downloadon
                   help="Download only")
 parser.add_option("-i", "--install",  dest="install", metavar="LABEL",
                   help="Install update")
+parser.add_option("-a", "--install-all",  dest="installall", action="store_true", default=False,
+                  help="Install all updates")
 parser.add_option("-r", "--recommended",  dest="recommended", action="store_true", default=False,
                   help="Install recommended updates only")
 parser.add_option("-q", "--quiet",
@@ -127,3 +230,20 @@ if options.osver:
 if options.listupdates:
     probe_updates()
     list_updates()
+
+if options.downloadonly:
+    probe_updates()
+    download_all_updates()
+
+if options.install is not None:
+    probe_updates()
+    updates = parse_updates()
+    if not updates.has_key(options.install):
+        print "%s is not available for installation. Abort." %options.install
+        sys.exit()
+    u = updates[options.install]
+    download_update(u)
+    prepare_update(u)
+
+
+