public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-01-22  5:04 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-01-22  5:04 UTC (permalink / raw
  To: gentoo-commits

commit:     c257c5d51c3936b0a5bafee7aa40a4ff340cc89a
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 23:56:02 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Jan 22 04:28:54 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=c257c5d5

modules/generic_stage_target.py, Create SOURCE_MOUNTS_DEFAULTS

Similarly to TARGET_MOUNTS_DEFAULTS this is a temporary location.
This will simplify the migration to being fully configurable.
It also simplifies initialization somewhat.

---
 catalyst/base/stagebase.py | 24 ++++++++++++++----------
 catalyst/defaults.py       |  9 +++++++++
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index fd7fda5..7e09ed1 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -13,7 +13,7 @@ from catalyst.support import (CatalystError, msg, file_locate, normpath,
 from catalyst.base.targetbase import TargetBase
 from catalyst.base.clearbase import ClearBase
 from catalyst.base.genbase import GenBase
-from catalyst.defaults import TARGET_MOUNT_DEFAULTS
+from catalyst.defaults import TARGET_MOUNT_DEFAULTS, SOURCE_MOUNT_DEFAULTS
 from catalyst.lock import LockDir
 from catalyst.fileops import ensure_dirs, pjoin
 from catalyst.base.resume import AutoResume
@@ -194,15 +194,19 @@ class StageBase(TargetBase, ClearBase, GenBase):
 		""" Setup our mount points """
 		# initialize our target mounts.
 		self.target_mounts = TARGET_MOUNT_DEFAULTS.copy()
-		if "snapcache" in self.settings["options"]:
-			self.mounts=["proc", "dev", 'portdir', 'distdir', 'port_tmpdir']
-			self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
-				"portdir":normpath(self.settings["snapshot_cache_path"]+"/" + self.settings["repo_name"]),
-				"distdir":self.settings["distdir"],"port_tmpdir":"tmpfs"}
-		else:
-			self.mounts=["proc","dev", "distdir", "port_tmpdir"]
-			self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
-				"distdir":self.settings["distdir"], "port_tmpdir":"tmpfs"}
+
+		self.mounts = ["proc", "dev", "portdir", "distdir", "port_tmpdir"]
+		# initialize our source mounts
+		self.mountmap = SOURCE_MOUNT_DEFAULTS.copy()
+		# update them from settings
+		self.mountmap["distdir"] = self.settings["distdir"]
+		self.mountmap["portdir"] = normpath("/".join([
+			self.settings["snapshot_cache_path"],
+			self.settings["repo_name"],
+			]))
+		if "snapcache" not in self.settings["options"]:
+			self.mounts.remove("portdir")
+			#self.mountmap["portdir"] = None
 		if os.uname()[0] == "Linux":
 			self.mounts.append("devpts")
 

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 11cecb3..27bcff4 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -94,6 +94,15 @@ TARGET_MOUNT_DEFAULTS = {
 	"proc": "/proc",
 	}
 
