#!/usr/bin/python

import pwd, os, cPickle, xmlrpclib, sys, zlib

file = pwd.getpwuid(os.getuid())[5]
file = file + "/.rhn-applet.cache"

try:
    fd = open(file, "r")
    pkgs = cPickle.load(fd)
except Exception, e:
    print("can't open for reading %s  %s, trying to remove it..." % (file, str(e)))
    sys.exit()

appletData= {}
appletData['last_modified'] = pkgs[0]
appletData['contents']=pkgs[1]

f = open("applet-errata.%s" % (pkgs[0]), "w")
xml= xmlrpclib.dumps((appletData,),methodresponse=1)
f.write(xml)
f.close
f = open("applet-errata.%s.zlib" % (pkgs[0]), "w")
xmlzlib= zlib.compress(xml,9)
f.write(xmlzlib)
f.close
