home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-apt / examples / inst.py < prev    next >
Encoding:
Python Source  |  2006-03-02  |  1.1 KB  |  52 lines

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