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 / apt / progress.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  9.1 KB  |  290 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import sys
  5. import apt_pkg
  6. import os
  7. import fcntl
  8. import string
  9. import re
  10.  
  11. class OpProgress(object):
  12.     ''' Abstract class to implement reporting on cache opening
  13.         Subclass this class to implement simple Operation progress reporting
  14.     '''
  15.     
  16.     def __init__(self):
  17.         pass
  18.  
  19.     
  20.     def update(self, percent):
  21.         pass
  22.  
  23.     
  24.     def done(self):
  25.         pass
  26.  
  27.  
  28.  
  29. class OpTextProgress(OpProgress):
  30.     ''' A simple text based cache open reporting class '''
  31.     
  32.     def __init__(self):
  33.         OpProgress.__init__(self)
  34.  
  35.     
  36.     def update(self, percent):
  37.         sys.stdout.write('\r%s: %.2i  ' % (self.subOp, percent))
  38.         sys.stdout.flush()
  39.  
  40.     
  41.     def done(self):
  42.         sys.stdout.write('\r%s: Done\n' % self.op)
  43.  
  44.  
  45.  
  46. class FetchProgress(object):
  47.     ''' Report the download/fetching progress
  48.         Subclass this class to implement fetch progress reporting
  49.     '''
  50.     dlDone = 0
  51.     dlQueued = 1
  52.     dlFailed = 2
  53.     dlHit = 3
  54.     dlIgnored = 4
  55.     dlStatusStr = {
  56.         dlDone: 'Done',
  57.         dlQueued: 'Queued',
  58.         dlFailed: 'Failed',
  59.         dlHit: 'Hit',
  60.         dlIgnored: 'Ignored' }
  61.     
  62.     def __init__(self):
  63.         self.eta = 0.0
  64.         self.percent = 0.0
  65.  
  66.     
  67.     def start(self):
  68.         pass
  69.  
  70.     
  71.     def stop(self):
  72.         pass
  73.  
  74.     
  75.     def updateStatus(self, uri, descr, shortDescr, status):
  76.         pass
  77.  
  78.     
  79.     def pulse(self):
  80.         ''' called periodically (to update the gui), importend to
  81.             return True to continue or False to cancel
  82.         '''
  83.         self.percent = (self.currentBytes + self.currentItems) * 100.0 / float(self.totalBytes + self.totalItems)
  84.         if self.currentCPS > 0:
  85.             self.eta = (self.totalBytes - self.currentBytes) / float(self.currentCPS)
  86.         
  87.         return True
  88.  
  89.     
  90.     def mediaChange(self, medium, drive):
  91.         pass
  92.  
  93.  
  94.  
  95. class TextFetchProgress(FetchProgress):
  96.     ''' Ready to use progress object for terminal windows '''
  97.     
  98.     def __init__(self):
  99.         self.items = { }
  100.  
  101.     
  102.     def updateStatus(self, uri, descr, shortDescr, status):
  103.         if status != self.dlQueued:
  104.             print '\r%s %s' % (self.dlStatusStr[status], descr)
  105.         
  106.         self.items[uri] = status
  107.  
  108.     
  109.     def pulse(self):
  110.         FetchProgress.pulse(self)
  111.         if self.currentCPS > 0:
  112.             s = '[%2.f%%] %sB/s %s' % (self.percent, apt_pkg.SizeToStr(int(self.currentCPS)), apt_pkg.TimeToStr(int(self.eta)))
  113.         else:
  114.             s = '%2.f%% [Working]' % self.percent
  115.         print '\r%s' % s,
  116.         sys.stdout.flush()
  117.         return True
  118.  
  119.     
  120.     def stop(self):
  121.         print '\rDone downloading            '
  122.  
  123.     
  124.     def mediaChange(self, medium, drive):
  125.         ''' react to media change events '''
  126.         res = True
  127.         print "Media change: please insert the disc labeled                '%s' in the drive '%s' and press enter" % (medium, drive)
  128.         s = sys.stdin.readline()
  129.         if s == 'c' or s == 'C':
  130.             res = false
  131.         
  132.         return res
  133.  
  134.  
  135.  
  136. class DumbInstallProgress(object):
  137.     ''' Report the install progress
  138.         Subclass this class to implement install progress reporting
  139.     '''
  140.     
  141.     def __init__(self):
  142.         pass
  143.  
  144.     
  145.     def startUpdate(self):
  146.         pass
  147.  
  148.     
  149.     def run(self, pm):
  150.         return pm.DoInstall()
  151.  
  152.     
  153.     def finishUpdate(self):
  154.         pass
  155.  
  156.     
  157.     def updateInterface(self):
  158.         pass
  159.  
  160.  
  161.  
  162. class InstallProgress(DumbInstallProgress):
  163.     """ A InstallProgress that is pretty useful.
  164.         It supports the attributes 'percent' 'status' and callbacks
  165.         for the dpkg errors and conffiles and status changes 
  166.      """
  167.     
  168.     def __init__(self):
  169.         DumbInstallProgress.__init__(self)
  170.         (read, write) = os.pipe()
  171.         self.writefd = write
  172.         self.statusfd = os.fdopen(read, 'r')
  173.         fcntl.fcntl(self.statusfd.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
  174.         self.read = ''
  175.         self.percent = 0.0
  176.         self.status = ''
  177.  
  178.     
  179.     def error(self, pkg, errormsg):
  180.         ''' called when a error is detected during the install '''
  181.         pass
  182.  
  183.     
  184.     def conffile(self, current, new):
  185.         ''' called when a conffile question from dpkg is detected '''
  186.         pass
  187.  
  188.     
  189.     def statusChange(self, pkg, percent, status):
  190.         ''' called when the status changed '''
  191.         pass
  192.  
  193.     
  194.     def updateInterface(self):
  195.         if self.statusfd != None:
  196.             
  197.             try:
  198.                 while not self.read.endswith('\n'):
  199.                     self.read += os.read(self.statusfd.fileno(), 1)
  200.                     continue
  201.                     self
  202.             except OSError:
  203.                 (errno, errstr) = None
  204.                 if errno != 11:
  205.                     print errstr
  206.                 
  207.             except:
  208.                 errno != 11
  209.  
  210.             if self.read.endswith('\n'):
  211.                 s = self.read
  212.                 (status, pkg, percent, status_str) = string.split(s, ':')
  213.                 if status == 'pmerror':
  214.                     self.error(pkg, status_str)
  215.                 elif status == 'pmconffile':
  216.                     match = re.compile("\\s*'(.*)'\\s*'(.*)'.*").match(status_str)
  217.                     if match:
  218.                         self.conffile(match.group(1), match.group(2))
  219.                     
  220.                 elif status == 'pmstatus':
  221.                     if float(percent) != self.percent or status_str != self.status:
  222.                         self.statusChange(pkg, float(percent), status_str.strip())
  223.                     
  224.                     self.percent = float(percent)
  225.                     self.status = string.strip(status_str)
  226.                 
  227.                 self.read = ''
  228.             
  229.         
  230.  
  231.     
  232.     def fork(self):
  233.         return os.fork()
  234.  
  235.     
  236.     def waitChild(self):
  237.         while True:
  238.             (pid, res) = os.waitpid(self.child_pid, os.WNOHANG)
  239.             if pid == self.child_pid:
  240.                 break
  241.             
  242.             self.updateInterface()
  243.         return os.WEXITSTATUS(res)
  244.  
  245.     
  246.     def run(self, pm):
  247.         pid = self.fork()
  248.         if pid == 0:
  249.             res = pm.DoInstall(self.writefd)
  250.             sys.exit(res)
  251.         
  252.         self.child_pid = pid
  253.         res = self.waitChild()
  254.         return res
  255.  
  256.  
  257.  
  258. class CdromProgress:
  259.     ''' Report the cdrom add progress
  260.         Subclass this class to implement cdrom add progress reporting
  261.     '''
  262.     
  263.     def __init__(self):
  264.         pass
  265.  
  266.     
  267.     def update(self, text, step):
  268.         ''' update is called regularly so that the gui can be redrawn '''
  269.         pass
  270.  
  271.     
  272.     def askCdromName(self):
  273.         pass
  274.  
  275.     
  276.     def changeCdrom(self):
  277.         pass
  278.  
  279.  
  280. if __name__ == '__main__':
  281.     import apt_pkg
  282.     apt_pkg.init()
  283.     progress = OpTextProgress()
  284.     cache = apt_pkg.GetCache(progress)
  285.     depcache = apt_pkg.GetDepCache(cache)
  286.     depcache.Init(progress)
  287.     fprogress = TextFetchProgress()
  288.     cache.Update(fprogress)
  289.  
  290.