home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / DistUpgrade / DistUpgradeViewText.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  10.5 KB  |  238 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import logging
  6. import subprocess
  7. import apt
  8. import os
  9. from DistUpgradeView import DistUpgradeView, InstallProgress, FetchProgress
  10. import apt.progress as apt
  11. import gettext
  12. from DistUpgradeGettext import gettext as _
  13.  
  14. def wrap(t, width = 70, subsequent_indent = ''):
  15.     out = ''
  16.     for s in t.split():
  17.         if (len(out) - out.rfind('\n')) + len(s) > width:
  18.             out += '\n' + subsequent_indent
  19.         
  20.         out += s + ' '
  21.     
  22.     return out
  23.  
  24.  
  25. def twrap(s, **kwargs):
  26.     msg = ''
  27.     paras = s.split('\n')
  28.     for par in paras:
  29.         s = wrap(par, **kwargs)
  30.         msg += s + '\n'
  31.     
  32.     return msg
  33.  
  34.  
  35. class TextFetchProgress(FetchProgress, apt.progress.TextFetchProgress):
  36.     
  37.     def __init__(self):
  38.         apt.progress.TextFetchProgress.__init__(self)
  39.         FetchProgress.__init__(self)
  40.  
  41.     
  42.     def pulse(self):
  43.         apt.progress.TextFetchProgress.pulse(self)
  44.         FetchProgress.pulse(self)
  45.         return True
  46.  
  47.  
  48.  
  49. class TextCdromProgressAdapter(apt.progress.CdromProgress):
  50.     ''' Report the cdrom add progress  '''
  51.     
  52.     def update(self, text, step):
  53.         ''' update is called regularly so that the gui can be redrawn '''
  54.         if text:
  55.             print '%s (%f)' % (text, (step / float(self.totalSteps)) * 100)
  56.         
  57.  
  58.     
  59.     def askCdromName(self):
  60.         return (False, '')
  61.  
  62.     
  63.     def changeCdrom(self):
  64.         return False
  65.  
  66.  
  67.  
  68. class DistUpgradeViewText(DistUpgradeView):
  69.     ''' text frontend of the distUpgrade tool '''
  70.     
  71.     def __init__(self, datadir = None, logdir = None):
  72.         if not os.environ.has_key('DEBIAN_FRONTEND'):
  73.             os.environ['DEBIAN_FRONTEND'] = 'dialog'
  74.         
  75.         if not datadir:
  76.             localedir = os.path.join(os.getcwd(), 'mo')
  77.         else:
  78.             localedir = '/usr/share/locale/update-manager'
  79.         
  80.         try:
  81.             gettext.bindtextdomain('update-manager', localedir)
  82.             gettext.textdomain('update-manager')
  83.         except Exception:
  84.             e = None
  85.             logging.warning('Error setting locales (%s)' % e)
  86.  
  87.         self.last_step = 0
  88.         self._opCacheProgress = apt.progress.OpTextProgress()
  89.         self._fetchProgress = TextFetchProgress()
  90.         self._cdromProgress = TextCdromProgressAdapter()
  91.         self._installProgress = InstallProgress()
  92.         sys.excepthook = self._handleException
  93.  
  94.     
  95.     def _handleException(self, type, value, tb):
  96.         import traceback
  97.         print 
  98.         lines = traceback.format_exception(type, value, tb)
  99.         logging.error('not handled exception:\n%s' % '\n'.join(lines))
  100.         self.error(_('A fatal error occurred'), _('Please report this as a bug and include the files /var/log/dist-upgrade/main.log and /var/log/dist-upgrade/apt.log in your report. The upgrade is now aborted.\nYour original sources.list was saved in /etc/apt/sources.list.distUpgrade.'), '\n'.join(lines))
  101.         sys.exit(1)
  102.  
  103.     
  104.     def getFetchProgress(self):
  105.         return self._fetchProgress
  106.  
  107.     
  108.     def getInstallProgress(self, cache):
  109.         self._installProgress._cache = cache
  110.         return self._installProgress
  111.  
  112.     
  113.     def getOpCacheProgress(self):
  114.         return self._opCacheProgress
  115.  
  116.     
  117.     def getCdromProgress(self):
  118.         return self._cdromProgress
  119.  
  120.     
  121.     def updateStatus(self, msg):
  122.         print 
  123.         print msg
  124.         sys.stdout.flush()
  125.  
  126.     
  127.     def abort(self):
  128.         print 
  129.         print _('Aborting')
  130.  
  131.     
  132.     def setStep(self, step):
  133.         self.last_step = step
  134.  
  135.     
  136.     def showDemotions(self, summary, msg, demotions):
  137.         self.information(summary, msg, _('Demoted:\n') + twrap(', '.join(demotions)))
  138.  
  139.     
  140.     def information(self, summary, msg, extended_msg = None):
  141.         print 
  142.         print twrap(summary)
  143.         print twrap(msg)
  144.         if extended_msg:
  145.             print twrap(extended_msg)
  146.         
  147.  
  148.     
  149.     def error(self, summary, msg, extended_msg = None):
  150.         print 
  151.         print twrap(summary)
  152.         print twrap(msg)
  153.         if extended_msg:
  154.             print twrap(extended_msg)
  155.         
  156.         return False
  157.  
  158.     
  159.     def showInPager(self, output):
  160.         ''' helper to show output in a pager'''
  161.         for pager in [
  162.             '/usr/bin/sensible-pager',
  163.             '/bin/more']:
  164.             if os.path.exists(pager):
  165.                 p = subprocess.Popen([
  166.                     pager,
  167.                     '-'], stdin = subprocess.PIPE)
  168.                 p.stdin.write(output)
  169.                 p.stdin.close()
  170.                 p.wait()
  171.                 return None
  172.         
  173.         print output
  174.  
  175.     
  176.     def confirmChanges(self, summary, changes, downloadSize, actions = None, removal_bold = True):
  177.         DistUpgradeView.confirmChanges(self, summary, changes, downloadSize, actions)
  178.         print 
  179.         print twrap(summary)
  180.         print twrap(self.confirmChangesMessage)
  181.         print ' %s %s' % (_('Continue [yN] '), _('Details [d]')),
  182.         while True:
  183.             res = sys.stdin.readline()
  184.             if res.strip().lower().startswith(_('y')):
  185.                 return True
  186.             if res.strip().lower().startswith(_('n')):
  187.                 return False
  188.             print '%s %s' % (_('Continue [yN] '), _('Details [d]')),
  189.             continue
  190.             res.strip().lower().startswith(_('y')) if res.strip().lower().startswith(_('d')) else res.strip().lower().startswith(_('n'))
  191.  
  192.     
  193.     def askYesNoQuestion(self, summary, msg, default = 'No'):
  194.         print 
  195.         print twrap(summary)
  196.         print twrap(msg)
  197.         if default == 'No':
  198.             print _('Continue [yN] '),
  199.             res = sys.stdin.readline()
  200.             if res.strip().lower().startswith(_('y')):
  201.                 return True
  202.             return False
  203.         print _('Continue [Yn] '),
  204.         res = sys.stdin.readline()
  205.         if res.strip().lower().startswith(_('n')):
  206.             return False
  207.         return True
  208.  
  209.     
  210.     def confirmRestart(self):
  211.         return self.askYesNoQuestion(_('Restart required'), _("To finish the upgrade, a restart is required.\nIf you select 'y' the system will be restarted."), default = 'No')
  212.  
  213.  
  214. if __name__ == '__main__':
  215.     view = DistUpgradeViewText()
  216.     print twrap('89 packages are going to be upgraded.\nYou have to download a total of 82.7M.\nThis download will take about 10 minutes with a 1Mbit DSL connection and about 3 hours 12 minutes with a 56k modem.', subsequent_indent = ' ')
  217.     view = DistUpgradeViewText()
  218.     print view.askYesNoQuestion('hello', 'Icecream?', 'No')
  219.     print view.askYesNoQuestion('hello', 'Icecream?', 'Yes')
  220.     sys.exit(0)
  221.     view.confirmRestart()
  222.     cache = apt.Cache()
  223.     fp = view.getFetchProgress()
  224.     ip = view.getInstallProgress(cache)
  225.     for pkg in sys.argv[1:]:
  226.         cache[pkg].markInstall()
  227.     
  228.     cache.commit(fp, ip)
  229.     sys.exit(0)
  230.     view.getTerminal().call([
  231.         'dpkg',
  232.         '--configure',
  233.         '-a'])
  234.     view.error('short', 'long', 'asfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\n')
  235.     view.confirmChanges('xx', [], 100)
  236.     print view.askYesNoQuestion('hello', 'Icecream?')
  237.  
  238.