home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-apt / examples / inst.py < prev    next >
Encoding:
Python Source  |  2009-03-30  |  1.2 KB  |  52 lines

  1. #!/usr/bin/python
  2. # example how to deal with the depcache
  3.  
  4. import apt
  5. import sys
  6. import os
  7. import copy
  8. import time
  9.  
  10. from apt.progress import InstallProgress
  11.  
  12.  
  13. class TextInstallProgress(InstallProgress):
  14.  
  15.     def __init__(self):
  16.         apt.progress.InstallProgress.__init__(self)
  17.         self.last = 0.0
  18.  
  19.     def updateInterface(self):
  20.         InstallProgress.updateInterface(self)
  21.         if self.last >= self.percent:
  22.             return
  23.         sys.stdout.write("\r[%s] %s\n" %(self.percent, self.status))
  24.         sys.stdout.flush()
  25.         self.last = self.percent
  26.  
  27.     def conffile(self, current, new):
  28.         print "conffile prompt: %s %s" % (current, new)
  29.  
  30.     def error(self, errorstr):
  31.         print "got dpkg error: '%s'" % errorstr
  32.  
  33.  
  34. cache = apt.Cache(apt.progress.OpTextProgress())
  35.  
  36. fprogress = apt.progress.TextFetchProgress()
  37. iprogress = TextInstallProgress()
  38.  
  39. pkg = cache["3dchess"]
  40.  
  41. # install or remove, the importend thing is to keep us busy :)
  42. if pkg.isInstalled:
  43.     print "Going to delete %s" % pkg.name
  44.     pkg.markDelete()
  45. else:
  46.     print "Going to install %s" % pkg.name
  47.     pkg.markInstall()
  48. res = cache.commit(fprogress, iprogress)
  49. print res
  50.  
  51. sys.exit(0)
  52.