Skip to content

Commit 9fcd99e

Browse files
authored
Merge pull request nicolasbock#108 from linxon/tmpbr1
get a real name from the current profiles/repo_name file
2 parents 0b4df65 + 9d7f1e5 commit 9fcd99e

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

ebuildtester/docker.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import os
2+
import re
3+
import sys
4+
import subprocess
5+
16
import ebuildtester.options as options
27
from ebuildtester.utils import massage_string
38

@@ -11,20 +16,18 @@ class Docker:
1116
def __init__(self, local_portage, overlay_dirs):
1217
"""Create a new container."""
1318

14-
import os.path
15-
1619
docker_image = "gentoo/stage3-amd64"
17-
overlay_dirs = list(set(overlay_dirs))
18-
overlay_mountpoints = [os.path.join("/var/lib/overlays", p)
19-
for p in map(os.path.basename, overlay_dirs)]
20+
repo_names = self._get_repo_names(overlay_dirs)
21+
overlay_mountpoints = [os.path.join("/var/lib/overlays", r)
22+
for r in repo_names]
2023

2124
self._setup_container(docker_image)
2225
self._create_container(docker_image, local_portage,
2326
zip(overlay_dirs, overlay_mountpoints))
2427
self._start_container()
2528
self._set_profile()
2629
self._tweak_settings()
27-
self._enable_overlays(map(os.path.basename, overlay_dirs))
30+
self._enable_overlays(repo_names)
2831
self._enable_test()
2932
self._unmask_atom()
3033
self._unmask()
@@ -40,10 +43,6 @@ def execute(self, cmd):
4043
cmd is a string which is executed within a bash shell.
4144
"""
4245

43-
import os
44-
import subprocess
45-
import sys
46-
4746
options.log.info("%s %s" % (self.cid[:6], cmd))
4847
docker_cmd = ["docker", "exec", "--interactive"]
4948
docker_cmd += [self.cid, "/bin/bash"]
@@ -94,8 +93,6 @@ def execute(self, cmd):
9493
def shell(self):
9594
"""Run an interactive shell in container."""
9695

97-
import subprocess
98-
9996
options.log.info("running interactive shell in container")
10097
docker = subprocess.Popen(["docker", "exec", "--tty", "--interactive",
10198
self.cid, "/bin/bash"])
@@ -113,8 +110,6 @@ def cleanup(self):
113110
def remove(self):
114111
"""Remove the docker container."""
115112

116-
import subprocess
117-
118113
options.log.info("stopping container")
119114
docker = subprocess.Popen(["docker", "kill", self.cid])
120115
docker.wait()
@@ -137,17 +132,13 @@ def _setup_container(self, docker_image):
137132
"""Setup the container."""
138133

139134
if options.options.pull:
140-
import subprocess
141-
142135
docker_args = ["docker", "pull", docker_image]
143136
docker = subprocess.Popen(docker_args)
144137
docker.wait()
145138

146139
def _create_container(self, docker_image, local_portage, overlays):
147140
"""Create new container."""
148141

149-
import subprocess
150-
151142
docker_args = [
152143
"docker", "create",
153144
"--tty",
@@ -183,8 +174,6 @@ def _create_container(self, docker_image, local_portage, overlays):
183174
def _start_container(self):
184175
"""Start the container."""
185176

186-
import subprocess
187-
188177
docker_args = ["docker", "start", "%s" % self.cid]
189178
docker = subprocess.Popen(docker_args, stdout=subprocess.PIPE)
190179
docker.wait()
@@ -216,17 +205,27 @@ def _tweak_settings(self):
216205
if options.options.with_X:
217206
self.execute("echo USE=\\\"X\\\" >> /etc/portage/make.conf")
218207

219-
def _enable_overlays(self, overlays):
208+
def _get_repo_names(self, overlay_dirs):
209+
"""Get repo names from local overlay settings."""
210+
211+
repo_names = []
212+
for o in overlay_dirs:
213+
with open(os.path.join(o, "profiles/repo_name"), "r") as f:
214+
for repo_name in f:
215+
repo_names.append(repo_name.replace("\n", ""))
216+
217+
return repo_names
218+
219+
def _enable_overlays(self, repo_names):
220220
"""Enable overlays."""
221221

222-
self.execute("mkdir -p /etc/portage/repos.conf")
223-
for o in overlays:
224-
self.execute("echo \"[%s]\" >> "
225-
"/etc/portage/repos.conf/overlays.conf" % o)
226-
self.execute("echo \"location = /var/lib/overlays/%s\" >> "
227-
"/etc/portage/repos.conf/overlays.conf" % o)
228-
self.execute("echo \"master = gentoo\" >> "
229-
"/etc/portage/repos.conf/overlays.conf")
222+
for r in repo_names:
223+
self.execute(
224+
"mkdir -p /etc/portage/repos.conf && " +
225+
"echo -e \"[%s]\\n" % str(r) +
226+
"location = /var/lib/overlays/%s\\n" % str(r) +
227+
"master = gentoo\" >> /etc/portage/repos.conf/overlays.conf"
228+
)
230229

231230
def _enable_test(self):
232231
"""Enable test FEATURES for ATOM."""
@@ -308,8 +307,6 @@ def _enable_global_use(self):
308307
def _set_gcc(self):
309308
"""Set gcc in the container."""
310309

311-
import re
312-
313310
options.log.info("setting gcc")
314311
if options.options.gcc_version:
315312
self.execute("mkdir -p /etc/portage/package.accept_keywords")

0 commit comments

Comments
 (0)