commit: abf559d73cbb0a2e0e1092bf1d029ff8fe4ae21c
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 14 21:47:37 2015 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Tue Jul 14 21:47:37 2015 +0000
URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=abf559d7
grs/MountDirectories.py: add documentation.
grs/MountDirectories.py | 51 +++++++++++++++++++++++++++----------------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/grs/MountDirectories.py b/grs/MountDirectories.py
index 737daf0..c55c2ca 100644
--- a/grs/MountDirectories.py
+++ b/grs/MountDirectories.py
@@ -6,15 +6,13 @@ from grs.Constants import CONST
from grs.Execute import Execute
class MountDirectories():
- """ doc here
- more doc
+ """ This controls the mounting/unmounting of directories under the system's
+ portage configroot.
"""
- def __init__(self, portage_configroot = CONST.PORTAGE_CONFIGROOT, package
= CONST.PACKAGE, logfile = CONST.LOGFILE):
- """ doc here
- more doc
- """
- # The order is respected
+ def __init__(self, portage_configroot = CONST.PORTAGE_CONFIGROOT, \
+ package = CONST.PACKAGE, logfile = CONST.LOGFILE):
+ # The order is respected. Note that 'dev' needs to be mounted beore
'dev/pts'.
self.directories = [
'dev',
'dev/pts',
@@ -24,7 +22,7 @@ class MountDirectories():
'usr/portage',
[ package, 'usr/portage/packages' ]
]
- # Once initiated, we'll only work with one portage_configroot
+ # Once initiated, we only work with one portage_configroot
self.portage_configroot = portage_configroot
self.package = package
self.logfile = logfile
@@ -32,21 +30,22 @@ class MountDirectories():
self.rev_directories = deepcopy(self.directories)
self.rev_directories.reverse()
+
def ismounted(self, mountpoint):
- # Obtain all the current mountpoints. os.path.ismount() fails for for
bind mounts,
- # so we obtain them all ourselves
+ """ Obtain all the current mountpoints. Since python's
os.path.ismount()
+ fails for for bind mounts, we obtain these ourselves from
/proc/mounts.
+ """
mountpoints = []
for line in open('/proc/mounts', 'r').readlines():
mountpoints.append(line.split()[1])
- # Let's make sure mountoint is canonical real path, no sym links,
- # since that's what /proc/mounts reports.
+ # Let's make sure mountoint is canonical real path, no sym links,
since that's
+ # what /proc/mounts reports. Otherwise we can get a false negative on
matching.
mountpoint = os.path.realpath(mountpoint)
return mountpoint in mountpoints
+
def are_mounted(self):
- """ doc here
- more doc
- """
+ """ Return whether some or all of the self.directories[] are mounted.
"""
some_mounted = False
all_mounted = True
for mount in self.directories:
@@ -66,34 +65,38 @@ class MountDirectories():
def mount_all(self):
- """ doc here
- more doc
- """
- # If any our mounted, let's first unmount all, then mount all
+ """ Mount all the self.directories[] under the system's portage
configroot. """
+ # If any are mounted, let's first unmount all, then mount all
some_mounted, all_mounted = self.are_mounted()
if some_mounted:
self.umount_all()
-
+ # Now go through each of the self.directories[] to be mounted in order.
for mount in self.directories:
if isinstance(mount, str):
- # Here source_directory is assumed to exist relative to /
+ # In this case, the source_directory is assumed to exist
relative to /
+ # and we will just bind mount it in the system's portage
configroot.
source_directory = mount
target_directory = mount
elif isinstance(mount, list):
- # Here source_directory is assumed to be an abspath
- # and we create it if it doesn't exist
+ # In this case, the source_directory is assumed to be an
abspath, and
+ # we create it if it doesn't already exist.
source_directory = mount[0]
os.makedirs(source_directory, mode=0o755, exist_ok=True)
target_directory = mount[1]
elif isinstance(mount, dict):
+ # In this case, we are given the mountpoint, type and name,
+ # so we just go right ahead and mount -t type name mountpoint.
+ # This is useful for tmpfs filesystems.
tmp = list(mount.values())
tmp = tmp[0]
vfstype = tmp[0]
vfsname = tmp[1]
tmp = list(mount.keys())
target_directory = tmp[0]
+ # Let's make sure the target_directory exists.
target_directory = os.path.join(self.portage_configroot,
target_directory)
os.makedirs(target_directory, mode=0o755, exist_ok=True)
+ # Okay now we're ready to do the actual mounting.
if isinstance(mount, str):
cmd = 'mount --bind /%s %s' % (source_directory,
target_directory)
elif isinstance(mount, list):
@@ -104,6 +107,8 @@ class MountDirectories():
def umount_all(self):
+ """ Unmount all the self.directories[]. """
+ # We must unmount in the opposite order that we mounted.
for mount in self.rev_directories:
if isinstance(mount, str):
target_directory = mount