+SOURCE_MOUNT_DEFAULTS = {
+	"dev": "/dev",
+	"devpts": "/dev/pts",
+	"distdir": None,      # set from settings options
+	"portdir": None,      # set from settings options
+	"port_tmpdir": "tmpfs",
+	"proc": "/proc",
+	}
+
 # legend:  key: message
 option_messages = {
 	"autoresume": "Autoresuming support enabled.",


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-04-18 16:52 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-04-18 16:52 UTC (permalink / raw
  To: gentoo-commits

commit:     9e6bcc4b78172611430db8b981b2ce1b23a59263
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 29 09:03:14 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Apr 18 16:50:36 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=9e6bcc4b

Fix mounts and mountmap port_logdir code block.

Conflicts:
	catalyst/base/stagebase.py

---
 catalyst/base/stagebase.py | 9 +++++----
 catalyst/defaults.py       | 3 +++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 2cce2f7..aa9be38 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -13,7 +13,8 @@ from catalyst.support import (CatalystError, msg, file_locate, normpath,
 from catalyst.base.targetbase import TargetBase
 from catalyst.base.clearbase import ClearBase
 from catalyst.base.genbase import GenBase
-from catalyst.defaults import TARGET_MOUNT_DEFAULTS, SOURCE_MOUNT_DEFAULTS
+from catalyst.defaults import (TARGET_MOUNT_DEFAULTS, SOURCE_MOUNT_DEFAULTS,
+	PORT_LOGDIR_CLEAN)
 from catalyst.lock import LockDir
 from catalyst.fileops import ensure_dirs, pjoin
 from catalyst.base.resume import AutoResume
@@ -253,9 +254,9 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
 		if "port_logdir" in self.settings:
 			self.mounts.append("port_logdir")
-			self.mountmap["port_logdir"]=self.settings["port_logdir"]
-			self.env["PORT_LOGDIR"]=self.settings["port_logdir"]
-			self.env["PORT_LOGDIR_CLEAN"]='find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
+			self.mountmap["port_logdir"] = self.settings["port_logdir"]
+			self.env["PORT_LOGDIR"] = self.settings["port_logdir"]
+			self.env["PORT_LOGDIR_CLEAN"] = PORT_LOGDIR_CLEAN
 
 	def override_cbuild(self):
 		if "CBUILD" in self.makeconf:

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 1f86c1d..59941ee 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -105,6 +105,9 @@ SOURCE_MOUNT_DEFAULTS = {
 	"shm": "shmfs",
 	}
 
+PORT_LOGDIR_CLEAN = \
+	'find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
+
 # legend:  key: message
 option_messages = {
 	"autoresume": "Autoresuming support enabled.",


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-04-18 16:52 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-04-18 16:52 UTC (permalink / raw
  To: gentoo-commits

commit:     237fccb622b92f4feabf89ac9ecb5c2a1b9b5e5c
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 23:57:28 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Apr 18 16:50:36 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=237fccb6

catalyst/targets/generic_stage_target.py: mount /dev/shm on linux

Add shm targets defaults. Anthony G. Basile <blueness <AT> gentoo.org>
Some build systems require /dev/shm to be mounted, like python's
build system.  We make sure that on Linux systems, /dev/shm is
mounted in the stage chroots.  See bug #496328.

Douglas Freed <dwfreed <AT> mtu.edu> :
Mount /dev/shm in the chroot with the right options
Bind mounting /dev/shm into the chroot isn't a good idea, as there may
be collisions and result in weird side effects.  Instead, we can just
mount a new tmpfs there, with the right options to ensure security.

(Forward ported to 3.0 branch from 2.X Brian Dolbec)

---
 catalyst/base/stagebase.py | 6 +++++-
 catalyst/defaults.py       | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 31b5779..2cce2f7 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -209,6 +209,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			#self.mountmap["portdir"] = None
 		if os.uname()[0] == "Linux":
 			self.mounts.append("devpts")
+			self.mounts.append("shm")
 
 		self.set_mounts()
 
@@ -930,7 +931,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			ensure_dirs(target, mode=0755)
 
 			if not os.path.exists(self.mountmap[x]):
-				if not self.mountmap[x] == "tmpfs":
+				if self.mountmap[x] not in ["tmpfs", "shmfs"]:
 					ensure_dirs(self.mountmap[x], mode=0755)
 
 			src=self.mountmap[x]
@@ -951,6 +952,9 @@ class StageBase(TargetBase, ClearBase, GenBase):
 							self.settings["var_tmpfs_portage"] + "G " + \
 							src + " " + target
 						retval=os.system(cmd)
+				elif src == "shmfs":
+					cmd = "mount -t tmpfs -o noexec,nosuid,nodev shm " + target
+					retval=os.system(cmd)
 				else:
 					cmd = "mount --bind " + src + " " + target
 					#print "bind(); cmd =", cmd

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 27bcff4..1f86c1d 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -92,6 +92,7 @@ TARGET_MOUNT_DEFAULTS = {
 	"port_tmpdir": "/var/tmp/portage",
 	"port_logdir": "/var/log/portage",
 	"proc": "/proc",
+	"shm": "/dev/shm",
 	}
 
 SOURCE_MOUNT_DEFAULTS = {
@@ -101,6 +102,7 @@ SOURCE_MOUNT_DEFAULTS = {
 	"portdir": None,      # set from settings options
 	"port_tmpdir": "tmpfs",
 	"proc": "/proc",
+	"shm": "shmfs",
 	}
 
 # legend:  key: message


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-04-18 16:52 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-04-18 16:52 UTC (permalink / raw
  To: gentoo-commits

commit:     4ed44b55ac0d9aa773f8a79c5ded8df08f1eef1b
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 23:56:02 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Apr 18 16:50:35 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=4ed44b55

modules/generic_stage_target.py, Create SOURCE_MOUNTS_DEFAULTS

Similarly to TARGET_MOUNTS_DEFAULTS this is a temporary location.
This will simplify the migration to being fully configurable.
It also simplifies initialization somewhat.

---
 catalyst/base/stagebase.py | 24 ++++++++++++++----------
 catalyst/defaults.py       |  9 +++++++++
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 0e9b84f..31b5779 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -13,7 +13,7 @@ from catalyst.support import (CatalystError, msg, file_locate, normpath,
 from catalyst.base.targetbase import TargetBase
 from catalyst.base.clearbase import ClearBase
 from catalyst.base.genbase import GenBase
-from catalyst.defaults import TARGET_MOUNT_DEFAULTS
+from catalyst.defaults import TARGET_MOUNT_DEFAULTS, SOURCE_MOUNT_DEFAULTS
 from catalyst.lock import LockDir
 from catalyst.fileops import ensure_dirs, pjoin
 from catalyst.base.resume import AutoResume
@@ -194,15 +194,19 @@ class StageBase(TargetBase, ClearBase, GenBase):
 		""" Setup our mount points """
 		# initialize our target mounts.
 		self.target_mounts = TARGET_MOUNT_DEFAULTS.copy()
-		if "snapcache" in self.settings["options"]:
-			self.mounts=["proc", "dev", 'portdir', 'distdir', 'port_tmpdir']
-			self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
-				"portdir":normpath(self.settings["snapshot_cache_path"]+"/" + self.settings["repo_name"]),
-				"distdir":self.settings["distdir"],"port_tmpdir":"tmpfs"}
-		else:
-			self.mounts=["proc","dev", "distdir", "port_tmpdir"]
-			self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
-				"distdir":self.settings["distdir"], "port_tmpdir":"tmpfs"}
+
+		self.mounts = ["proc", "dev", "portdir", "distdir", "port_tmpdir"]
+		# initialize our source mounts
+		self.mountmap = SOURCE_MOUNT_DEFAULTS.copy()
+		# update them from settings
+		self.mountmap["distdir"] = self.settings["distdir"]
+		self.mountmap["portdir"] = normpath("/".join([
+			self.settings["snapshot_cache_path"],
+			self.settings["repo_name"],
+			]))
+		if "snapcache" not in self.settings["options"]:
+			self.mounts.remove("portdir")
+			#self.mountmap["portdir"] = None
 		if os.uname()[0] == "Linux":
 			self.mounts.append("devpts")
 

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 11cecb3..27bcff4 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -94,6 +94,15 @@ TARGET_MOUNT_DEFAULTS = {
 	"proc": "/proc",
 	}
 
+SOURCE_MOUNT_DEFAULTS = {
+	"dev": "/dev",
+	"devpts": "/dev/pts",
+	"distdir": None,      # set from settings options
+	"portdir": None,      # set from settings options
+	"port_tmpdir": "tmpfs",
+	"proc": "/proc",
+	}
+
 # legend:  key: message
 option_messages = {
 	"autoresume": "Autoresuming support enabled.",


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-04-18 16:52 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-04-18 16:52 UTC (permalink / raw
  To: gentoo-commits

commit:     0a33779ee771de6d1bbfbde21365cb961e62720a
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Wed Jan 22 04:07:20 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Apr 18 16:50:35 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=0a33779e

Rename target_mounts, devpts and sort members.

---
 catalyst/base/stagebase.py |  8 +++++---
 catalyst/defaults.py       | 14 +++++++-------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 02ccb37..0e9b84f 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -13,11 +13,12 @@ from catalyst.support import (CatalystError, msg, file_locate, normpath,
 from catalyst.base.targetbase import TargetBase
 from catalyst.base.clearbase import ClearBase
 from catalyst.base.genbase import GenBase
-from catalyst.defaults import target_mounts
+from catalyst.defaults import TARGET_MOUNT_DEFAULTS
 from catalyst.lock import LockDir
 from catalyst.fileops import ensure_dirs, pjoin
 from catalyst.base.resume import AutoResume
 
+
 class StageBase(TargetBase, ClearBase, GenBase):
 	"""
 	This class does all of the chroot setup, copying of files, etc. It is
@@ -191,7 +192,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			file_locate(self.settings,["portage_confdir"],expand=0)
 
 		""" Setup our mount points """
-		self.target_mounts = target_mounts.copy()
+		# initialize our target mounts.
+		self.target_mounts = TARGET_MOUNT_DEFAULTS.copy()
 		if "snapcache" in self.settings["options"]:
 			self.mounts=["proc", "dev", 'portdir', 'distdir', 'port_tmpdir']
 			self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
@@ -202,7 +204,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
 				"distdir":self.settings["distdir"], "port_tmpdir":"tmpfs"}
 		if os.uname()[0] == "Linux":
-			self.mounts.append("pts")
+			self.mounts.append("devpts")
 
 		self.set_mounts()
 

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 0b98d83..11cecb3 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -80,18 +80,18 @@ confdefaults={
 	}
 
 
-target_mounts = {
-	"proc": "/proc",
+TARGET_MOUNT_DEFAULTS = {
+	"ccache": "/var/tmp/ccache",
 	"dev": "/dev",
-	"pts": "/dev/pts",
-	"portdir": "/usr/portage",
+	"devpts": "/dev/pts",
 	"distdir": "/usr/portage/distfiles",
+	"icecream": "/usr/lib/icecc/bin",
+	"kerncache": "/tmp/kerncache",
 	"packagedir": "/usr/portage/packages",
+	"portdir": "/usr/portage",
 	"port_tmpdir": "/var/tmp/portage",
-	"kerncache": "/tmp/kerncache",
-	"ccache": "/var/tmp/ccache",
-	"icecream": "/var/cache/icecream",
 	"port_logdir": "/var/log/portage",
+	"proc": "/proc",
 	}
 
 # legend:  key: message


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-01-22  5:04 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-01-22  5:04 UTC (permalink / raw
  To: gentoo-commits

commit:     59f782fb182510a86bbb5b120083b93b90cf7a80
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 29 09:03:14 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Jan 22 04:30:23 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=59f782fb

Fix mounts and mountmap port_logdir code block.

Conflicts:
	catalyst/base/stagebase.py

---
 catalyst/base/stagebase.py | 9 +++++----
 catalyst/defaults.py       | 3 +++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 10868ee..3021620 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -13,7 +13,8 @@ from catalyst.support import (CatalystError, msg, file_locate, normpath,
 from catalyst.base.targetbase import TargetBase
 from catalyst.base.clearbase import ClearBase
 from catalyst.base.genbase import GenBase
-from catalyst.defaults import TARGET_MOUNT_DEFAULTS, SOURCE_MOUNT_DEFAULTS
+from catalyst.defaults import (TARGET_MOUNT_DEFAULTS, SOURCE_MOUNT_DEFAULTS,
+	PORT_LOGDIR_CLEAN)
 from catalyst.lock import LockDir
 from catalyst.fileops import ensure_dirs, pjoin
 from catalyst.base.resume import AutoResume
@@ -253,9 +254,9 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
 		if "port_logdir" in self.settings:
 			self.mounts.append("port_logdir")
-			self.mountmap["port_logdir"]=self.settings["port_logdir"]
-			self.env["PORT_LOGDIR"]=self.settings["port_logdir"]
-			self.env["PORT_LOGDIR_CLEAN"]='find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
+			self.mountmap["port_logdir"] = self.settings["port_logdir"]
+			self.env["PORT_LOGDIR"] = self.settings["port_logdir"]
+			self.env["PORT_LOGDIR_CLEAN"] = PORT_LOGDIR_CLEAN
 
 	def override_cbuild(self):
 		if "CBUILD" in self.makeconf:

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 1f86c1d..59941ee 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -105,6 +105,9 @@ SOURCE_MOUNT_DEFAULTS = {
 	"shm": "shmfs",
 	}
 
+PORT_LOGDIR_CLEAN = \
+	'find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
+
 # legend:  key: message
 option_messages = {
 	"autoresume": "Autoresuming support enabled.",


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-01-22  5:04 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-01-22  5:04 UTC (permalink / raw
  To: gentoo-commits

commit:     b5dcf208b1798e0ba90adf5b85866b5e5ef42c65
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Dec 31 17:41:52 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Jan  3 18:02:21 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=b5dcf208

Add some docstring updates.

---
 catalyst/base/resume.py | 1 +
 catalyst/fileops.py     | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/catalyst/base/resume.py b/catalyst/base/resume.py
index cf495fc..2c006ab 100644
--- a/catalyst/base/resume.py
+++ b/catalyst/base/resume.py
@@ -142,6 +142,7 @@ class AutoResume(object):
 	def clear_all(self, remove=False):
 		'''Clear all active resume points
 
+		@remove: boolean, passed through to clear_dir()
 		@return boolean
 		'''
 		if clear_dir(self.basedir, mode=0755, chg_flags=True, remove=remove):

diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index 245c83e..fd98db2 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -52,6 +52,12 @@ def ensure_dirs(path, gid=-1, uid=-1, mode=0777, minimal=True,
 
 def clear_dir(target, mode=0755, chg_flags=False, remove=False):
 	'''Universal directory clearing function
+
+	@target: string, path to be cleared or removed
+	@mode: integer, desired mode to set the directory to
+	@chg_flags: boolean used for FreeBSD hoosts
+	@remove: boolean, passed through to clear_dir()
+	@return boolean
 	'''
 	#print "fileops.clear_dir()"
 	if not target:


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-01-22  5:04 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-01-22  5:04 UTC (permalink / raw
  To: gentoo-commits

commit:     a6e39695fec360dce3612e8b3f00ff0cc9fec4d0
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Wed Jan 22 04:07:20 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Jan 22 04:28:49 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=a6e39695

Rename target_mounts, devpts and sort members.

---
 catalyst/base/stagebase.py |  8 +++++---
 catalyst/defaults.py       | 14 +++++++-------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index f42d943..fd7fda5 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -13,11 +13,12 @@ from catalyst.support import (CatalystError, msg, file_locate, normpath,
 from catalyst.base.targetbase import TargetBase
 from catalyst.base.clearbase import ClearBase
 from catalyst.base.genbase import GenBase
-from catalyst.defaults import target_mounts
+from catalyst.defaults import TARGET_MOUNT_DEFAULTS
 from catalyst.lock import LockDir
 from catalyst.fileops import ensure_dirs, pjoin
 from catalyst.base.resume import AutoResume
 
+
 class StageBase(TargetBase, ClearBase, GenBase):
 	"""
 	This class does all of the chroot setup, copying of files, etc. It is
@@ -191,7 +192,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			file_locate(self.settings,["portage_confdir"],expand=0)
 
 		""" Setup our mount points """
-		self.target_mounts = target_mounts.copy()
+		# initialize our target mounts.
+		self.target_mounts = TARGET_MOUNT_DEFAULTS.copy()
 		if "snapcache" in self.settings["options"]:
 			self.mounts=["proc", "dev", 'portdir', 'distdir', 'port_tmpdir']
 			self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
@@ -202,7 +204,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
 				"distdir":self.settings["distdir"], "port_tmpdir":"tmpfs"}
 		if os.uname()[0] == "Linux":
-			self.mounts.append("pts")
+			self.mounts.append("devpts")
 
 		self.set_mounts()
 

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 0b98d83..11cecb3 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -80,18 +80,18 @@ confdefaults={
 	}
 
 
-target_mounts = {
-	"proc": "/proc",
+TARGET_MOUNT_DEFAULTS = {
+	"ccache": "/var/tmp/ccache",
 	"dev": "/dev",
-	"pts": "/dev/pts",
-	"portdir": "/usr/portage",
+	"devpts": "/dev/pts",
 	"distdir": "/usr/portage/distfiles",
+	"icecream": "/usr/lib/icecc/bin",
+	"kerncache": "/tmp/kerncache",
 	"packagedir": "/usr/portage/packages",
+	"portdir": "/usr/portage",
 	"port_tmpdir": "/var/tmp/portage",
-	"kerncache": "/tmp/kerncache",
-	"ccache": "/var/tmp/ccache",
-	"icecream": "/var/cache/icecream",
 	"port_logdir": "/var/log/portage",
+	"proc": "/proc",
 	}
 
 # legend:  key: message


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-01-22  5:04 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-01-22  5:04 UTC (permalink / raw
  To: gentoo-commits

commit:     32dd2617139e93159abb42eb4e3028a8b3f2f48a
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 23:57:28 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Jan 22 04:30:16 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=32dd2617

catalyst/targets/generic_stage_target.py: mount /dev/shm on linux

Add shm targets defaults. Anthony G. Basile <blueness <AT> gentoo.org>
Some build systems require /dev/shm to be mounted, like python's
build system.  We make sure that on Linux systems, /dev/shm is
mounted in the stage chroots.  See bug #496328.

Douglas Freed <dwfreed <AT> mtu.edu> :
Mount /dev/shm in the chroot with the right options
Bind mounting /dev/shm into the chroot isn't a good idea, as there may
be collisions and result in weird side effects.  Instead, we can just
mount a new tmpfs there, with the right options to ensure security.

(Forward ported to 3.0 branch from 2.X Brian Dolbec)

---
 catalyst/base/stagebase.py | 6 +++++-
 catalyst/defaults.py       | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 7e09ed1..10868ee 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -209,6 +209,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			#self.mountmap["portdir"] = None
 		if os.uname()[0] == "Linux":
 			self.mounts.append("devpts")
+			self.mounts.append("shm")
 
 		self.set_mounts()
 
@@ -930,7 +931,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			ensure_dirs(target, mode=0755)
 
 			if not os.path.exists(self.mountmap[x]):
-				if not self.mountmap[x] == "tmpfs":
+				if self.mountmap[x] not in ["tmpfs", "shmfs"]:
 					ensure_dirs(self.mountmap[x], mode=0755)
 
 			src=self.mountmap[x]
@@ -951,6 +952,9 @@ class StageBase(TargetBase, ClearBase, GenBase):
 							self.settings["var_tmpfs_portage"] + "G " + \
 							src + " " + target
 						retval=os.system(cmd)
+				elif src == "shmfs":
+					cmd = "mount -t tmpfs -o noexec,nosuid,nodev shm " + target
+					retval=os.system(cmd)
 				else:
 					cmd = "mount --bind " + src + " " + target
 					#print "bind(); cmd =", cmd

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 27bcff4..1f86c1d 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -92,6 +92,7 @@ TARGET_MOUNT_DEFAULTS = {
 	"port_tmpdir": "/var/tmp/portage",
 	"port_logdir": "/var/log/portage",
 	"proc": "/proc",
+	"shm": "/dev/shm",
 	}
 
 SOURCE_MOUNT_DEFAULTS = {
@@ -101,6 +102,7 @@ SOURCE_MOUNT_DEFAULTS = {
 	"portdir": None,      # set from settings options
 	"port_tmpdir": "tmpfs",
 	"proc": "/proc",
+	"shm": "shmfs",
 	}
 
 # legend:  key: message


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2014-01-22  5:04 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2014-01-22  5:04 UTC (permalink / raw
  To: gentoo-commits

commit:     0e4b6cd843b0d6a75909b8455ab76dffa6ee6e60
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 21:19:28 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Jan  3 18:02:21 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=0e4b6cd8

Move some duplicate code to fileops, extend it's capability to not re-make the directory.

---
 catalyst/base/clearbase.py | 55 +++++++++++++---------------------------------
 catalyst/base/resume.py    | 26 +++++-----------------
 catalyst/fileops.py        | 43 +++++++++++++++++++++++++++++++++++-
 3 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/catalyst/base/clearbase.py b/catalyst/base/clearbase.py
index 50cbc35..e38b1a8 100644
--- a/catalyst/base/clearbase.py
+++ b/catalyst/base/clearbase.py
@@ -5,7 +5,7 @@ from stat import ST_UID, ST_GID, ST_MODE
 
 
 from catalyst.support import cmd, countdown
-from catalyst.fileops import ensure_dirs
+from catalyst.fileops import ensure_dirs, clear_dir
 
 class ClearBase(object):
 	"""
@@ -16,68 +16,43 @@ class ClearBase(object):
 		self.resume = None
 
 
-	def clear_autoresume(self):
+	def clear_autoresume(self, remove=False):
 		""" Clean resume points since they are no longer needed """
 		if "autoresume" in self.settings["options"]:
 			print "Removing AutoResume Points: ..."
 			self.resume.clear_all()
 
 
-	def clear_chroot(self):
+	def clear_chroot(self, remove=False):
 		print 'Clearing the chroot path ...'
-		self.clear_dir(self.settings["chroot_path"], 0755, True)
+		clear_dir(self.settings["chroot_path"], 0755, True, remove)
 
 
-	def clear_packages(self):
+	def clear_packages(self, remove=False):
 		if "pkgcache" in self.settings["options"]:
 			print "purging the pkgcache ..."
-			self.clear_dir(self.settings["pkgcache_path"])
+			clear_dir(self.settings["pkgcache_path"], remove=remove)
 
 
-	def clear_kerncache(self):
+	def clear_kerncache(self, remove=False):
 		if "kerncache" in self.settings["options"]:
 			print "purging the kerncache ..."
-			self.clear_dir(self.settings["kerncache_path"])
+			clear_dir(self.settings["kerncache_path"], remove=remove)
 
 
-	def purge(self):
+	def purge(self, remove=False):
 		countdown(10,"Purging Caches ...")
-		if any(k in self.settings["options"] for k in ("purge","purgeonly","purgetmponly")):
+		if any(k in self.settings["options"] for k in ("purge",
+				"purgeonly", "purgetmponly")):
 			print "purge(); clearing autoresume ..."
-			self.clear_autoresume()
+			self.clear_autoresume(remove)
 
 			print "purge(); clearing chroot ..."
-			self.clear_chroot()
+			self.clear_chroot(remove)
 
 			if "purgetmponly" not in self.settings["options"]:
 				print "purge(); clearing package cache ..."
-				self.clear_packages()
+				self.clear_packages(remove)
 
 			print "purge(); clearing kerncache ..."
-			self.clear_kerncache()
-
-
-	def clear_dir(self, myemp, mode=0755, chg_flags=False):
-		'''Universal directory clearing function
-		'''
-		if not myemp:
-			return False
-		if os.path.isdir(myemp):
-			print "Emptying directory" , myemp
-			"""
-			stat the dir, delete the dir, recreate the dir and set
-			the proper perms and ownership
-			"""
-			try:
-				mystat=os.stat(myemp)
-				""" There's no easy way to change flags recursively in python """
-				if chg_flags and os.uname()[0] == "FreeBSD":
-					os.system("chflags -R noschg " + myemp)
-				shutil.rmtree(myemp)
-				ensure_dirs(myemp, mode=mode)
-				os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
-				os.chmod(myemp,mystat[ST_MODE])
-			except Exception as e:
-				print CatalystError("clear_dir(); Exeption: %s" % str(e))
-				return False
-			return True
+			self.clear_kerncache(remove)

diff --git a/catalyst/base/resume.py b/catalyst/base/resume.py
index e42c7dc..cf495fc 100644
--- a/catalyst/base/resume.py
+++ b/catalyst/base/resume.py
@@ -16,7 +16,7 @@ import shutil
 from stat import ST_UID, ST_GID, ST_MODE
 import traceback
 
-from catalyst.fileops import ensure_dirs, pjoin, listdir_files
+from catalyst.fileops import ensure_dirs, pjoin, listdir_files, clear_dir
 from catalyst.support import touch
 
 
@@ -139,28 +139,12 @@ class AutoResume(object):
 		return list(self._points)
 
 
-	def clear_all(self):
+	def clear_all(self, remove=False):
 		'''Clear all active resume points
 
 		@return boolean
 		'''
-		try:
-			print "Emptying directory---", self.basedir
-			"""
-			stat the dir, delete the dir, recreate the dir and set
-			the proper perms and ownership
-			"""
-			mystat=os.stat(self.basedir)
-			if os.uname()[0] == "FreeBSD":
-				cmd("chflags -R noschg " + self.basedir,\
-					"Could not remove immutable flag for file "\
-					+ self.basedir)
-			shutil.rmtree(self.basedir)
-			ensure_dirs(self.basedir, 0755)
-			os.chown(self.basedir,mystat[ST_UID],mystat[ST_GID])
-			os.chmod(self.basedir,mystat[ST_MODE])
+		if clear_dir(self.basedir, mode=0755, chg_flags=True, remove=remove):
 			self._points = {}
-		except Exception as e:
-			print AutoResumeError(str(e))
-			return False
-		return True
+			return True
+		return False

diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index e3a4ead..245c83e 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -10,7 +10,13 @@ ensuring directories exist,... imports snakeoils osutils
 functions for use throughout catalyst.
 '''
 
-from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs, normpath,
+import os
+import shutil
+from stat import ST_UID, ST_GID, ST_MODE
+
+# NOTE: pjoin and listdir_files are imported here for export
+# to other catalyst modules
+from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs,
 	pjoin, listdir_files)
 from catalyst.support import CatalystError
 
@@ -42,3 +48,38 @@ def ensure_dirs(path, gid=-1, uid=-1, mode=0777, minimal=True,
 			raise CatalystError(
 				"Failed to create directory: %s" % path, print_traceback=True)
 	return succeeded
+
+
+def clear_dir(target, mode=0755, chg_flags=False, remove=False):
+	'''Universal directory clearing function
+	'''
+	#print "fileops.clear_dir()"
+	if not target:
+		#print "fileops.clear_dir(), no target... returning"
+		return False
+	if os.path.isdir(target):
+		print "Emptying directory" , target
+		"""
+		stat the dir, delete the dir, recreate the dir and set
+		the proper perms and ownership
+		"""
+		try:
+			#print "fileops.clear_dir(), os.stat()"
+			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)
+			#print "fileops.clear_dir(), shutil.rmtree()"
+			shutil.rmtree(target)
+			if not remove:
+				#print "fileops.clear_dir(), ensure_dirs()"
+				ensure_dirs(target, mode=mode)
+				os.chown(target, mystat[ST_UID], mystat[ST_GID])
+				os.chmod(target, mystat[ST_MODE])
+		except Exception as e:
+			print CatalystError("clear_dir(); Exeption: %s" % str(e))
+			return False
+	else:
+		print "fileops.clear_dir(), %s is not a directory" % (target)
+	#print "fileops.clear_dir(), DONE, returning True"
+	return True


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
@ 2013-12-31 10:48 Brian Dolbec
  0 siblings, 0 replies; 11+ messages in thread
From: Brian Dolbec @ 2013-12-31 10:48 UTC (permalink / raw
  To: gentoo-commits

commit:     d3f06c64221059f8eec4bec99072b9f71ea23dfe
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 21:19:28 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Tue Dec 31 10:00:18 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=d3f06c64

Move some duplicate code to fileops, extend it's capability to not re-make the directory.

---
 catalyst/base/clearbase.py | 55 +++++++++++++---------------------------------
 catalyst/base/resume.py    | 26 +++++-----------------
 catalyst/fileops.py        | 43 +++++++++++++++++++++++++++++++++++-
 3 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/catalyst/base/clearbase.py b/catalyst/base/clearbase.py
index 50cbc35..e38b1a8 100644
--- a/catalyst/base/clearbase.py
+++ b/catalyst/base/clearbase.py
@@ -5,7 +5,7 @@ from stat import ST_UID, ST_GID, ST_MODE
 
 
 from catalyst.support import cmd, countdown
-from catalyst.fileops import ensure_dirs
+from catalyst.fileops import ensure_dirs, clear_dir
 
 class ClearBase(object):
 	"""
@@ -16,68 +16,43 @@ class ClearBase(object):
 		self.resume = None
 
 
-	def clear_autoresume(self):
+	def clear_autoresume(self, remove=False):
 		""" Clean resume points since they are no longer needed """
 		if "autoresume" in self.settings["options"]:
 			print "Removing AutoResume Points: ..."
 			self.resume.clear_all()
 
 
-	def clear_chroot(self):
+	def clear_chroot(self, remove=False):
 		print 'Clearing the chroot path ...'
-		self.clear_dir(self.settings["chroot_path"], 0755, True)
+		clear_dir(self.settings["chroot_path"], 0755, True, remove)
 
 
-	def clear_packages(self):
+	def clear_packages(self, remove=False):
 		if "pkgcache" in self.settings["options"]:
 			print "purging the pkgcache ..."
-			self.clear_dir(self.settings["pkgcache_path"])
+			clear_dir(self.settings["pkgcache_path"], remove=remove)
 
 
-	def clear_kerncache(self):
+	def clear_kerncache(self, remove=False):
 		if "kerncache" in self.settings["options"]:
 			print "purging the kerncache ..."
-			self.clear_dir(self.settings["kerncache_path"])
+			clear_dir(self.settings["kerncache_path"], remove=remove)
 
 
-	def purge(self):
+	def purge(self, remove=False):
 		countdown(10,"Purging Caches ...")
-		if any(k in self.settings["options"] for k in ("purge","purgeonly","purgetmponly")):
+		if any(k in self.settings["options"] for k in ("purge",
+				"purgeonly", "purgetmponly")):
 			print "purge(); clearing autoresume ..."
-			self.clear_autoresume()
+			self.clear_autoresume(remove)
 
 			print "purge(); clearing chroot ..."
-			self.clear_chroot()
+			self.clear_chroot(remove)
 
 			if "purgetmponly" not in self.settings["options"]:
 				print "purge(); clearing package cache ..."
-				self.clear_packages()
+				self.clear_packages(remove)
 
 			print "purge(); clearing kerncache ..."
-			self.clear_kerncache()
-
-
-	def clear_dir(self, myemp, mode=0755, chg_flags=False):
-		'''Universal directory clearing function
-		'''
-		if not myemp:
-			return False
-		if os.path.isdir(myemp):
-			print "Emptying directory" , myemp
-			"""
-			stat the dir, delete the dir, recreate the dir and set
-			the proper perms and ownership
-			"""
-			try:
-				mystat=os.stat(myemp)
-				""" There's no easy way to change flags recursively in python """
-				if chg_flags and os.uname()[0] == "FreeBSD":
-					os.system("chflags -R noschg " + myemp)
-				shutil.rmtree(myemp)
-				ensure_dirs(myemp, mode=mode)
-				os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
-				os.chmod(myemp,mystat[ST_MODE])
-			except Exception as e:
-				print CatalystError("clear_dir(); Exeption: %s" % str(e))
-				return False
-			return True
+			self.clear_kerncache(remove)

diff --git a/catalyst/base/resume.py b/catalyst/base/resume.py
index e42c7dc..cf495fc 100644
--- a/catalyst/base/resume.py
+++ b/catalyst/base/resume.py
@@ -16,7 +16,7 @@ import shutil
 from stat import ST_UID, ST_GID, ST_MODE
 import traceback
 
-from catalyst.fileops import ensure_dirs, pjoin, listdir_files
+from catalyst.fileops import ensure_dirs, pjoin, listdir_files, clear_dir
 from catalyst.support import touch
 
 
@@ -139,28 +139,12 @@ class AutoResume(object):
 		return list(self._points)
 
 
-	def clear_all(self):
+	def clear_all(self, remove=False):
 		'''Clear all active resume points
 
 		@return boolean
 		'''
-		try:
-			print "Emptying directory---", self.basedir
-			"""
-			stat the dir, delete the dir, recreate the dir and set
-			the proper perms and ownership
-			"""
-			mystat=os.stat(self.basedir)
-			if os.uname()[0] == "FreeBSD":
-				cmd("chflags -R noschg " + self.basedir,\
-					"Could not remove immutable flag for file "\
-					+ self.basedir)
-			shutil.rmtree(self.basedir)
-			ensure_dirs(self.basedir, 0755)
-			os.chown(self.basedir,mystat[ST_UID],mystat[ST_GID])
-			os.chmod(self.basedir,mystat[ST_MODE])
+		if clear_dir(self.basedir, mode=0755, chg_flags=True, remove=remove):
 			self._points = {}
-		except Exception as e:
-			print AutoResumeError(str(e))
-			return False
-		return True
+			return True
+		return False

diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index e3a4ead..245c83e 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -10,7 +10,13 @@ ensuring directories exist,... imports snakeoils osutils
 functions for use throughout catalyst.
 '''
 
-from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs, normpath,
+import os
+import shutil
+from stat import ST_UID, ST_GID, ST_MODE
+
+# NOTE: pjoin and listdir_files are imported here for export
+# to other catalyst modules
+from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs,
 	pjoin, listdir_files)
 from catalyst.support import CatalystError
 
@@ -42,3 +48,38 @@ def ensure_dirs(path, gid=-1, uid=-1, mode=0777, minimal=True,
 			raise CatalystError(
 				"Failed to create directory: %s" % path, print_traceback=True)
 	return succeeded
+
+
+def clear_dir(target, mode=0755, chg_flags=False, remove=False):
+	'''Universal directory clearing function
+	'''
+	#print "fileops.clear_dir()"
+	if not target:
+		#print "fileops.clear_dir(), no target... returning"
+		return False
+	if os.path.isdir(target):
+		print "Emptying directory" , target
+		"""
+		stat the dir, delete the dir, recreate the dir and set
+		the proper perms and ownership
+		"""
+		try:
+			#print "fileops.clear_dir(), os.stat()"
+			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)
+			#print "fileops.clear_dir(), shutil.rmtree()"
+			shutil.rmtree(target)
+			if not remove:
+				#print "fileops.clear_dir(), ensure_dirs()"
+				ensure_dirs(target, mode=mode)
+				os.chown(target, mystat[ST_UID], mystat[ST_GID])
+				os.chmod(target, mystat[ST_MODE])
+		except Exception as e:
+			print CatalystError("clear_dir(); Exeption: %s" % str(e))
+			return False
+	else:
+		print "fileops.clear_dir(), %s is not a directory" % (target)
+	#print "fileops.clear_dir(), DONE, returning True"
+	return True


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

end of thread, other threads:[~2014-04-18 16:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-22  5:04 [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/ Brian Dolbec
  -- strict thread matches above, loose matches on Subject: below --
2014-04-18 16:52 Brian Dolbec
2014-04-18 16:52 Brian Dolbec
2014-04-18 16:52 Brian Dolbec
2014-04-18 16:52 Brian Dolbec
2014-01-22  5:04 Brian Dolbec
2014-01-22  5:04 Brian Dolbec
2014-01-22  5:04 Brian Dolbec
2014-01-22  5:04 Brian Dolbec
2014-01-22  5:04 Brian Dolbec
2013-12-31 10:48 Brian Dolbec

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