commit: 3db7628eb5a3c05e0b11d346b2f8dad4da56136a
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 7 02:19:59 2015 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Tue Jul 7 02:19:59 2015 +0000
URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=3db7628e
grs/PivotChroot.py: introduce 'pivot' directive.
grs/Interpret.py | 6 ++++++
grs/PivotChroot.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/grs/Interpret.py b/grs/Interpret.py
index 6525c9e..8b1166b 100644
--- a/grs/Interpret.py
+++ b/grs/Interpret.py
@@ -87,6 +87,7 @@ class Interpret(Daemon):
md = MountDirectories(portage_configroot, package, logfile)
po = Populate(nameserver, libdir, workdir, portage_configroot, logfile)
ru = RunScript(libdir, portage_configroot, logfile)
+ pc = PivotChroot(tmdpir, portage_configroot, logfile)
ke = Kernel(libdir, portage_configroot, kernelroot, package, logfile)
bi = TarIt(name, portage_configroot, logfile)
@@ -170,6 +171,11 @@ class Interpret(Daemon):
stampit(progress)
continue
ru.runscript(obj)
+ elif verb == 'pivot':
+ if smartlog(l, obj):
+ stampit(progress)
+ continue
+ pc.pivot(obj, md)
elif verb == 'clean':
if smartlog(l, obj, False):
stampit(progress)
diff --git a/grs/PivotChroot.py b/grs/PivotChroot.py
new file mode 100644
index 0000000..3392559
--- /dev/null
+++ b/grs/PivotChroot.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+
+import glob
+import re
+import os
+import shutil
+
+from grs.Constants import CONST
+from grs.MountDirectories import MountDirectories
+
+
+class PivotChroot():
+ """ doc here
+ more doc
+ """
+
+ def __init__(self, tmpdir = CONST.TMPDIR, portage_configroot =
CONST.PORTAGE_CONFIGROOT, \
+ logfile = CONST.LOGFILE):
+ """ doc here
+ more doc
+ """
+ self.tmpdir = tmpdir
+ self.portage_configroot = portage_configroot
+ self.logfile = logfile
+
+
+ def pivot(self, subchroot, md):
+ """ doc here
+ more doc
+ """
+ some_mounted, all_mounted = md.are_mounted()
+ if some_mounted:
+ md.umount_all()
+
+ # TODO: we need to move this code into its own class and inherit
+ # Rotate any previous portage_configroots out of the way
+ dirs = glob.glob('%s.*' % self.portage_configroot)
+ indexed_dir = {}
+ for d in dirs:
+ m = re.search('^.+\.(\d+)$', d)
+ indexed_dir[int(m.group(1))] = d
+ count = list(indexed_dir.keys())
+ count.sort()
+ count.reverse()
+ for c in count:
+ current_dir = indexed_dir[c]
+ m = re.search('^(.+)\.\d+$', current_dir)
+ next_dir = '%s.%d' % (m.group(1), c+1)
+ shutil.move(current_dir, next_dir)
+ # If there is a directory, then move it to %s.0
+ if os.path.isdir(self.portage_configroot):
+ shutil.move(self.portage_configroot, '%s.0' %
self.portage_configroot)
+
+ inner_chroot = os.path.join(self.portage_configroot, subdir)
+ shutil.move(inner_chroot, os.path.join(self.tmpdir, 'system'))
+
+ if all_mounted:
+ md.mount_all()