summaryrefslogtreecommitdiff
path: root/apt/cache.py
diff options
context:
space:
mode:
Diffstat (limited to 'apt/cache.py')
-rw-r--r--apt/cache.py62
1 files changed, 28 insertions, 34 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())