summaryrefslogtreecommitdiffstats
path: root/lib/bb/cache.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-09 21:06:45 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-09 22:26:29 +0100
commit9f08b901375ba640f47596f1bcf43f98a931550f (patch)
tree061dade29876b4ef187460c166cbad15a1f485ae /lib/bb/cache.py
parent3627b02f77c78beedadadd77c619b9e5edaae076 (diff)
downloadopenembedded-core-contrib-9f08b901375ba640f47596f1bcf43f98a931550f.tar.gz
lib: Clean up various file access syntax
Python 3 is stricter about how files are accessed. Specficially: * Use open(), not file() * Use binary mode for binary files (when checksumming) * Use with statements to ensure files get closed * Add missing file close statements Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/cache.py')
-rw-r--r--lib/bb/cache.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/bb/cache.py b/lib/bb/cache.py
index 1c975b62e1..c92ba35641 100644
--- a/lib/bb/cache.py
+++ b/lib/bb/cache.py
@@ -738,8 +738,9 @@ class MultiProcessCache(object):
logger.debug(1, "Using cache in '%s'", self.cachefile)
try:
- p = pickle.Unpickler(file(self.cachefile, "rb"))
- data, version = p.load()
+ with open(self.cachefile, "rb") as f:
+ p = pickle.Unpickler(f)
+ data, version = p.load()
except:
return
@@ -779,8 +780,9 @@ class MultiProcessCache(object):
i = i + 1
continue
- p = pickle.Pickler(file(self.cachefile + "-" + str(i), "wb"), -1)
- p.dump([self.cachedata_extras, self.__class__.CACHE_VERSION])
+ with open(self.cachefile + "-" + str(i), "wb") as f:
+ p = pickle.Pickler(f, -1)
+ p.dump([self.cachedata_extras, self.__class__.CACHE_VERSION])
bb.utils.unlockfile(lf)
bb.utils.unlockfile(glf)
@@ -798,8 +800,9 @@ class MultiProcessCache(object):
glf = bb.utils.lockfile(self.cachefile + ".lock")
try:
- p = pickle.Unpickler(file(self.cachefile, "rb"))
- data, version = p.load()
+ with open(self.cachefile, "rb") as f:
+ p = pickle.Unpickler(f)
+ data, version = p.load()
except (IOError, EOFError):
data, version = None, None
@@ -809,8 +812,9 @@ class MultiProcessCache(object):
for f in [y for y in os.listdir(os.path.dirname(self.cachefile)) if y.startswith(os.path.basename(self.cachefile) + '-')]:
f = os.path.join(os.path.dirname(self.cachefile), f)
try:
- p = pickle.Unpickler(file(f, "rb"))
- extradata, version = p.load()
+ with open(f, "rb") as fd:
+ p = pickle.Unpickler(fd)
+ extradata, version = p.load()
except (IOError, EOFError):
extradata, version = self.create_cachedata(), None
@@ -822,8 +826,9 @@ class MultiProcessCache(object):
self.compress_keys(data)
- p = pickle.Pickler(file(self.cachefile, "wb"), -1)
- p.dump([data, self.__class__.CACHE_VERSION])
+ with open(self.cachefile, "wb") as f:
+ p = pickle.Pickler(f, -1)
+ p.dump([data, self.__class__.CACHE_VERSION])
bb.utils.unlockfile(glf)