1
+ import os
2
+ import re
3
+ import sys
4
+ import subprocess
5
+
1
6
import ebuildtester .options as options
2
7
from ebuildtester .utils import massage_string
3
8
@@ -11,20 +16,18 @@ class Docker:
11
16
def __init__ (self , local_portage , overlay_dirs ):
12
17
"""Create a new container."""
13
18
14
- import os .path
15
-
16
19
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 ]
20
23
21
24
self ._setup_container (docker_image )
22
25
self ._create_container (docker_image , local_portage ,
23
26
zip (overlay_dirs , overlay_mountpoints ))
24
27
self ._start_container ()
25
28
self ._set_profile ()
26
29
self ._tweak_settings ()
27
- self ._enable_overlays (map ( os . path . basename , overlay_dirs ) )
30
+ self ._enable_overlays (repo_names )
28
31
self ._enable_test ()
29
32
self ._unmask_atom ()
30
33
self ._unmask ()
@@ -40,10 +43,6 @@ def execute(self, cmd):
40
43
cmd is a string which is executed within a bash shell.
41
44
"""
42
45
43
- import os
44
- import subprocess
45
- import sys
46
-
47
46
options .log .info ("%s %s" % (self .cid [:6 ], cmd ))
48
47
docker_cmd = ["docker" , "exec" , "--interactive" ]
49
48
docker_cmd += [self .cid , "/bin/bash" ]
@@ -94,8 +93,6 @@ def execute(self, cmd):
94
93
def shell (self ):
95
94
"""Run an interactive shell in container."""
96
95
97
- import subprocess
98
-
99
96
options .log .info ("running interactive shell in container" )
100
97
docker = subprocess .Popen (["docker" , "exec" , "--tty" , "--interactive" ,
101
98
self .cid , "/bin/bash" ])
@@ -113,8 +110,6 @@ def cleanup(self):
113
110
def remove (self ):
114
111
"""Remove the docker container."""
115
112
116
- import subprocess
117
-
118
113
options .log .info ("stopping container" )
119
114
docker = subprocess .Popen (["docker" , "kill" , self .cid ])
120
115
docker .wait ()
@@ -137,17 +132,13 @@ def _setup_container(self, docker_image):
137
132
"""Setup the container."""
138
133
139
134
if options .options .pull :
140
- import subprocess
141
-
142
135
docker_args = ["docker" , "pull" , docker_image ]
143
136
docker = subprocess .Popen (docker_args )
144
137
docker .wait ()
145
138
146
139
def _create_container (self , docker_image , local_portage , overlays ):
147
140
"""Create new container."""
148
141
149
- import subprocess
150
-
151
142
docker_args = [
152
143
"docker" , "create" ,
153
144
"--tty" ,
@@ -183,8 +174,6 @@ def _create_container(self, docker_image, local_portage, overlays):
183
174
def _start_container (self ):
184
175
"""Start the container."""
185
176
186
- import subprocess
187
-
188
177
docker_args = ["docker" , "start" , "%s" % self .cid ]
189
178
docker = subprocess .Popen (docker_args , stdout = subprocess .PIPE )
190
179
docker .wait ()
@@ -216,17 +205,27 @@ def _tweak_settings(self):
216
205
if options .options .with_X :
217
206
self .execute ("echo USE=\\ \" X\\ \" >> /etc/portage/make.conf" )
218
207
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 ):
220
220
"""Enable overlays."""
221
221
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
+ )
230
229
231
230
def _enable_test (self ):
232
231
"""Enable test FEATURES for ATOM."""
@@ -308,8 +307,6 @@ def _enable_global_use(self):
308
307
def _set_gcc (self ):
309
308
"""Set gcc in the container."""
310
309
311
- import re
312
-
313
310
options .log .info ("setting gcc" )
314
311
if options .options .gcc_version :
315
312
self .execute ("mkdir -p /etc/portage/package.accept_keywords" )
0 commit comments