public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/catalyst:master commit in: catalyst/targets/, catalyst/, catalyst/base/
  2015-11-21  1:33 [gentoo-commits] proj/catalyst:pending " Brian Dolbec
@ 2015-11-09  4:47 ` Brian Dolbec
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Dolbec @ 2015-11-09  4:47 UTC (permalink / raw
  To: gentoo-commits

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",\


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/catalyst:master commit in: catalyst/targets/, catalyst/, catalyst/base/
@ 2016-05-20  2:39 Mike Frysinger
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2016-05-20  2:39 UTC (permalink / raw
  To: gentoo-commits

commit:     67af25c7824102b93db0d4016d6a9e101bbf6c09
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu May 19 19:18:29 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu May 19 19:39:22 2016 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=67af25c7

clear_dir: make a bit more robust/flexible

Make it so clear_dir will recover from non-directory paths, and it will
always call ensure_dirs even if the path didn't exist previously.  Most
callers want this behavior and call ensure_dirs themselves.

 catalyst/base/stagebase.py        |  9 ++-------
 catalyst/fileops.py               | 28 +++++++++++++++++++---------
 catalyst/targets/livecd_stage2.py | 12 +++---------
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index b6dd08d..6aa854b 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -18,7 +18,7 @@ from catalyst.base.targetbase import TargetBase
 from catalyst.base.clearbase import ClearBase
 from catalyst.base.genbase import GenBase
 from catalyst.lock import LockDir, LockInUse
-from catalyst.fileops import ensure_dirs, pjoin
+from catalyst.fileops import ensure_dirs, pjoin, clear_dir
 from catalyst.base.resume import AutoResume
 
 if sys.version_info[0] >= 3:
@@ -821,13 +821,11 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			cleanup_msg="Cleaning up invalid snapshot cache at \n\t"+\
 				self.settings["snapshot_cache_path"]+\
 				" (this can take a long time)..."
-			cleanup_errmsg="Error removing existing snapshot cache directory."
 
 			if self.settings["snapshot_path_hash"]==snapshot_cache_hash:
 				log.info('Valid snapshot cache, skipping unpack of portage tree...')
 				unpack=False
 		else:
-			cleanup_errmsg="Error removing existing snapshot directory."
 			cleanup_msg=\
 				'Cleaning up existing portage tree (this can take a long time)...'
 			unpack_info['destination'] = normpath(
@@ -847,10 +845,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
 				self.snapcache_lock.write_lock()
 			if os.path.exists(target_portdir):
 				log.info('%s', cleanup_msg)
-				cleanup_cmd = "rm -rf " + target_portdir
-				log.info('unpack() cleanup_cmd = %s', cleanup_cmd)
-				cmd(cleanup_cmd,cleanup_errmsg,env=self.env)
-			ensure_dirs(target_portdir, mode=0o755)
+			clear_dir(target_portdir)
 
 			log.notice('Unpacking portage tree (this can take a long time) ...')
 			if not self.decompressor.extract(unpack_info):

diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index 4fdc044..5fbca26 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -54,7 +54,8 @@ def ensure_dirs(path, gid=-1, uid=-1, mode=0o755, minimal=True,
 	return succeeded
 
 
-def clear_dir(target, mode=0o755, chg_flags=False, remove=False):
+def clear_dir(target, mode=0o755, chg_flags=False, remove=False,
+		clear_nondir=True):
 	'''Universal directory clearing function
 
 	@target: string, path to be cleared or removed
@@ -67,27 +68,36 @@ def clear_dir(target, mode=0o755, chg_flags=False, remove=False):
 	if not target:
 		log.debug('no target... returning')
 		return False
+
+	mystat = None
 	if os.path.isdir(target):
 		log.info('Emptying directory: %s', target)
 		# stat the dir, delete the dir, recreate the dir and set
 		# the proper perms and ownership
 		try:
 			log.debug('os.stat()')
-			mystat=os.stat(target)
+			mystat = os.stat(target)
 			# There's no easy way to change flags recursively in python
 			if chg_flags and os.uname()[0] == "FreeBSD":
 				os.system("chflags -R noschg " + target)
 			log.debug('shutil.rmtree()')
 			shutil.rmtree(target)
-			if not remove:
-				log.debug('ensure_dirs()')
-				ensure_dirs(target, mode=mode)
-				os.chown(target, mystat[ST_UID], mystat[ST_GID])
-				os.chmod(target, mystat[ST_MODE])
 		except Exception:
 			log.error('clear_dir failed', exc_info=True)
 			return False
-	else:
-		log.info('clear_dir failed: %s: is not a directory', target)
+	elif os.path.exists(target):
+		if clear_nondir:
+			os.unlink(clear_nondir)
+		else:
+			log.info('clear_dir failed: %s: is not a directory', target)
+			return False
+
+	if not remove:
+		log.debug('ensure_dirs()')
+		ensure_dirs(target, mode=mode)
+		if mystat:
+			os.chown(target, mystat[ST_UID], mystat[ST_GID])
+			os.chmod(target, mystat[ST_MODE])
+
 	log.debug('DONE, returning True')
 	return True

diff --git a/catalyst/targets/livecd_stage2.py b/catalyst/targets/livecd_stage2.py
index ea916b8..a3b5e5e 100644
--- a/catalyst/targets/livecd_stage2.py
+++ b/catalyst/targets/livecd_stage2.py
@@ -3,10 +3,8 @@ LiveCD stage2 target, builds upon previous LiveCD stage1 tarball
 """
 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
 
-import os
-
-from catalyst.support import (normpath, file_locate, CatalystError, cmd)
-from catalyst.fileops import ensure_dirs
+from catalyst.support import (normpath, file_locate, CatalystError)
+from catalyst.fileops import clear_dir
 from catalyst.base.stagebase import StageBase
 
 
@@ -46,11 +44,7 @@ class livecd_stage2(StageBase):
 		the final components needed to produce the iso image.
 		'''
 		super(livecd_stage2, self).set_target_path()
-		if os.path.isdir(self.settings["target_path"]):
-			cmd("rm -rf " + self.settings["target_path"],
-				"Could not remove existing directory: " +
-				self.settings["target_path"], env=self.env)
-		ensure_dirs(self.settings["target_path"])
+		clear_dir(self.settings['target_path'])
 
 	def run_local(self):
 		# what modules do we want to blacklist?


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/catalyst:master commit in: catalyst/targets/, catalyst/, catalyst/base/
@ 2020-04-10 21:04 Matt Turner
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Turner @ 2020-04-10 21:04 UTC (permalink / raw
  To: gentoo-commits

commit:     f6650276525e49b6b1a5bcd9bb6eefb0c0820a2c
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Fri Apr 10 07:30:36 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri Apr 10 07:30:36 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=f6650276

catalyst: Drop some dead code and comments

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py   | 3 ---
 catalyst/config.py           | 8 --------
 catalyst/defaults.py         | 3 ---
 catalyst/targets/snapshot.py | 2 +-
 4 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 72ef57d3..53d39536 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1388,7 +1388,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
 		for x in list(self.settings):
 			log.debug('setup_environment(); processing: %s', x)
 			if x == "options":
-				#self.env['clst_' + x] = ' '.join(self.settings[x])
 				for opt in self.settings[x]:
 					self.env['clst_' + opt.upper()] = "true"
 				continue
@@ -1398,13 +1397,11 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			varname = varname.replace(".", "_")
 			if isinstance(self.settings[x], str):
 				# Prefix to prevent namespace clashes
-				#os.environ[varname] = self.settings[x]
 				if "path" in x:
 					self.env[varname] = self.settings[x].rstrip("/")
 				else:
 					self.env[varname] = self.settings[x]
 			elif isinstance(self.settings[x], list):
-				#os.environ[varname] = ' '.join(self.settings[x])
 				self.env[varname] = ' '.join(self.settings[x])
 			elif isinstance(self.settings[x], bool):
 				if self.settings[x]:

diff --git a/catalyst/config.py b/catalyst/config.py
index a3a7200a..9f184ed5 100644
--- a/catalyst/config.py
+++ b/catalyst/config.py
@@ -45,7 +45,6 @@ class ParserBase(object):
 		cur_array = []
 
 		trailing_comment=re.compile(r'\s*#.*$')
-		#white_space=re.compile('\s+')
 
 		for x, myline in enumerate(self.lines):
 			myline = myline.strip()
@@ -63,10 +62,6 @@ class ParserBase(object):
 				mobjs = myline.split(self.key_value_separator, 1)
 				mobjs[1] = mobjs[1].strip().strip('"')
 
-#				# Check that this key doesn't exist already in the spec
-#				if mobjs[0] in values:
-#					raise Exception("You have a duplicate key (" + mobjs[0] + ") in your spec. Please fix it")
-
 				# Start a new array using the first element of mobjs
 				cur_array = [mobjs[0]]
 				if mobjs[1]:
@@ -75,7 +70,6 @@ class ParserBase(object):
 					mobjs[1] = mobjs[1] % values
 					if self.multiple_values:
 						# split on white space creating additional array elements
-#						subarray = white_space.split(mobjs[1])
 						subarray = mobjs[1].split()
 						cur_array += subarray
 					else:
@@ -84,8 +78,6 @@ class ParserBase(object):
 			# Else add on to the last key we were working on
 			else:
 				if self.multiple_values:
-#					mobjs = white_space.split(myline)
-#					cur_array += mobjs
 					cur_array += myline.split()
 				else:
 					raise CatalystError("Syntax error: %s" % x, print_traceback=True)

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 72a8f56a..5b4ae83e 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -104,12 +104,10 @@ SOURCE_MOUNT_DEFAULTS = {
 	"run": "tmpfs",
 	}
 
-# legend:  key: message
 option_messages = {
 	"autoresume": "Autoresuming support enabled.",
 	"ccache": "Compiler cache support enabled.",
 	"clear-autoresume": "Cleaning autoresume flags support enabled.",
-	#"compress": "Compression enabled.",
 	"distcc": "Distcc support enabled.",
 	"icecream": "Icecream compiler cluster support enabled.",
 	"kerncache": "Kernel cache support enabled.",
@@ -117,5 +115,4 @@ option_messages = {
 	"purge": "Purge support enabled.",
 	"seedcache": "Seed cache support enabled.",
 	"snapcache": "Snapshot cache support enabled.",
-	#"tarball": "Tarball creation enabled.",
 	}

diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py
index 607e718e..c80d224f 100644
--- a/catalyst/targets/snapshot.py
+++ b/catalyst/targets/snapshot.py
@@ -21,7 +21,7 @@ class snapshot(TargetBase, GenBase):
 
 		TargetBase.__init__(self, myspec, addlargs)
 		GenBase.__init__(self,myspec)
-		#self.settings=myspec
+
 		self.settings["target_subpath"]="repos"
 		st=self.settings["storedir"]
 		self.settings["snapshot_path"] = normpath(st + "/snapshots/"


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-10 21:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-10 21:04 [gentoo-commits] proj/catalyst:master commit in: catalyst/targets/, catalyst/, catalyst/base/ Matt Turner
  -- strict thread matches above, loose matches on Subject: below --
2016-05-20  2:39 Mike Frysinger
2015-11-21  1:33 [gentoo-commits] proj/catalyst:pending " Brian Dolbec
2015-11-09  4:47 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox