Gentoo Archives: gentoo-catalyst

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

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies