From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 39981138D19 for ; Tue, 14 Jul 2015 21:45:32 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C9300E0876; Tue, 14 Jul 2015 21:45:29 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 57803E0876 for ; Tue, 14 Jul 2015 21:45:29 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 65D7D340A15 for ; Tue, 14 Jul 2015 21:45:28 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id DB2D374B for ; Tue, 14 Jul 2015 21:45:26 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1436910457.abf559d73cbb0a2e0e1092bf1d029ff8fe4ae21c.blueness@gentoo> Subject: [gentoo-commits] proj/grss:master commit in: grs/ X-VCS-Repository: proj/grss X-VCS-Files: grs/MountDirectories.py X-VCS-Directories: grs/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: abf559d73cbb0a2e0e1092bf1d029ff8fe4ae21c X-VCS-Branch: master Date: Tue, 14 Jul 2015 21:45:26 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: c70e6ba3-3080-4c2c-bb41-610f5c92121c X-Archives-Hash: 4c22fea34ab8848d3acdaa3a10ebe9ec commit: abf559d73cbb0a2e0e1092bf1d029ff8fe4ae21c Author: Anthony G. Basile gentoo org> AuthorDate: Tue Jul 14 21:47:37 2015 +0000 Commit: Anthony G. Basile gentoo 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