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 / AppInstall / Util.py < prev    next >
Encoding:
Python Source  |  2006-08-28  |  2.7 KB  |  99 lines

  1. # misc utils
  2. # (c) 2005 Canonical, GPL
  3.  
  4. import warnings
  5. warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
  6. import apt
  7. import os
  8.  
  9. # Column enumeration
  10.  
  11. # Columns
  12. (COL_NAME,
  13.  COL_ITEM,
  14.  COL_POPCON) = range(3)
  15.  
  16. class MyCache(apt.Cache):
  17.     def __init__(self, progress=None):
  18.         apt.Cache.__init__(self, progress)
  19.         # cache the arch we use
  20.         pipe = os.popen("dpkg --print-architecture")
  21.         self._arch = pipe.read().strip()
  22.         del pipe
  23.     
  24.     def pkgDependsOn(self, pkgname, depends_name):
  25.         """ check if a given pkg depends on a given dependencie """
  26.         if not self.has_key(pkgname):
  27.             return False
  28.         pkg = self[pkgname]
  29.         candver = self._depcache.GetCandidateVer(pkg._pkg)
  30.     if candver == None:
  31.         return False
  32.     dependslist = candver.DependsList
  33.     for dep in dependslist.keys():
  34.             if dep == "Depends" or dep == "PreDepends":
  35.                 # get the list of each dependency object
  36.                 for depVerList in dependslist[dep]:
  37.                     for z in depVerList:
  38.                         # get all TargetVersions of
  39.                         # the dependency object
  40.                         for tpkg in z.AllTargets():
  41.                             if depends_name == tpkg.ParentPkg.Name:
  42.                                 return True
  43.         return False
  44.     def clean(self):
  45.         self._depcache.Init()
  46.     def getArch(self):
  47.         """ Return the cpu architecture of the system"""
  48.         
  49.         return self._arch
  50.  
  51.  
  52. def xmlescape(s):
  53.     from xml.sax.saxutils import escape
  54.     if s==None:
  55.         return ""
  56.     else:
  57.         return escape(s)
  58.  
  59.  
  60. def iterate_list_store(store, it):
  61.     """ iterate over a gtk tree-model, returns a gtk.TreeIter for each element
  62.     """
  63.     if not it:
  64.         raise StopIteration
  65.     yield it
  66.     while True:
  67.         it = store.iter_next(it)
  68.         if it == None:
  69.             raise StopIteration
  70.         yield it
  71.     
  72.  
  73.  
  74. # class SimpleFilteredCache(apt.cache.FilteredCache):
  75. #     """ a simpler version of the filtered cache that will not react to
  76. #         cache changed (no need, we are only interessted in text)
  77. #     """
  78. #     def filterCachePostChange(self):
  79. #         pass
  80. #     def runFilter(self):
  81. #         self._reapplyFilter()
  82.  
  83. # class SearchFilter(apt.cache.Filter):
  84. #     """ a filter class that just searchs insensitive in name/description """
  85. #     def SetSearchTerm(self, term):
  86. #         self._term = term.lower()
  87. #     def apply(self, pkg):
  88. #         if self._term in pkg.name.lower() or \
  89. #                self._term in pkg.description.lower():
  90. #             return True
  91. #         else:
  92. #             return False
  93. #     def __init__(self, query=None):
  94. #         if query != None:
  95. #             self.SetSearchTerm(query)
  96.  
  97.  
  98.  
  99.