From 2298b4a03e03586d61309300e975421baca1537c Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Mon, 18 May 2015 16:15:05 +0100 Subject: 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. (From OE-Core rev: 99ac382d84667eb496dc510d3277b8c55b237738) Signed-off-by: Paul Eggleton Signed-off-by: Richard Purdie --- meta/lib/oe/patch.py | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'meta/lib/oe/patch.py') 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) -- cgit v1.2.3-54-g00ecf