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 / DistUpgradeFetcher.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  7.1 KB  |  210 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import pygtk
  5. pygtk.require('2.0')
  6. import gtk
  7. import os
  8. import apt_pkg
  9. import tarfile
  10. import urllib2
  11. import tempfile
  12. import shutil
  13. import GnuPGInterface
  14. from gettext import gettext as _
  15. import GtkProgress
  16. from ReleaseNotesViewer import ReleaseNotesViewer
  17. from Common.utils import *
  18.  
  19. class DistUpgradeFetcher(object):
  20.     
  21.     def __init__(self, parent, new_dist):
  22.         self.parent = parent
  23.         self.window_main = parent.window_main
  24.         self.new_dist = new_dist
  25.  
  26.     
  27.     def showReleaseNotes(self):
  28.         if self.new_dist.releaseNotesURI != None:
  29.             uri = self.new_dist.releaseNotesURI
  30.             self.window_main.set_sensitive(False)
  31.             self.window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
  32.             while gtk.events_pending():
  33.                 gtk.main_iteration()
  34.             res = gtk.RESPONSE_CANCEL
  35.             
  36.             try:
  37.                 release_notes = urllib2.urlopen(uri)
  38.                 notes = release_notes.read()
  39.                 textview_release_notes = ReleaseNotesViewer(notes)
  40.                 textview_release_notes.show()
  41.                 self.parent.scrolled_notes.add(textview_release_notes)
  42.                 self.parent.dialog_release_notes.set_transient_for(self.window_main)
  43.                 res = self.parent.dialog_release_notes.run()
  44.                 self.parent.dialog_release_notes.hide()
  45.             except urllib2.HTTPError:
  46.                 primary = '<span weight="bold" size="larger">%s</span>' % _('Could not find the release notes')
  47.                 secondary = _('The server may be overloaded. ')
  48.                 dialog = gtk.MessageDialog(self.window_main, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, '')
  49.                 dialog.set_title('')
  50.                 dialog.set_markup(primary)
  51.                 dialog.format_secondary_text(secondary)
  52.                 dialog.run()
  53.                 dialog.destroy()
  54.             except IOError:
  55.                 primary = '<span weight="bold" size="larger">%s</span>' % _('Could not download the release notes')
  56.                 secondary = _('Please check your internet connection.')
  57.                 dialog = gtk.MessageDialog(self.window_main, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, '')
  58.                 dialog.set_title('')
  59.                 dialog.set_markup(primary)
  60.                 dialog.format_secondary_text(secondary)
  61.                 dialog.run()
  62.                 dialog.destroy()
  63.  
  64.             self.window_main.set_sensitive(True)
  65.             self.window_main.window.set_cursor(None)
  66.             if res == gtk.RESPONSE_CANCEL:
  67.                 return False
  68.             
  69.         
  70.         return True
  71.  
  72.     
  73.     def authenticate(self):
  74.         if self.new_dist.upgradeToolSig:
  75.             f = self.tmpdir + '/' + os.path.basename(self.new_dist.upgradeTool)
  76.             sig = self.tmpdir + '/' + os.path.basename(self.new_dist.upgradeToolSig)
  77.             print "authenticate '%s' against '%s' " % (f, sig)
  78.             if not self.gpgauthenticate(f, sig):
  79.                 return False
  80.             
  81.         
  82.         return True
  83.  
  84.     
  85.     def gpgauthenticate(self, file, signature, keyring = '/etc/apt/trusted.gpg'):
  86.         ''' authenticated a file against a given signature, if no keyring
  87.             is given use the apt default keyring
  88.         '''
  89.         gpg = GnuPGInterface.GnuPG()
  90.         gpg.options.extra_args = [
  91.             '--no-options',
  92.             '--no-default-keyring',
  93.             '--keyring',
  94.             keyring]
  95.         proc = gpg.run([
  96.             '--verify',
  97.             signature,
  98.             file], create_fhs = [
  99.             'status',
  100.             'logger',
  101.             'stderr'])
  102.         gpgres = proc.handles['status'].read()
  103.         
  104.         try:
  105.             proc.wait()
  106.         except IOError:
  107.             e = None
  108.             print 'exception from gpg: %s' % e
  109.             return False
  110.  
  111.         if 'VALIDSIG' in gpgres:
  112.             return True
  113.         
  114.         print 'invalid result from gpg:'
  115.         print gpgres
  116.         return False
  117.  
  118.     
  119.     def extractDistUpgrader(self):
  120.         print "extracting '%s'" % (self.tmpdir + '/' + os.path.basename(self.uri))
  121.         tar = tarfile.open(self.tmpdir + '/' + os.path.basename(self.uri), 'r')
  122.         for tarinfo in tar:
  123.             tar.extract(tarinfo)
  124.         
  125.         tar.close()
  126.         return True
  127.  
  128.     
  129.     def verifyDistUprader(self):
  130.         self.script = script = '%s/%s' % (self.tmpdir, self.new_dist.name)
  131.         if not os.path.exists(script):
  132.             primary = '<span weight="bold" size="larger">%s</span>' % _('Could not run the upgrade tool')
  133.             secondary = _('This is most likely a bug in the upgrade tool. Please report it as a bug')
  134.             dialog = gtk.MessageDialog(self.window_main, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, '')
  135.             dialog.set_title('')
  136.             dialog.set_markup(primary)
  137.             dialog.format_secondary_text(secondary)
  138.             dialog.run()
  139.             dialog.destroy()
  140.             return False
  141.         
  142.         return True
  143.  
  144.     
  145.     def fetchDistUpgrader(self):
  146.         self.tmpdir = tmpdir = tempfile.mkdtemp()
  147.         os.chdir(tmpdir)
  148.         progress = GtkProgress.GtkFetchProgress(self.parent, _('Downloading the upgrade tool'), _('The upgrade tool will guide you through the upgrade process.'))
  149.         fetcher = apt_pkg.GetAcquire(progress)
  150.         if self.new_dist.upgradeToolSig != None:
  151.             uri = self.new_dist.upgradeToolSig
  152.             af = apt_pkg.GetPkgAcqFile(fetcher, uri, descr = _('Upgrade tool signature'))
  153.         
  154.         if self.new_dist.upgradeTool != None:
  155.             self.uri = self.new_dist.upgradeTool
  156.             af = apt_pkg.GetPkgAcqFile(fetcher, self.uri, descr = _('Upgrade tool'))
  157.             if fetcher.Run() != fetcher.ResultContinue:
  158.                 return False
  159.             
  160.             return True
  161.         
  162.         return False
  163.  
  164.     
  165.     def runDistUpgrader(self):
  166.         if os.getuid() != 0:
  167.             os.execv('/usr/bin/gksu', [
  168.                 'gksu',
  169.                 self.script])
  170.         else:
  171.             os.execv(self.script, [
  172.                 self.script])
  173.  
  174.     
  175.     def cleanup(self):
  176.         os.chdir('..')
  177.         shutil.rmtree(self.tmpdir)
  178.  
  179.     
  180.     def run(self):
  181.         if not self.showReleaseNotes():
  182.             return None
  183.         
  184.         if not self.fetchDistUpgrader():
  185.             error(self.window_main, _('Failed to fetch'), _('Fetching the upgrade failed. There may be a network problem. '))
  186.             return None
  187.         
  188.         if not self.extractDistUpgrader():
  189.             error(self.window_main, _('Failed to extract'), _('Extracting the upgrade failed. There may be a problem with the network or with the server. '))
  190.             return None
  191.         
  192.         if not self.verifyDistUprader():
  193.             error(self.window_main, _('Verfication failed'), _('Verfing the upgrade failed.  There may be a problem with the network or with the server. '))
  194.             self.cleanup()
  195.             return None
  196.         
  197.         if not self.authenticate():
  198.             error(self.window_main, _('Authentication failed'), _('Authenticating the upgrade failed. There may be a problem with the network or with the server. '))
  199.             self.cleanup()
  200.             return None
  201.         
  202.         self.runDistUpgrader()
  203.  
  204.  
  205. if __name__ == '__main__':
  206.     error(None, 'summary', 'message')
  207.     d = DistUpgradeFetcher(None, None)
  208.     print d.authenticate('/tmp/Release', '/tmp/Release.gpg')
  209.  
  210.