home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / UpdateManager / MetaRelease.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  4.7 KB  |  154 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import pygtk
  5. pygtk.require('2.0')
  6. import gobject
  7. import thread
  8. import urllib2
  9. import os
  10. import string
  11. import apt_pkg
  12. import time
  13. import rfc822
  14. from subprocess import Popen, PIPE
  15.  
  16. class Dist(object):
  17.     
  18.     def __init__(self, name, version, date, supported):
  19.         self.name = name
  20.         self.version = version
  21.         self.date = date
  22.         self.supported = supported
  23.         self.releaseNotesURI = None
  24.         self.upgradeTool = None
  25.         self.upgradeToolSig = None
  26.  
  27.  
  28.  
  29. class MetaRelease(gobject.GObject):
  30.     METARELEASE_URI = 'http://changelogs.ubuntu.com/meta-release'
  31.     METARELEASE_URI_UNSTABLE = 'http://changelogs.ubuntu.com/meta-release-development'
  32.     METARELEASE_FILE = '/var/lib/update-manager/meta-release'
  33.     __gsignals__ = {
  34.         'new_dist_available': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
  35.         'dist_no_longer_supported': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()) }
  36.     
  37.     def __init__(self, useDevelopmentRelase = False):
  38.         gobject.GObject.__init__(self)
  39.         if useDevelopmentRelase:
  40.             self.METARELEASE_URI = self.METARELEASE_URI_UNSTABLE
  41.         
  42.         if not os.access(self.METARELEASE_FILE, os.F_OK | os.W_OK | os.R_OK):
  43.             path = os.path.expanduser('~/.update-manager/')
  44.             if not os.path.exists(path):
  45.                 os.mkdir(path)
  46.             
  47.             self.METARELEASE_FILE = os.path.join(path, 'meta-release')
  48.         
  49.         self.metarelease_information = None
  50.         self.downloading = True
  51.         t = thread.start_new_thread(self.download, ())
  52.         gobject.timeout_add(1000, self.check)
  53.  
  54.     
  55.     def get_dist(self):
  56.         ''' return the codename of the current runing distro '''
  57.         p = Popen([
  58.             '/bin/lsb_release',
  59.             '-c',
  60.             '-s'], stdout = PIPE)
  61.         res = p.wait()
  62.         if res != 0:
  63.             sys.stderr.write('lsb_release returned exitcode: %i\n' % res)
  64.         
  65.         dist = string.strip(p.stdout.readline())
  66.         return dist
  67.  
  68.     
  69.     def check(self):
  70.         if self.metarelease_information != None:
  71.             self.parse()
  72.             return False
  73.         
  74.         return True
  75.  
  76.     
  77.     def parse(self):
  78.         current_dist_name = self.get_dist()
  79.         current_dist = None
  80.         dists = []
  81.         index_tag = apt_pkg.ParseTagFile(self.metarelease_information)
  82.         step_result = index_tag.Step()
  83.         while step_result:
  84.             if index_tag.Section.has_key('Dist'):
  85.                 name = index_tag.Section['Dist']
  86.                 rawdate = index_tag.Section['Date']
  87.                 date = time.mktime(rfc822.parsedate(rawdate))
  88.                 supported = bool(index_tag.Section['Supported'])
  89.                 version = index_tag.Section['Version']
  90.                 dist = Dist(name, version, date, supported)
  91.                 if index_tag.Section.has_key('ReleaseNotes'):
  92.                     dist.releaseNotesURI = index_tag.Section['ReleaseNotes']
  93.                 
  94.                 if index_tag.Section.has_key('UpgradeTool'):
  95.                     dist.upgradeTool = index_tag.Section['UpgradeTool']
  96.                 
  97.                 if index_tag.Section.has_key('UpgradeToolSignature'):
  98.                     dist.upgradeToolSig = index_tag.Section['UpgradeToolSignature']
  99.                 
  100.                 dists.append(dist)
  101.                 if name == current_dist_name:
  102.                     current_dist = dist
  103.                 
  104.             
  105.             step_result = index_tag.Step()
  106.         if current_dist == None:
  107.             print 'current dist not found in meta-release file'
  108.             return False
  109.         
  110.         upgradable_to = ''
  111.         for dist in dists:
  112.             if dist.date > current_dist.date and dist.supported == True:
  113.                 upgradable_to = dist
  114.                 break
  115.                 continue
  116.         
  117.         if upgradable_to != '' and not (current_dist.supported):
  118.             self.emit('dist_no_longer_supported', upgradabl_to)
  119.         elif upgradable_to != '':
  120.             self.emit('new_dist_available', upgradable_to)
  121.         
  122.         return True
  123.  
  124.     
  125.     def download(self):
  126.         lastmodified = 0
  127.         req = urllib2.Request(self.METARELEASE_URI)
  128.         if os.access(self.METARELEASE_FILE, os.W_OK):
  129.             lastmodified = os.stat(self.METARELEASE_FILE).st_mtime
  130.         
  131.         if lastmodified > 0:
  132.             req.add_header('If-Modified-Since', lastmodified)
  133.         
  134.         
  135.         try:
  136.             uri = urllib2.urlopen(req)
  137.             f = open(self.METARELEASE_FILE, 'w+')
  138.             for line in uri.readlines():
  139.                 f.write(line)
  140.             
  141.             f.flush()
  142.             f.seek(0, 0)
  143.             self.metarelease_information = f
  144.             uri.close()
  145.         except urllib2.URLError:
  146.             if os.path.exists(self.METARELEASE_FILE):
  147.                 f = open(self.METARELEASE_FILE, 'r')
  148.             
  149.         except:
  150.             os.path.exists(self.METARELEASE_FILE)
  151.  
  152.  
  153.  
  154.