Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/grss:master commit in: grs/
Date: Tue, 07 Jul 2015 02:17:44
Message-Id: 1436235599.3db7628eb5a3c05e0b11d346b2f8dad4da56136a.blueness@gentoo
1 commit: 3db7628eb5a3c05e0b11d346b2f8dad4da56136a
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Tue Jul 7 02:19:59 2015 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Tue Jul 7 02:19:59 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=3db7628e
7
8 grs/PivotChroot.py: introduce 'pivot' directive.
9
10 grs/Interpret.py | 6 ++++++
11 grs/PivotChroot.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
12 2 files changed, 64 insertions(+)
13
14 diff --git a/grs/Interpret.py b/grs/Interpret.py
15 index 6525c9e..8b1166b 100644
16 --- a/grs/Interpret.py
17 +++ b/grs/Interpret.py
18 @@ -87,6 +87,7 @@ class Interpret(Daemon):
19 md = MountDirectories(portage_configroot, package, logfile)
20 po = Populate(nameserver, libdir, workdir, portage_configroot, logfile)
21 ru = RunScript(libdir, portage_configroot, logfile)
22 + pc = PivotChroot(tmdpir, portage_configroot, logfile)
23 ke = Kernel(libdir, portage_configroot, kernelroot, package, logfile)
24 bi = TarIt(name, portage_configroot, logfile)
25
26 @@ -170,6 +171,11 @@ class Interpret(Daemon):
27 stampit(progress)
28 continue
29 ru.runscript(obj)
30 + elif verb == 'pivot':
31 + if smartlog(l, obj):
32 + stampit(progress)
33 + continue
34 + pc.pivot(obj, md)
35 elif verb == 'clean':
36 if smartlog(l, obj, False):
37 stampit(progress)
38
39 diff --git a/grs/PivotChroot.py b/grs/PivotChroot.py
40 new file mode 100644
41 index 0000000..3392559
42 --- /dev/null
43 +++ b/grs/PivotChroot.py
44 @@ -0,0 +1,58 @@
45 +#!/usr/bin/env python
46 +
47 +import glob
48 +import re
49 +import os
50 +import shutil
51 +
52 +from grs.Constants import CONST
53 +from grs.MountDirectories import MountDirectories
54 +
55 +
56 +class PivotChroot():
57 + """ doc here
58 + more doc
59 + """
60 +
61 + def __init__(self, tmpdir = CONST.TMPDIR, portage_configroot = CONST.PORTAGE_CONFIGROOT, \
62 + logfile = CONST.LOGFILE):
63 + """ doc here
64 + more doc
65 + """
66 + self.tmpdir = tmpdir
67 + self.portage_configroot = portage_configroot
68 + self.logfile = logfile
69 +
70 +
71 + def pivot(self, subchroot, md):
72 + """ doc here
73 + more doc
74 + """
75 + some_mounted, all_mounted = md.are_mounted()
76 + if some_mounted:
77 + md.umount_all()
78 +
79 + # TODO: we need to move this code into its own class and inherit
80 + # Rotate any previous portage_configroots out of the way
81 + dirs = glob.glob('%s.*' % self.portage_configroot)
82 + indexed_dir = {}
83 + for d in dirs:
84 + m = re.search('^.+\.(\d+)$', d)
85 + indexed_dir[int(m.group(1))] = d
86 + count = list(indexed_dir.keys())
87 + count.sort()
88 + count.reverse()
89 + for c in count:
90 + current_dir = indexed_dir[c]
91 + m = re.search('^(.+)\.\d+$', current_dir)
92 + next_dir = '%s.%d' % (m.group(1), c+1)
93 + shutil.move(current_dir, next_dir)
94 + # If there is a directory, then move it to %s.0
95 + if os.path.isdir(self.portage_configroot):
96 + shutil.move(self.portage_configroot, '%s.0' % self.portage_configroot)
97 +
98 + inner_chroot = os.path.join(self.portage_configroot, subdir)
99 + shutil.move(inner_chroot, os.path.join(self.tmpdir, 'system'))
100 +
101 + if all_mounted:
102 + md.mount_all()