Gentoo Archives: gentoo-catalyst

From: Brian Dolbec <dolsen@g.o>
To: gentoo-catalyst@l.g.o
Cc: Brian Dolbec <dolsen@g.o>
Subject: [gentoo-catalyst] [PATCH 2/4] Remove self.mounts and self.mountmap's use of paths for keys and paths.
Date: Sat, 14 Dec 2013 03:07:55
Message-Id: 1386990436-9198-3-git-send-email-dolsen@gentoo.org
In Reply to: [gentoo-catalyst] rewrite-on-master patches by Brian Dolbec
1 Migrate more hardcoded paths to use settings variables instead.
2 ---
3 catalyst | 3 ++
4 modules/generic_stage_target.py | 80 ++++++++++++++++++++---------------------
5 2 files changed, 43 insertions(+), 40 deletions(-)
6
7 diff --git a/catalyst b/catalyst
8 index 19ec77e..60cea3e 100755
9 --- a/catalyst
10 +++ b/catalyst
11 @@ -62,8 +62,11 @@ def parse_config(myconfig):
12 config_file=""
13
14 confdefaults={
15 + "distdir": "/usr/portage/distfiles",
16 "hash_function": "crc32",
17 + "packagedir": "/usr/portage/packages",
18 "portdir": "/usr/portage",
19 + "port_tmpdir": "/var/tmp/portage",
20 "repo_name": "portage",
21 "sharedir": "/usr/lib/catalyst",
22 "snapshot_name": "portage-",
23 diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py
24 index c2888b6..342c65b 100644
25 --- a/modules/generic_stage_target.py
26 +++ b/modules/generic_stage_target.py
27 @@ -179,11 +179,11 @@ class generic_stage_target(generic_target):
28 "/usr/portage":self.settings["snapshot_cache_path"]+"/portage",\
29 "/usr/portage/distfiles":self.settings["distdir"],"/var/tmp/portage":"tmpfs"}
30 else:
31 - self.mounts=["/proc","/dev","/usr/portage/distfiles","/var/tmp/portage"]
32 - self.mountmap={"/proc":"/proc","/dev":"/dev","/dev/pts":"/dev/pts",\
33 - "/usr/portage/distfiles":self.settings["distdir"],"/var/tmp/portage":"tmpfs"}
34 + self.mounts=["proc","dev", "distdir", "port_tmpdir"]
35 + self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
36 + "distdir":self.settings["distdir"], "port_tmpdir":"tmpfs"}
37 if os.uname()[0] == "Linux":
38 - self.mounts.append("/dev/pts")
39 + self.mounts.append("pts")
40
41 self.set_mounts()
42
43 @@ -195,16 +195,15 @@ class generic_stage_target(generic_target):
44 self.set_pkgcache_path()
45 print "Location of the package cache is "+\
46 self.settings["pkgcache_path"]
47 - self.mounts.append("/usr/portage/packages")
48 - self.mountmap["/usr/portage/packages"]=\
49 - self.settings["pkgcache_path"]
50 + self.mounts.append("packagedir")
51 + self.mountmap["packagedir"] = self.settings["pkgcache_path"]
52
53 if "KERNCACHE" in self.settings:
54 self.set_kerncache_path()
55 print "Location of the kerncache is "+\
56 self.settings["kerncache_path"]
57 - self.mounts.append("/tmp/kerncache")
58 - self.mountmap["/tmp/kerncache"]=self.settings["kerncache_path"]
59 + self.mounts.append("kerncache")
60 + self.mountmap["kerncache"]=self.settings["kerncache_path"]
61
62 if "CCACHE" in self.settings:
63 if "CCACHE_DIR" in os.environ:
64 @@ -216,8 +215,8 @@ class generic_stage_target(generic_target):
65 raise CatalystError,\
66 "Compiler cache support can't be enabled (can't find "+\
67 ccdir+")"
68 - self.mounts.append("/var/tmp/ccache")
69 - self.mountmap["/var/tmp/ccache"]=ccdir
70 + self.mounts.append("ccache")
71 + self.mountmap["ccache"]=ccdir
72 """ for the chroot: """
73 self.env["CCACHE_DIR"]="/var/tmp/ccache"
74
75 @@ -406,7 +405,7 @@ class generic_stage_target(generic_target):
76
77 def set_cleanables(self):
78 self.settings["cleanables"]=["/etc/resolv.conf","/var/tmp/*","/tmp/*",\
79 - "/root/*","/usr/portage"]
80 + "/root/*", self.settings["portdir"]]
81
82 def set_snapshot_path(self):
83 self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
84 @@ -615,21 +614,21 @@ class generic_stage_target(generic_target):
85 return
86
87 for x in self.mounts:
88 - if not os.path.exists(mypath+x):
89 + if not os.path.exists(mypath + self.mountmap[x]):
90 continue
91
92 - if ismount(mypath+x):
93 + if ismount(mypath +self.mountmap[x]):
94 """ Something is still mounted "" """
95 try:
96 - print x+" is still mounted; performing auto-bind-umount...",
97 + print self.mountmap[x] + " is still mounted; performing auto-bind-umount...",
98 """ Try to umount stuff ourselves """
99 self.unbind()
100 - if ismount(mypath+x):
101 - raise CatalystError, "Auto-unbind failed for "+x
102 + if ismount(mypath + self.mountmap[x]):
103 + raise CatalystError, "Auto-unbind failed for " + self.mountmap[x]
104 else:
105 print "Auto-unbind successful..."
106 except CatalystError:
107 - raise CatalystError, "Unable to auto-unbind "+x
108 + raise CatalystError, "Unable to auto-unbind " + self.mountmap[x]
109
110 def unpack(self):
111 unpack=True
112 @@ -787,7 +786,7 @@ class generic_stage_target(generic_target):
113 print "Valid snapshot cache, skipping unpack of portage tree..."
114 unpack=False
115 else:
116 - destdir=normpath(self.settings["chroot_path"]+"/usr/portage")
117 + destdir=normpath(self.settings["chroot_path"] + self.settings["portdir"])
118 cleanup_errmsg="Error removing existing snapshot directory."
119 cleanup_msg=\
120 "Cleaning up existing portage tree (This can take a long time)..."
121 @@ -801,7 +800,7 @@ class generic_stage_target(generic_target):
122
123 if "AUTORESUME" in self.settings \
124 and os.path.exists(self.settings["chroot_path"]+\
125 - "/usr/portage/") \
126 + self.settings["portdir"]) \
127 and os.path.exists(self.settings["autoresume_path"]\
128 +"unpack_portage") \
129 and self.settings["snapshot_path_hash"] == snapshot_hash:
130 @@ -848,7 +847,7 @@ class generic_stage_target(generic_target):
131 cmd("rm -f "+self.settings["chroot_path"]+"/etc/portage/make.profile",\
132 "Error zapping profile link",env=self.env)
133 cmd("mkdir -p "+self.settings["chroot_path"]+"/etc/portage/")
134 - cmd("ln -sf ../../usr/portage/profiles/"+\
135 + cmd("ln -sf ../.." + self.settings["portdir"] + "/profiles/"+\
136 self.settings["target_profile"]+" "+\
137 self.settings["chroot_path"]+"/etc/portage/make.profile",\
138 "Error creating profile link",env=self.env)
139 @@ -874,10 +873,10 @@ class generic_stage_target(generic_target):
140 if os.path.exists(x):
141 print "Copying overlay dir " +x
142 cmd("mkdir -p "+self.settings["chroot_path"]+\
143 - "/usr/local/portage",\
144 + self.settings["local_overlay"],\
145 "Could not make portage_overlay dir",env=self.env)
146 cmd("cp -R "+x+"/* "+self.settings["chroot_path"]+\
147 - "/usr/local/portage",\
148 + self.settings["local_overlay"],\
149 "Could not copy portage_overlay",env=self.env)
150
151 def root_overlay(self):
152 @@ -897,7 +896,7 @@ class generic_stage_target(generic_target):
153
154 def bind(self):
155 for x in self.mounts:
156 - if not os.path.exists(self.settings["chroot_path"]+x):
157 + if not os.path.exists(self.settings["chroot_path"] + self.mountmap[x]):
158 os.makedirs(self.settings["chroot_path"]+x,0755)
159
160 if not os.path.exists(self.mountmap[x]):
161 @@ -909,11 +908,11 @@ class generic_stage_target(generic_target):
162 self.snapshot_lock_object.read_lock()
163 if os.uname()[0] == "FreeBSD":
164 if src == "/dev":
165 - retval=os.system("mount -t devfs none "+\
166 - self.settings["chroot_path"]+x)
167 + retval=os.system("mount -t devfs none " +
168 + self.settings["chroot_path"] + src)
169 else:
170 - retval=os.system("mount_nullfs "+src+" "+\
171 - self.settings["chroot_path"]+x)
172 + retval=os.system("mount_nullfs " + src + " " +
173 + self.settings["chroot_path"] + src)
174 else:
175 if src == "tmpfs":
176 if "var_tmpfs_portage" in self.settings:
177 @@ -921,11 +920,11 @@ class generic_stage_target(generic_target):
178 self.settings["var_tmpfs_portage"]+"G "+src+" "+\
179 self.settings["chroot_path"]+x)
180 else:
181 - retval=os.system("mount --bind "+src+" "+\
182 - self.settings["chroot_path"]+x)
183 + retval=os.system("mount --bind " + src + " " +
184 + self.settings["chroot_path"] + src)
185 if retval!=0:
186 self.unbind()
187 - raise CatalystError,"Couldn't bind mount "+src
188 + raise CatalystError,"Couldn't bind mount " + src
189
190 def unbind(self):
191 ouch=0
192 @@ -934,25 +933,26 @@ class generic_stage_target(generic_target):
193 myrevmounts.reverse()
194 """ Unmount in reverse order for nested bind-mounts """
195 for x in myrevmounts:
196 - if not os.path.exists(mypath+x):
197 + if not os.path.exists(mypath + self.mountmap[x]):
198 continue
199
200 - if not ismount(mypath+x):
201 + if not ismount(mypath + self.mountmap[x]):
202 continue
203
204 retval=os.system("umount "+\
205 - os.path.join(mypath,x.lstrip(os.path.sep)))
206 + os.path.join(mypath, self.mountmap[x].lstrip(os.path.sep)))
207
208 if retval!=0:
209 - warn("First attempt to unmount: "+mypath+x+" failed.")
210 + warn("First attempt to unmount: " + mypath +
211 + self.mountmap[x] +" failed.")
212 warn("Killing any pids still running in the chroot")
213
214 self.kill_chroot_pids()
215
216 - retval2=os.system("umount "+mypath+x)
217 + retval2=os.system("umount " + mypath + self.mountmap[x])
218 if retval2!=0:
219 ouch=1
220 - warn("Couldn't umount bind mount: "+mypath+x)
221 + warn("Couldn't umount bind mount: " + mypath + self.mountmap[x])
222
223 if "SNAPCACHE" in self.settings and x == "/usr/portage":
224 try:
225 @@ -1118,9 +1118,9 @@ class generic_stage_target(generic_target):
226 "Could not replace /etc/hosts",env=self.env)
227
228 """ Remove our overlay """
229 - if os.path.exists(self.settings["chroot_path"]+"/usr/local/portage"):
230 - cmd("rm -rf "+self.settings["chroot_path"]+"/usr/local/portage",\
231 - "Could not remove /usr/local/portage",env=self.env)
232 + if os.path.exists(self.settings["chroot_path"] + self.settings["local_overlay"]):
233 + cmd("rm -rf " + self.settings["chroot_path"] + self.settings["local_overlay"],
234 + "Could not remove " + self.settings["local_overlay"], env=self.env)
235 cmd("sed -i '/^PORTDIR_OVERLAY/d' "+self.settings["chroot_path"]+\
236 "/etc/portage/make.conf",\
237 "Could not remove PORTDIR_OVERLAY from make.conf",env=self.env)
238 --
239 1.8.3.2

Replies