summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/patch.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-05-18 16:15:05 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-05-20 21:41:04 +0100
commit2298b4a03e03586d61309300e975421baca1537c (patch)
tree238ca8a917b5a876e4c97df3442bba68ef1030f4 /meta/lib/oe/patch.py
parent3d0418a3314e70242b347ad370cd268ed5783685 (diff)
downloadpoky-2298b4a03e03586d61309300e975421baca1537c.tar.gz
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 <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/patch.py')
-rw-r--r--meta/lib/oe/patch.py40
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):
115 def _removePatchFile(self, all = False): 115 def _removePatchFile(self, all = False):
116 if not os.path.exists(self.seriespath): 116 if not os.path.exists(self.seriespath):
117 return 117 return
118 patches = open(self.seriespath, 'r+').readlines() 118 with open(self.seriespath, 'r+') as f:
119 patches = f.readlines()
119 if all: 120 if all:
120 for p in reversed(patches): 121 for p in reversed(patches):
121 self._removePatch(os.path.join(self.patchdir, p.strip())) 122 self._removePatch(os.path.join(self.patchdir, p.strip()))
@@ -405,16 +406,15 @@ class QuiltTree(PatchSet):
405 if not os.path.exists(self.dir): 406 if not os.path.exists(self.dir):
406 raise NotFoundError(self.dir) 407 raise NotFoundError(self.dir)
407 if os.path.exists(seriespath): 408 if os.path.exists(seriespath):
408 series = file(seriespath, 'r') 409 with open(seriespath, 'r') as f:
409 for line in series.readlines(): 410 for line in f.readlines():
410 patch = {} 411 patch = {}
411 parts = line.strip().split() 412 parts = line.strip().split()
412 patch["quiltfile"] = self._quiltpatchpath(parts[0]) 413 patch["quiltfile"] = self._quiltpatchpath(parts[0])
413 patch["quiltfilemd5"] = bb.utils.md5_file(patch["quiltfile"]) 414 patch["quiltfilemd5"] = bb.utils.md5_file(patch["quiltfile"])
414 if len(parts) > 1: 415 if len(parts) > 1:
415 patch["strippath"] = parts[1][2:] 416 patch["strippath"] = parts[1][2:]
416 self.patches.append(patch) 417 self.patches.append(patch)
417 series.close()
418 418
419 # determine which patches are applied -> self._current 419 # determine which patches are applied -> self._current
420 try: 420 try:
@@ -436,9 +436,8 @@ class QuiltTree(PatchSet):
436 self.InitFromDir() 436 self.InitFromDir()
437 PatchSet.Import(self, patch, force) 437 PatchSet.Import(self, patch, force)
438 oe.path.symlink(patch["file"], self._quiltpatchpath(patch["file"]), force=True) 438 oe.path.symlink(patch["file"], self._quiltpatchpath(patch["file"]), force=True)
439 f = open(os.path.join(self.dir, "patches","series"), "a"); 439 with open(os.path.join(self.dir, "patches", "series"), "a") as f:
440 f.write(os.path.basename(patch["file"]) + " -p" + patch["strippath"]+"\n") 440 f.write(os.path.basename(patch["file"]) + " -p" + patch["strippath"] + "\n")
441 f.close()
442 patch["quiltfile"] = self._quiltpatchpath(patch["file"]) 441 patch["quiltfile"] = self._quiltpatchpath(patch["file"])
443 patch["quiltfilemd5"] = bb.utils.md5_file(patch["quiltfile"]) 442 patch["quiltfilemd5"] = bb.utils.md5_file(patch["quiltfile"])
444 443
@@ -559,13 +558,12 @@ class UserResolver(Resolver):
559 bb.utils.mkdirhier(t) 558 bb.utils.mkdirhier(t)
560 import random 559 import random
561 rcfile = "%s/bashrc.%s.%s" % (t, str(os.getpid()), random.random()) 560 rcfile = "%s/bashrc.%s.%s" % (t, str(os.getpid()), random.random())
562 f = open(rcfile, "w") 561 with open(rcfile, "w") as f:
563 f.write("echo '*** Manual patch resolution mode ***'\n") 562 f.write("echo '*** Manual patch resolution mode ***'\n")
564 f.write("echo 'Dropping to a shell, so patch rejects can be fixed manually.'\n") 563 f.write("echo 'Dropping to a shell, so patch rejects can be fixed manually.'\n")
565 f.write("echo 'Run \"quilt refresh\" when patch is corrected, press CTRL+D to exit.'\n") 564 f.write("echo 'Run \"quilt refresh\" when patch is corrected, press CTRL+D to exit.'\n")
566 f.write("echo ''\n") 565 f.write("echo ''\n")
567 f.write(" ".join(patchcmd) + "\n") 566 f.write(" ".join(patchcmd) + "\n")
568 f.close()
569 os.chmod(rcfile, 0775) 567 os.chmod(rcfile, 0775)
570 568
571 self.terminal("bash --rcfile " + rcfile, 'Patch Rejects: Please fix patch rejects manually', self.patchset.d) 569 self.terminal("bash --rcfile " + rcfile, 'Patch Rejects: Please fix patch rejects manually', self.patchset.d)