aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2015-11-08 20:46:28 -0800
committerBrian Dolbec <dolsen@gentoo.org>2015-11-08 20:46:28 -0800
commit5cce2772eda7d0885c9d7cfea184a3f5606dddef (patch)
tree20ecba1c1095dbd8ece6e7c08e606fdd176e5127
parentgenbase.py: Fix py3 compatibilty issue for contents saving (diff)
downloadcatalyst-5cce2772eda7d0885c9d7cfea184a3f5606dddef.tar.gz
catalyst-5cce2772eda7d0885c9d7cfea184a3f5606dddef.tar.bz2
catalyst-5cce2772eda7d0885c9d7cfea184a3f5606dddef.zip
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.
-rw-r--r--catalyst/base/stagebase.py5
-rw-r--r--catalyst/config.py5
-rw-r--r--catalyst/support.py5
-rw-r--r--catalyst/targets/livecd_stage2.py19
4 files changed, 16 insertions, 18 deletions
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index ffd84de6..edbcaa66 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 5f72e151..ee73abd2 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 4bf1b227..e1325685 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 fa764214..943466e5 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",\