diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2015-05-18 16:15:05 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-05-19 08:16:47 +0100 |
commit | 99ac382d84667eb496dc510d3277b8c55b237738 (patch) | |
tree | 6c2da33f805a95857a5acade4dfcb165d4322753 /meta/lib/oe | |
parent | 69f426a2d966a2228cbdc708b9ddab31005c6d96 (diff) | |
download | openembedded-core-99ac382d84667eb496dc510d3277b8c55b237738.tar.gz openembedded-core-99ac382d84667eb496dc510d3277b8c55b237738.tar.bz2 openembedded-core-99ac382d84667eb496dc510d3277b8c55b237738.zip |
lib/oe/patch: use with open() for all file operations
with open(...)... is preferred for reading/writing files as it is neater
and takes care of closing the file for you.
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r-- | meta/lib/oe/patch.py | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index f68d40f8c8..e1f1c53bef 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py @@ -115,7 +115,8 @@ class PatchTree(PatchSet): def _removePatchFile(self, all = False): if not os.path.exists(self.seriespath): return - patches = open(self.seriespath, 'r+').readlines() + with open(self.seriespath, 'r+') as f: + patches = f.readlines() if all: for p in reversed(patches): self._removePatch(os.path.join(self.patchdir, p.strip())) @@ -405,16 +406,15 @@ class QuiltTree(PatchSet): if not os.path.exists(self.dir): raise NotFoundError(self.dir) if os.path.exists(seriespath): - series = file(seriespath, 'r') - for line in series.readlines(): - patch = {} - parts = line.strip().split() - patch["quiltfile"] = self._quiltpatchpath(parts[0]) - patch["quiltfilemd5"] = bb.utils.md5_file(patch["quiltfile"]) - if len(parts) > 1: - patch["strippath"] = parts[1][2:] - self.patches.append(patch) - series.close() + with open(seriespath, 'r') as f: + for line in f.readlines(): + patch = {} + parts = line.strip().split() + patch["quiltfile"] = self._quiltpatchpath(parts[0]) + patch["quiltfilemd5"] = bb.utils.md5_file(patch["quiltfile"]) + if len(parts) > 1: + patch["strippath"] = parts[1][2:] + self.patches.append(patch) # determine which patches are applied -> self._current try: @@ -436,9 +436,8 @@ class QuiltTree(PatchSet): self.InitFromDir() PatchSet.Import(self, patch, force) oe.path.symlink(patch["file"], self._quiltpatchpath(patch["file"]), force=True) - f = open(os.path.join(self.dir, "patches","series"), "a"); - f.write(os.path.basename(patch["file"]) + " -p" + patch["strippath"]+"\n") - f.close() + with open(os.path.join(self.dir, "patches", "series"), "a") as f: + f.write(os.path.basename(patch["file"]) + " -p" + patch["strippath"] + "\n") patch["quiltfile"] = self._quiltpatchpath(patch["file"]) patch["quiltfilemd5"] = bb.utils.md5_file(patch["quiltfile"]) @@ -559,13 +558,12 @@ class UserResolver(Resolver): bb.utils.mkdirhier(t) import random rcfile = "%s/bashrc.%s.%s" % (t, str(os.getpid()), random.random()) - f = open(rcfile, "w") - f.write("echo '*** Manual patch resolution mode ***'\n") - f.write("echo 'Dropping to a shell, so patch rejects can be fixed manually.'\n") - f.write("echo 'Run \"quilt refresh\" when patch is corrected, press CTRL+D to exit.'\n") - f.write("echo ''\n") - f.write(" ".join(patchcmd) + "\n") - f.close() + with open(rcfile, "w") as f: + f.write("echo '*** Manual patch resolution mode ***'\n") + f.write("echo 'Dropping to a shell, so patch rejects can be fixed manually.'\n") + f.write("echo 'Run \"quilt refresh\" when patch is corrected, press CTRL+D to exit.'\n") + f.write("echo ''\n") + f.write(" ".join(patchcmd) + "\n") os.chmod(rcfile, 0775) self.terminal("bash --rcfile " + rcfile, 'Patch Rejects: Please fix patch rejects manually', self.patchset.d) |