summaryrefslogtreecommitdiff
path: root/apt
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-05-09 12:59:08 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-05-09 12:59:08 +0000
commitae3f10fba648644a568dab3e21480580eb21e8a1 (patch)
tree4e7f64dc172c4813f926d8607672e28ce07f04bb /apt
parent5e4d32fbdcb6ab0bfe5326e09fea1c9ecd7ef98d (diff)
downloadpython-apt-ae3f10fba648644a568dab3e21480580eb21e8a1.tar.gz
* more work on the native python apt interface
Diffstat (limited to 'apt')
-rw-r--r--apt/cache.py60
-rw-r--r--apt/package.py154
-rw-r--r--apt/progress.py49
3 files changed, 263 insertions, 0 deletions
diff --git a/apt/cache.py b/apt/cache.py
new file mode 100644
index 00000000..e575745f
--- /dev/null
+++ b/apt/cache.py
@@ -0,0 +1,60 @@
+import apt_pkg
+from apt import Package
+from UserDict import UserDict
+
+class Filter(object):
+ def apply(self, pkg):
+ pass
+
+
+
+class Cache(object):
+ def __init__(self):
+ #dict.__init__(self)
+ self.open()
+
+ def open(self)
+ self._cache = apt_pkg.GetCache()
+ self._depcache = apt_pkg.GetDepCache(self._cache)
+ self._records = apt_pkg.GetPkgRecords(self._cache)
+ self._depcache.Init()
+ self._dict = {}
+
+ # build the packages dict
+ for pkg in self._cache.Packages:
+ self._dict[pkg.Name] = Package(self._cache, self._depcache, self._records, pkg)
+
+ def __getitem__(self, key):
+ return self._dict[key]
+
+ def has_key(self, key):
+ try:
+ self._dict[key]
+ except KeyError:
+ return False
+ return True
+
+ def __len__(self):
+ return len(self._dict)
+
+ def keys(self):
+ return self._dict.keys()
+
+ def Upgrade(self, DistUpgrade=False):
+ self._depcache.Upgrade(DistUpgrade)
+
+ def Commit(self, fprogress, iprogress):
+ self._depcache.Commit(fprogress, iprogress)
+
+ def
+
+if __name__ == "__main__":
+ print "Cache self test"
+ apt_pkg.init()
+ c = Cache()
+ print c.has_key("aptitudex")
+ p = c["aptitude"]
+ print p.Name()
+
+ for pkg in c.keys():
+ x= c[pkg].Name()
diff --git a/apt/package.py b/apt/package.py
new file mode 100644
index 00000000..138a520f
--- /dev/null
+++ b/apt/package.py
@@ -0,0 +1,154 @@
+import apt_pkg, string
+
+class Package(object):
+
+ def __init__(self, cache, depcache, records, pkgiter):
+ """ Init the Package object """
+ self._cache = cache
+ self._depcache = depcache
+ self._records = records
+ self._pkg = pkgiter
+ pass
+
+ # helper
+ def _LookupRecord(self, UseCandidate=True):
+ """ internal helper that moves the Records to the right
+ position, must be called before _records is accessed """
+ if UseCandidate:
+ ver = self._depcache.GetCandidateVer(self._pkg)
+ else:
+ ver = self._pkg.CurrentVer
+ file, index = ver.FileList.pop(0)
+ self._records.Lookup((file,index))
+
+
+ # basic information
+ def Name(self):
+ """ return the name of the package """
+ return self._pkg.Name
+
+ def ID(self):
+ """ return a uniq ID for the pkg, can be used to store
+ additional information about the pkg """
+ return self._pkg.ID
+
+ def InstalledVersion(self):
+ """ return the installed version as string """
+ ver = self._pkg.CurrentVer
+ if ver != None:
+ return ver.VerStr
+ else:
+ return None
+
+ def CandidateVersion(self):
+ """ return the candidate version as string """
+ ver = self._depcache.GetCandidateVer(self._pkg)
+ if ver != None:
+ return ver.VerStr
+ else:
+ return None
+
+ def SourcePackageName(self):
+ """ return the source package name as string """
+ self._LookupRecord()
+ src = self._records.SourcePkg
+ if src != "":
+ return src
+ else:
+ return self._pkg.Name
+
+ def Section(self):
+ """ return the section of the package"""
+ return self._pkg.Section
+
+ def Priority(self, UseCandidate=True):
+ """ return the priority """
+ if UseCandidate:
+ ver = self._depcache.GetCandidateVer(self._pkg)
+ else:
+ ver = self._pkg.CurrentVer
+ if ver:
+ return ver.PriorityStr
+ else:
+ return None
+
+ def Summary(self):
+ """ return the short description (one-line summary) """
+ self._LookupRecord()
+ return self._records.ShortDesc
+
+ def Description(self, format=False):
+ """ return the long description """
+ self._LookupRecord()
+ if format:
+ desc = ""
+ for line in string.split(self._records.LongDesc, "\n"):
+ tmp = string.strip(line)
+ if tmp == ".":
+ desc += "\n"
+ else:
+ desc += tmp + "\n"
+ return desc
+ else:
+ return self._records.LongDesc
+
+ # depcache state
+ def MarkedInstall(self):
+ return self._depcache.MarkedInstall(self._pkg)
+ def MarkedUpgrade(self):
+ return self._depcache.MarkedUpgrade(self._pkg)
+ def MarkedDelete(self):
+ return self._depcache.MarkedKeep(self._pkg)
+ def MarkedKeep(self):
+ return self._depcache.MarkedKeep(self._pkg)
+ def IsUpgradable(self):
+ return self._depcache.IsUpgradable(self._pkg)
+
+ # depcache action
+ def MarkKeep(self):
+ return self._depcache.MarkKeep(self._pkg)
+ def MarkDelete(self):
+ return self._depcache.MarkDelete(self._pkg)
+ def MarkInstall(self):
+ return self._depcache.MarkInstall(self._pkg)
+
+ # size
+ def PackageSize(self, UseCandidate=True):
+ if UseCandidate:
+ ver = self._depcache.GetCandidateVer(self._pkg)
+ else:
+ ver = self._pkg.GetCurrentVer
+ return ver.Size
+
+ def InstalledSize(self, UseCandidate=True):
+ if UseCandidate:
+ ver = self._depcache.GetCandidateVer(self._pkg)
+ else:
+ ver = self._pkg.GetCurrentVer
+ return ver.InstalledSize
+
+ def Commit(self, fprogress, iprogress):
+ self._depcache.Commit(fprogress, iprogress)
+
+# self-test
+if __name__ == "__main__":
+ print "Self-test for the Package modul"
+ apt_pkg.init()
+ cache = apt_pkg.GetCache()
+ depcache = apt_pkg.GetDepCache(cache)
+ records = apt_pkg.GetPkgRecords(cache)
+
+ iter = cache["apt-utils"]
+ pkg = Package(cache, depcache, records, iter)
+ print "Name: %s " % pkg.Name()
+ print "Installed: %s " % pkg.InstalledVersion()
+ print "Candidate: %s " % pkg.CandidateVersion()
+ print "SourcePkg: %s " % pkg.SourcePackageName()
+ print "Section: %s " % pkg.Section()
+ print "Priority (Candidate): %s " % pkg.Priority()
+ print "Priority (Installed): %s " % pkg.Priority(False)
+ print "Summary: %s" % pkg.Summary()
+ print "Description:\n%s" % pkg.Description()
+ print "Description (formated) :\n%s" % pkg.Description(True)
+ print "InstalledSize: %s " % pkg.InstalledSize()
+ print "PackageSize: %s " % pkg.PackageSize()
diff --git a/apt/progress.py b/apt/progress.py
new file mode 100644
index 00000000..ae5706af
--- /dev/null
+++ b/apt/progress.py
@@ -0,0 +1,49 @@
+
+class OpProgress:
+ def __init__(self):
+ pass
+ def Update(self, percent):
+ pass
+ def Done(self):
+ pass
+
+class FetchProgress:
+ def __init__(self):
+ pass
+
+ def Start(self):
+ pass
+
+ def Stop(self):
+ pass
+
+ def UpdateStatus(self, uri, descr, shortDescr, status):
+ pass
+
+ def Pulse(self):
+ pass
+
+ def MediaChange(self, medium, drive):
+ pass
+
+class InstallProgress:
+ def __init__(self):
+ pass
+ def StartUpdate(self):
+ pass
+ def FinishUpdate(self):
+ pass
+ def UpdateInterface(self):
+ pass
+
+
+class CdromProgress:
+ def __init__(self):
+ pass
+ def Update(self, text, step):
+ """ update is called regularly so that the gui can be redrawn """
+ pass
+ def AskCdromName(self):
+ pass
+ def ChangeCdrom(self):
+ pass