summaryrefslogtreecommitdiff
path: root/apt
diff options
context:
space:
mode:
Diffstat (limited to 'apt')
-rw-r--r--apt/cache.py62
-rw-r--r--apt/package.py19
-rw-r--r--apt/progress.py20
3 files changed, 53 insertions, 48 deletions
diff --git a/apt/cache.py b/apt/cache.py
index fbca0f2a..01034cf9 100644
--- a/apt/cache.py
+++ b/apt/cache.py
@@ -83,11 +83,7 @@ class Cache(object):
raise StopIteration
def has_key(self, key):
- try:
- self._dict[key]
- except KeyError:
- return False
- return True
+ return self._dict.has_key(key)
def __len__(self):
return len(self._dict)
@@ -116,8 +112,6 @@ class Cache(object):
def _runFetcher(self, fetcher):
# do the actual fetching
res = fetcher.Run()
- if res == fetcher.ResultFailed:
- return False
# now check the result (this is the code from apt-get.cc)
failed = False
@@ -146,31 +140,35 @@ class Cache(object):
if lock < 0:
raise IOError, "Failed to lock %s" % lockfile
- # this may as well throw a SystemError exception
- if not pm.GetArchives(fetcher, self._list, self._records):
- return False
- # now run the fetcher, throw exception if something fails to be
- # fetched
- res = self._runFetcher(fetcher)
-
- # cleanup
- os.close(lock)
- return res
+ try:
+ # this may as well throw a SystemError exception
+ if not pm.GetArchives(fetcher, self._list, self._records):
+ return False
+ # now run the fetcher, throw exception if something fails to be
+ # fetched
+ return self._runFetcher(fetcher)
+ finally:
+ os.close(lock)
def update(self, fetchProgress=None):
lockfile = apt_pkg.Config.FindDir("Dir::State::Lists") + "lock"
lock = apt_pkg.GetLock(lockfile)
if lock < 0:
raise IOError, "Failed to lock %s" % lockfile
- if fetchProgress == None:
- fetchProgress = apt.progress.FetchProgress()
- fetcher = apt_pkg.GetAcquire(fetchProgress)
- # this can throw a exception
- self._list.GetIndexes(fetcher)
- # now run the fetcher, throw exception if something fails to be
- # fetched
- res = self._runFetcher(fetcher)
- return res
+
+ try:
+ if fetchProgress == None:
+ fetchProgress = apt.progress.FetchProgress()
+ fetcher = apt_pkg.GetAcquire(fetchProgress)
+ # this can throw a exception
+ self._list.GetIndexes(fetcher)
+ # now run the fetcher, throw exception if something fails to be
+ # fetched
+ if self._runFetcher(fetcher) == fetcher.ResultContinue:
+ return True
+ return False
+ finally:
+ os.close(lock)
def installArchives(self, pm, installProgress):
installProgress.startUpdate()
@@ -266,11 +264,7 @@ class FilteredCache(object):
return self._filtered.keys()
def has_key(self, key):
- try:
- self._filtered[key]
- except KeyError:
- return False
- return True
+ return self._filtered.has_key(key)
def _reapplyFilter(self):
" internal helper to refilter "
@@ -337,9 +331,9 @@ if __name__ == "__main__":
# see if fetching works
- for dir in ["/tmp/pytest", "/tmp/pytest/partial"]:
- if not os.path.exists(dir):
- os.mkdir(dir)
+ for d in ["/tmp/pytest", "/tmp/pytest/partial"]:
+ if not os.path.exists(d):
+ os.mkdir(d)
apt_pkg.Config.Set("Dir::Cache::Archives","/tmp/pytest")
pm = apt_pkg.GetPackageManager(c._depcache)
fetcher = apt_pkg.GetAcquire(apt.progress.TextFetchProgress())
diff --git a/apt/package.py b/apt/package.py
index 4633123a..4fceb904 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -19,19 +19,22 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
-import apt_pkg, string, sys, random
+import apt_pkg
+import sys
+import random
+import string
class Package(object):
""" This class represents a package in the cache
"""
- def __init__(self, cache, depcache, records, list, pcache, pkgiter):
+ def __init__(self, cache, depcache, records, sourcelist, pcache, pkgiter):
""" Init the Package object """
self._cache = cache # low level cache
self._depcache = depcache
self._records = records
self._pkg = pkgiter
- self._list = list # sourcelist
+ self._list = sourcelist # sourcelist
self._pcache = pcache # python cache in cache.py
pass
@@ -52,8 +55,8 @@ class Package(object):
if ver.FileList == None:
print "No FileList for: %s " % self._pkg.Name()
return False
- file, index = ver.FileList.pop(0)
- self._records.Lookup((file,index))
+ f, index = ver.FileList.pop(0)
+ self._records.Lookup((f,index))
return True
@@ -317,10 +320,10 @@ if __name__ == "__main__":
cache = apt_pkg.GetCache()
depcache = apt_pkg.GetDepCache(cache)
records = apt_pkg.GetPkgRecords(cache)
- list = apt_pkg.GetPkgSourceList()
+ sourcelist = apt_pkg.GetPkgSourceList()
- iter = cache["apt-utils"]
- pkg = Package(cache, depcache, records, list, None, iter)
+ pkgiter = cache["apt-utils"]
+ pkg = Package(cache, depcache, records, sourcelist, None, pkgiter)
print "Name: %s " % pkg.name
print "ID: %s " % pkg.id
print "Priority (Candidate): %s " % pkg.priority
diff --git a/apt/progress.py b/apt/progress.py
index 40cf8e48..4119067c 100644
--- a/apt/progress.py
+++ b/apt/progress.py
@@ -21,7 +21,7 @@
import sys, apt_pkg, os, fcntl, string, re
-class OpProgress:
+class OpProgress(object):
""" Abstract class to implement reporting on cache opening
Subclass this class to implement simple Operation progress reporting
"""
@@ -62,7 +62,7 @@ class FetchProgress(object):
dlIgnored : "Ignored"}
def __init__(self):
- self.eta = ""
+ self.eta = 0.0
self.percent = 0.0
pass
@@ -117,7 +117,7 @@ class TextFetchProgress(FetchProgress):
res = false;
return res
-class DumbInstallProgress:
+class DumbInstallProgress(object):
""" Report the install progress
Subclass this class to implement install progress reporting
"""
@@ -135,9 +135,10 @@ class DumbInstallProgress:
class InstallProgress(DumbInstallProgress):
""" A InstallProgress that is pretty useful.
It supports the attributes 'percent' 'status' and callbacks
- for the dpkg errors and conffiles (not implemented yet)
+ for the dpkg errors and conffiles and status changes
"""
def __init__(self):
+ DumbInstallProgress.__init__(self)
(read, write) = os.pipe()
self.writefd=write
self.statusfd = os.fdopen(read, "r")
@@ -151,6 +152,9 @@ class InstallProgress(DumbInstallProgress):
def conffile(self,current,new):
" called when a conffile question from dpkg is detected "
pass
+ def statusChange(self, pkg, percent, status):
+ " called when the status changed "
+ pass
def updateInterface(self):
if self.statusfd != None:
try:
@@ -173,8 +177,12 @@ class InstallProgress(DumbInstallProgress):
match = re.compile("\s*\'(.*)\'\s*\'(.*)\'.*").match(status_str)
if match:
self.conffile(match.group(1), match.group(2))
- self.percent = float(percent)
- self.status = string.strip(status_str)
+ elif status == "pmstatus":
+ if float(percent) != self.percent or \
+ status_str != self.status:
+ self.statusChange(pkg, float(percent), status_str.strip())
+ self.percent = float(percent)
+ self.status = string.strip(status_str)
self.read = ""
def fork(self):