From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/targets/, catalyst/, catalyst/base/
Date: Mon, 9 Nov 2015 04:47:39 +0000 (UTC) [thread overview]
Message-ID: <1447044388.5cce2772eda7d0885c9d7cfea184a3f5606dddef.dolsen@gentoo> (raw)
Message-ID: <20151109044739.1z-KHypzJE3Lu7SQ68yPYWnN4IdGbBvWBQEtVN8_CVI@z> (raw)
commit: 5cce2772eda7d0885c9d7cfea184a3f5606dddef
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 9 04:46:28 2015 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Nov 9 04:46:28 2015 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=5cce2772
catalyst: Convert nearly all use of open() to use the with statement.
There was one use in stagebase that was too large a code block to convert at this time.
catalyst/base/stagebase.py | 5 ++---
catalyst/config.py | 5 ++---
catalyst/support.py | 5 ++---
catalyst/targets/livecd_stage2.py | 19 ++++++++++---------
4 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index ffd84de..edbcaa6 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -848,9 +848,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
log.error('%s', unpack_errmsg % unpack_info)
if "snapcache" in self.settings["options"]:
- myf = open(snapshot_cache_hash_path, 'w')
- myf.write(self.settings["snapshot_path_hash"])
- myf.close()
+ with open(snapshot_cache_hash_path, 'w') as myf:
+ myf.write(self.settings["snapshot_path_hash"])
else:
log.info('Setting snapshot autoresume point')
self.resume.enable("unpack_portage",
diff --git a/catalyst/config.py b/catalyst/config.py
index 5f72e15..ee73abd 100644
--- a/catalyst/config.py
+++ b/catalyst/config.py
@@ -27,12 +27,11 @@ class ParserBase(object):
def parse_file(self, filename):
try:
- myf = open(filename, "r")
+ with open(filename, "r") as myf:
+ self.lines = myf.readlines()
except:
raise CatalystError("Could not open file " + filename,
print_traceback=True)
- self.lines = myf.readlines()
- myf.close()
self.filename = filename
self.parse()
diff --git a/catalyst/support.py b/catalyst/support.py
index 4bf1b22..e132568 100644
--- a/catalyst/support.py
+++ b/catalyst/support.py
@@ -155,9 +155,8 @@ def read_makeconf(mymakeconffile):
import portage_util
return portage_util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True)
except ImportError:
- myf=open(mymakeconffile,"r")
- mylines=myf.readlines()
- myf.close()
+ with open(mymakeconffile, "r") as myf:
+ mylines=myf.readlines()
return parse_makeconf(mylines)
except Exception:
raise CatalystError("Could not parse make.conf file " +
diff --git a/catalyst/targets/livecd_stage2.py b/catalyst/targets/livecd_stage2.py
index fa76421..943466e 100644
--- a/catalyst/targets/livecd_stage2.py
+++ b/catalyst/targets/livecd_stage2.py
@@ -68,8 +68,17 @@ class livecd_stage2(StageBase):
def run_local(self):
# what modules do we want to blacklist?
if "livecd/modblacklist" in self.settings:
+ path = normpath(self.settings["chroot_path"],
+ "/etc/modprobe.d/blacklist.conf")
try:
- myf=open(self.settings["chroot_path"]+"/etc/modprobe.d/blacklist.conf","a")
+ with open(path, "a") as myf:
+ myf.write("\n#Added by Catalyst:")
+ # workaround until config.py is using configparser
+ if isinstance(self.settings["livecd/modblacklist"], str):
+ self.settings["livecd/modblacklist"] = self.settings[
+ "livecd/modblacklist"].split()
+ for x in self.settings["livecd/modblacklist"]:
+ myf.write("\nblacklist "+x)
except:
self.unbind()
raise CatalystError("Couldn't open " +
@@ -77,14 +86,6 @@ class livecd_stage2(StageBase):
"/etc/modprobe.d/blacklist.conf.",
print_traceback=True)
- myf.write("\n#Added by Catalyst:")
- # workaround until config.py is using configparser
- if isinstance(self.settings["livecd/modblacklist"], str):
- self.settings["livecd/modblacklist"] = self.settings["livecd/modblacklist"].split()
- for x in self.settings["livecd/modblacklist"]:
- myf.write("\nblacklist "+x)
- myf.close()
-
def set_action_sequence(self):
self.settings["action_sequence"]=["unpack","unpack_snapshot",\
"config_profile_link","setup_confdir","portage_overlay",\
next reply other threads:[~2015-11-09 4:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-21 1:33 Brian Dolbec [this message]
2015-11-09 4:47 ` [gentoo-commits] proj/catalyst:master commit in: catalyst/targets/, catalyst/, catalyst/base/ Brian Dolbec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447044388.5cce2772eda7d0885c9d7cfea184a3f5606dddef.dolsen@gentoo \
--to=dolsen@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox