1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
# Copyright (C) 2013 Canonical Ltd.
# Author: Colin Watson <cjwatson@ubuntu.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Image building."""
from __future__ import print_function
__metaclass__ = type
import contextlib
import gzip
import os
import shutil
import socket
import stat
import subprocess
import sys
import time
import traceback
from cdimage import osextras
from cdimage.build_id import next_build_id
from cdimage.check_installable import check_installable
from cdimage.germinate import Germination
from cdimage.livefs import (
LiveBuildsFailed,
download_live_filesystems,
live_output_directory,
run_live_builds,
)
from cdimage.log import logger, reset_logging
from cdimage.mail import get_notify_addresses, send_mail
from cdimage.mirror import find_mirror, trigger_mirrors
from cdimage.semaphore import Semaphore
from cdimage.tracker import tracker_set_rebuild_status
from cdimage.tree import Publisher, Tree
from cdimage.config import Touch
@contextlib.contextmanager
def lock_build_image_set(config):
project = config.project
if config["UBUNTU_DEFAULTS_LOCALE"] == "zh_CN":
project = "ubuntu-chinese-edition"
if config.distribution == "ubuntu":
full_series = config.series
else:
full_series = "%s-%s" % (config.distribution, config.series)
lock_path = os.path.join(
config.root, "etc",
".lock-build-image-set-%s-%s-%s" % (
project, full_series, config.image_type))
try:
subprocess.check_call(["lockfile", "-l", "7200", "-r", "0", lock_path])
except subprocess.CalledProcessError:
logger.error("Another image set is already building!")
raise
try:
yield
finally:
osextras.unlink_force(lock_path)
def configure_for_project(config):
project = config.project
series = config["DIST"]
if project == "gobuntu":
config["CDIMAGE_ONLYFREE"] = "1"
elif project == "edubuntu":
if series >= "karmic":
config["CDIMAGE_UNSUPPORTED"] = "1"
elif project == "xubuntu":
if series >= "hardy":
config["CDIMAGE_UNSUPPORTED"] = "1"
elif project == "kubuntu":
if series >= "quantal":
config["CDIMAGE_UNSUPPORTED"] = "1"
elif project in (
"kubuntu-active",
"kubuntu-plasma5",
"ubuntustudio",
"mythbuntu",
"lubuntu",
"ubuntukylin",
"ubuntu-gnome",
"ubuntu-mate",
"ubuntu-moblin-remix",
"ubuntu-mid",
):
config["CDIMAGE_UNSUPPORTED"] = "1"
if config["CDIMAGE_INSTALL"]:
config["CDIMAGE_INSTALL_BASE"] = "1"
def open_log(config):
if config["DEBUG"] or config["CDIMAGE_NOLOG"]:
return None
project = config.project
if config["UBUNTU_DEFAULTS_LOCALE"] == "zh_CN":
project = "ubuntu-chinese-edition"
log_path = os.path.join(
config.root, "log", project, config.full_series,
"%s-%s.log" % (config.image_type, config["CDIMAGE_DATE"]))
osextras.ensuredir(os.path.dirname(log_path))
log = os.open(log_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o666)
os.dup2(log, 1)
os.dup2(log, 2)
os.close(log)
sys.stdout = os.fdopen(1, "w", 1)
sys.stderr = os.fdopen(2, "w", 1)
reset_logging()
# Since we now know we aren't going to be spamming the terminal, it's
# safe to crank up debian-cd's verbosity so that the logs are most
# useful.
config["VERBOSE"] = "3"
return log_path
def log_marker(message):
logger.info("===== %s =====" % message)
logger.info(time.strftime("%a %b %e %H:%M:%S UTC %Y", time.gmtime()))
def want_live_builds(options):
return options is not None and getattr(options, "live", False)
def _anonftpsync_config_path(config):
if config["ANONFTPSYNC_CONF"]:
return config["ANONFTPSYNC_CONF"]
paths = [
os.path.join(config.root, "production", "anonftpsync"),
os.path.join(config.root, "etc", "anonftpsync"),
]
for path in paths:
if os.path.exists(path):
return path
else:
return None
def _anonftpsync_options(config):
env = {}
path = _anonftpsync_config_path(config)
if path:
whitelisted_keys = [
"RSYNC_EXCLUDE",
"RSYNC_ICONV",
"RSYNC_PASSWORD",
"RSYNC_PROXY",
"RSYNC_RSH",
"RSYNC_SRC",
]
for key, value in osextras.read_shell_config(path, whitelisted_keys):
if key.startswith("RSYNC_"):
env[key] = value
if "RSYNC_SRC" not in env:
raise Exception(
"RSYNC_SRC not configured! Edit %s or %s and try again." % (
os.path.join(config.root, "production", "anonftpsync"),
os.path.join(config.root, "etc", "anonftpsync")))
return env
def anonftpsync(config):
env = dict(os.environ)
for key, value in _anonftpsync_options(config).items():
env[key] = value
target = os.path.join(config.root, "ftp")
fqdn = socket.getfqdn()
lock_base = "Archive-Update-in-Progress-%s" % fqdn
lock = os.path.join(target, lock_base)
if subprocess.call(
["lockfile", "-!", "-l", "43200", "-r", "0", lock]) == 0:
raise Exception(
"%s is unable to start rsync; lock file exists." % fqdn)
try:
log_path = os.path.join(config.root, "log", "rsync.log")
osextras.ensuredir(os.path.dirname(log_path))
with open(log_path, "w") as log:
command_base = [
"rsync", "--recursive", "--links", "--hard-links", "--times",
"--verbose", "--stats", "--chmod=Dg+s,g+rwX",
"--exclude", lock_base,
"--exclude", "project/trace/%s" % fqdn,
]
exclude = env.get("RSYNC_EXCLUDE", "").split()
source_target = ["%s/" % env["RSYNC_SRC"], "%s/" % target]
subprocess.call(
command_base + [
"--exclude", "Packages*", "--exclude", "Sources*",
"--exclude", "Release*", "--exclude", "InRelease",
] + exclude + source_target,
stdout=log, stderr=subprocess.STDOUT, env=env)
# Second pass to update metadata and clean up old files.
subprocess.call(
command_base + [
"--delay-updates", "--delete", "--delete-after",
] + exclude + source_target,
stdout=log, stderr=subprocess.STDOUT, env=env)
# Delete dangling symlinks.
for dirpath, _, filenames in os.walk(target):
for filename in filenames:
path = os.path.join(dirpath, filename)
if os.path.islink(path) and not os.path.exists(path):
os.unlink(path)
trace_dir = os.path.join(target, "project", "trace")
osextras.ensuredir(trace_dir)
with open(os.path.join(trace_dir, fqdn), "w") as trace:
subprocess.check_call(["date", "-u"], stdout=trace)
# Note: if you don't have savelog, use any other log rotation
# facility, or comment this out, the log will simply be overwritten
# each time.
with open("/dev/null", "w") as devnull:
subprocess.call(
["savelog", log_path],
stdout=devnull, stderr=subprocess.STDOUT)
finally:
osextras.unlink_force(lock)
def sync_local_mirror(config, semaphore_state):
if config["CDIMAGE_NOSYNC"]:
return
capproject = config.capproject
sync_lock = os.path.join(config.root, "etc", ".lock-archive-sync")
if semaphore_state == 0:
log_marker("Syncing %s mirror" % capproject)
# Acquire lock to allow parallel builds to ensure a consistent
# archive.
try:
subprocess.check_call(["lockfile", "-r", "4", sync_lock])
except subprocess.CalledProcessError:
logger.error("Couldn't acquire archive sync lock!")
raise
try:
anonftpsync(config)
finally:
osextras.unlink_force(sync_lock)
else:
log_marker(
"Parallel build; waiting for %s mirror to sync" % capproject)
try:
subprocess.check_call(["lockfile", "-8", "-r", "450", sync_lock])
except subprocess.CalledProcessError:
logger.error("Timed out waiting for archive sync lock!")
raise
osextras.unlink_force(sync_lock)
def _dpkg_field(path, field):
return subprocess.check_output(
["dpkg", "-f", path, field], universal_newlines=True).rstrip("\n")
def _find_endswith(path, suffixes):
for dirpath, _, filenames in os.walk(path):
for filename in filenames:
for suffix in suffixes:
if filename.endswith(suffix):
yield dirpath, filename
break
def update_local_indices(config):
packages = os.path.join(config.root, "local", "packages")
if not os.path.isdir(packages):
return
database = os.path.normpath(os.path.join(packages, os.pardir, "database"))
dists = os.path.join(database, "dists")
indices = os.path.join(database, "indices")
pool = os.path.join(packages, "pool", "local")
osextras.ensuredir(dists)
osextras.ensuredir(indices)
for arch in config.cpuarches:
binary_list_path = os.path.join(
dists, "%s_local_binary-%s.list" % (config.series, arch))
di_binary_list_path = os.path.join(
dists, "%s_local_debian-installer_binary-%s.list" % (
config.series, arch))
override_path = os.path.join(
indices, "override.%s.local.%s" % (config.series, arch))
di_override_path = os.path.join(
indices, "override.%s.local.debian-installer.%s" % (
config.series, arch))
with open(binary_list_path, "w") as binary_list, \
open(di_binary_list_path, "w") as di_binary_list, \
open(override_path, "w") as override, \
open(di_override_path, "w") as di_override:
for dirpath, deb in _find_endswith(
pool, ["_%s.deb" % arch, "_all.deb"]):
deb_path = os.path.join(dirpath, deb)
print(os.path.relpath(deb_path, packages), file=binary_list)
name = deb.split("_", 1)[0]
section = _dpkg_field(deb_path, "Section").split("/")[-1]
priority = _dpkg_field(deb_path, "Priority")
print(
"%s\t%s\tlocal/%s" % (name, priority, section),
file=override)
for dirpath, udeb in _find_endswith(
pool, ["_%s.udeb" % arch, "_all.udeb"]):
udeb_path = os.path.join(dirpath, udeb)
print(
os.path.relpath(udeb_path, packages), file=di_binary_list)
name = udeb.split("_", 1)[0]
priority = _dpkg_field(udeb_path, "Priority")
print(
"%s\t%s\tlocal/debian-installer" % (name, priority),
file=di_override)
osextras.ensuredir(os.path.join(
packages, "dists", config.series, "local", "binary-%s" % arch))
osextras.ensuredir(os.path.join(
packages, "dists", config.series, "local", "debian-installer",
"binary-%s" % arch))
subprocess.check_call(
["apt-ftparchive", "generate", "apt-ftparchive.conf"], cwd=packages)
def build_britney(config):
update_out = os.path.join(config.root, "britney", "update_out")
if os.path.isfile(os.path.join(update_out, "Makefile")):
log_marker("Building britney")
subprocess.check_call(["make", "-C", update_out])
class UnknownLocale(Exception):
pass
def build_ubuntu_defaults_locale(config):
locale = config["UBUNTU_DEFAULTS_LOCALE"]
if locale != "zh_CN":
raise UnknownLocale(
"UBUNTU_DEFAULTS_LOCALE='%s' not currently supported!" % locale)
series = config["DIST"]
if series < "oneiric":
# Original hack: repack an existing image.
iso = config["ISO"]
if not iso:
raise Exception(
"Pass ISO=<path to Ubuntu image> in the environment.")
scratch = os.path.join(
config.root, "scratch", "ubuntu-chinese-edition", series.name)
bsdtar_tree = os.path.join(scratch, "bsdtar-tree")
log_marker("Unpacking")
if os.path.isdir(bsdtar_tree):
subprocess.check_call(["chmod", "-R", "+w", bsdtar_tree])
osextras.mkemptydir(bsdtar_tree)
subprocess.check_call(["bsdtar", "-xf", iso, "-C", bsdtar_tree])
subprocess.check_call(["chmod", "-R", "+w", bsdtar_tree])
log_marker("Transforming (robots in disguise)")
with open(os.path.join(bsdtar_tree, "isolinux", "lang"), "w") as lang:
print(locale, file=lang)
subprocess.call([
"mkisofs",
"-r", "-V", "Ubuntu Chinese %s i386" % series.version,
"-o", os.path.join(scratch, os.path.basename(iso)),
"-cache-inodes", "-J", "-l",
"-b", "isolinux/isolinux.bin", "-c", "isolinux/boot.cat",
"-no-emul-boot", "-boot-load-size", "4", "-boot-info-table",
bsdtar_tree,
])
iso_prefix = iso.rsplit(".", 1)[0]
scratch_prefix = os.path.join(
scratch, os.path.basename(iso).rsplit(".", 1)[0])
for ext in "list", "manifest":
if os.path.exists("%s.%s" % (iso_prefix, ext)):
shutil.copy2(
"%s.%s" % (iso_prefix, ext),
"%s.%s" % (scratch_prefix, ext))
else:
osextras.unlink_force("%s.%s" % (scratch_prefix, ext))
else:
log_marker("Downloading live filesystem images")
download_live_filesystems(config)
scratch = live_output_directory(config)
for entry in os.listdir(scratch):
if "." in entry:
os.rename(
os.path.join(scratch, entry),
os.path.join(scratch, "%s-desktop-%s" % (series, entry)))
pi_makelist = os.path.join(
config.root, "debian-cd", "tools", "pi-makelist")
for entry in os.listdir(scratch):
if entry.endswith(".iso"):
entry_path = os.path.join(scratch, entry)
list_path = "%s.list" % entry_path.rsplit(".", 1)[0]
with open(list_path, "w") as list_file:
subprocess.check_call(
[pi_makelist, entry_path], stdout=list_file)
def add_android_support(config, arch, output_dir):
"""Copy Android support files to an Ubuntu Touch image.
"""
live_scratch_dir = os.path.join(
config.root, "scratch", config.project, config.full_series,
config.image_type, "live")
# copy recovery, boot and system imgs in place
for target in Touch.list_targets_by_ubuntu_arch(arch):
boot_img_src = "boot-%s+%s.img" % (target.ubuntu_arch, target.subarch)
boot_img = "%s-preinstalled-boot-%s+%s.img" % (
config.series, arch, target.subarch)
system_img_src = "system-%s+%s.img" % (
target.android_arch, target.subarch)
system_img = "%s-preinstalled-system-%s+%s.img" % (
config.series, target.android_arch, target.subarch)
recovery_img_src = "recovery-%s+%s.img" % (
target.android_arch, target.subarch)
recovery_img = "%s-preinstalled-recovery-%s+%s.img" % (
config.series, target.android_arch, target.subarch)
shutil.copy2(
os.path.join(live_scratch_dir, boot_img_src),
os.path.join(output_dir, boot_img))
shutil.copy2(
os.path.join(live_scratch_dir, system_img_src),
os.path.join(output_dir, system_img))
shutil.copy2(
os.path.join(live_scratch_dir, recovery_img_src),
os.path.join(output_dir, recovery_img))
def build_livecd_base(config):
log_marker("Downloading live filesystem images")
download_live_filesystems(config)
if (config.project in ("ubuntu-core", "ubuntu-touch") or
(config.project == "ubuntu-desktop-next" and
config.subproject == "system-image")):
log_marker("Copying images to debian-cd output directory")
scratch_dir = os.path.join(
config.root, "scratch", config.project, config.full_series,
config.image_type)
live_dir = os.path.join(scratch_dir, "live")
for arch in config.arches:
live_prefix = os.path.join(live_dir, arch)
rootfs = "%s.rootfs.tar.gz" % live_prefix
if os.path.exists(rootfs):
output_dir = os.path.join(scratch_dir, "debian-cd", arch)
osextras.ensuredir(output_dir)
if config.project == "ubuntu-core":
if config.image_type == "daily-preinstalled":
output_prefix = os.path.join(
output_dir,
"%s-preinstalled-core-%s" % (config.series, arch))
else:
output_prefix = os.path.join(
output_dir, "%s-core-%s" % (config.series, arch))
elif config.project == "ubuntu-touch":
output_prefix = os.path.join(
output_dir,
"%s-preinstalled-touch-%s" % (config.series, arch))
elif config.project == "ubuntu-desktop-next":
if config.image_type == "daily-preinstalled":
output_prefix = os.path.join(
output_dir,
"%s-preinstalled-desktop-next-%s" %
(config.series, arch))
else:
output_prefix = os.path.join(
output_dir, "%s-desktop-next-%s" %
(config.series, arch))
shutil.copy2(rootfs, "%s.raw" % output_prefix)
with open("%s.type" % output_prefix, "w") as f:
print("tar archive", file=f)
shutil.copy2(
"%s.manifest" % live_prefix, "%s.manifest" % output_prefix)
if config.project == "ubuntu-touch":
osextras.link_force(
"%s.raw" % output_prefix, "%s.tar.gz" % output_prefix)
add_android_support(config, arch, output_dir)
custom = "%s.custom.tar.gz" % live_prefix
if os.path.exists(custom):
shutil.copy2(
custom, "%s.custom.tar.gz" % output_prefix)
if config.project in ("ubuntu-core", "ubuntu-desktop-next"):
for dev in ("azure.device", "device"):
device = "%s.%s.tar.gz" % (live_prefix, dev)
if os.path.exists(device):
shutil.copy2(
device, "%s.%s.tar.gz" % (output_prefix, dev))
def _debootstrap_script(config):
if config["DIST"] <= "gutsy":
return "usr/lib/debootstrap/scripts/%s" % config.series
else:
return "usr/share/debootstrap/scripts/%s" % config.series
def extract_debootstrap(config):
output_dir = os.path.join(
config.root, "scratch", config.project, config.full_series,
config.image_type, "debootstrap")
osextras.ensuredir(output_dir)
for fullarch in config.arches:
arch = fullarch.split("+")[0]
mirror = find_mirror(config, arch)
# TODO: This might be more sensible with python-debian or python-apt.
packages_path = os.path.join(
mirror, "dists", config.series, "main", "debian-installer",
"binary-%s" % arch, "Packages.gz")
with gzip.GzipFile(packages_path, "rb") as packages:
grep_dctrl = subprocess.Popen(
["grep-dctrl", "-nsFilename", "-PX", "debootstrap-udeb"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
udeb, _ = grep_dctrl.communicate(packages.read())
if not isinstance(udeb, str):
udeb = udeb.decode()
udeb = udeb.rstrip("\n")
udeb_path = os.path.join(mirror, udeb)
if not udeb or not os.path.exists(udeb_path):
logger.warning(
"No debootstrap-udeb for %s/%s!" % (config.series, arch))
continue
# TODO: With python-debian, we could extract the one file we need
# directly.
unpack_dir = os.path.join(output_dir, "unpack-%s" % fullarch)
try:
shutil.rmtree(unpack_dir)
except OSError:
pass
subprocess.check_call(["dpkg", "-x", udeb_path, unpack_dir])
shutil.copy2(
os.path.join(unpack_dir, _debootstrap_script(config)),
os.path.join(output_dir, "%s-%s" % (config.series, fullarch)))
def configure_splash(config):
project = config.project
data_dir = os.path.join(config.root, "debian-cd", "data", config.series)
for key, extension in (
("SPLASHRLE", "rle"),
("GFXSPLASH", "pcx"),
("SPLASHPNG", "png"),
):
project_image = os.path.join(data_dir, "%s.%s" % (project, extension))
generic_image = os.path.join(data_dir, "splash.%s" % extension)
if os.path.exists(project_image):
config[key] = project_image
else:
config[key] = generic_image
def run_debian_cd(config):
log_marker("Building %s daily CDs" % config.capproject)
debian_cd_dir = os.path.join(config.root, "debian-cd")
subprocess.call(["./build_all.sh"], cwd=debian_cd_dir, env=config.export())
def fix_permissions(config):
"""Kludge to work around permission-handling problems elsewhere."""
scratch_dir = os.path.join(
config.root, "scratch", config.project, config.full_series,
config.image_type)
if not os.path.isdir(scratch_dir):
return
def fix_directory(path):
old_mode = os.stat(path).st_mode
new_mode = old_mode | stat.S_IRGRP | stat.S_IWGRP
new_mode |= stat.S_ISGID | stat.S_IXGRP
if new_mode != old_mode:
try:
os.chmod(path, new_mode)
except OSError:
pass
def fix_file(path):
old_mode = os.stat(path).st_mode
new_mode = old_mode | stat.S_IRGRP | stat.S_IWGRP
if new_mode & (stat.S_IXUSR | stat.S_IXOTH):
new_mode |= stat.S_IXGRP
if new_mode != old_mode:
try:
os.chmod(path, new_mode)
except OSError:
pass
fix_directory(scratch_dir)
for dirpath, dirnames, filenames in os.walk(scratch_dir):
for dirname in dirnames:
fix_directory(os.path.join(dirpath, dirname))
for filename in filenames:
fix_file(os.path.join(dirpath, filename))
def notify_failure(config, log_path):
if config["DEBUG"] or config["CDIMAGE_NOLOG"]:
return
project = config.project
if config["UBUNTU_DEFAULTS_LOCALE"] == "zh_CN":
project = "ubuntu-chinese-edition"
series = config.full_series
image_type = config.image_type
date = config["CDIMAGE_DATE"]
recipients = get_notify_addresses(config, project)
if not recipients:
return
try:
if log_path is None:
body = ""
else:
body = open(log_path)
send_mail(
"CD image %s%s/%s/%s failed to build on %s" % (
("(built by %s) " % config["SUDO_USER"]
if config["SUDO_USER"] else ""),
project, series, image_type, date),
"build-image-set", recipients, body)
finally:
if log_path is not None:
body.close()
def is_live_fs_only(config):
live_fs_only = False
if config.project in ("livecd-base", "ubuntu-core", "ubuntu-touch"):
live_fs_only = True
elif (config.project == "ubuntu-desktop-next" and
config.subproject == "system-image"):
live_fs_only = True
elif config.subproject == "wubi":
live_fs_only = True
return live_fs_only
def build_image_set_locked(config, options, semaphore_state):
image_type = config.image_type
config["CDIMAGE_DATE"] = date = next_build_id(config, image_type)
log_path = None
try:
configure_for_project(config)
log_path = open_log(config)
if want_live_builds(options):
log_marker("Building live filesystems")
live_successful = run_live_builds(config)
config.limit_arches(live_successful)
else:
tracker_set_rebuild_status(config, [0, 1], 2)
if not is_live_fs_only(config):
sync_local_mirror(config, semaphore_state)
if config["LOCAL"]:
log_marker("Updating archive of local packages")
update_local_indices(config)
build_britney(config)
log_marker("Extracting debootstrap scripts")
extract_debootstrap(config)
if config["UBUNTU_DEFAULTS_LOCALE"]:
build_ubuntu_defaults_locale(config)
elif is_live_fs_only(config):
build_livecd_base(config)
else:
if not config["CDIMAGE_PREINSTALLED"]:
log_marker("Germinating")
germination = Germination(config)
germination.run()
log_marker("Generating new task lists")
germinate_output = germination.output(config.project)
germinate_output.write_tasks()
log_marker("Checking for other task changes")
germinate_output.update_tasks(date)
if (config["CDIMAGE_LIVE"] or config["CDIMAGE_SQUASHFS_BASE"] or
config["CDIMAGE_PREINSTALLED"]):
log_marker("Downloading live filesystem images")
download_live_filesystems(config)
configure_splash(config)
run_debian_cd(config)
fix_permissions(config)
# Temporarily turned off for live builds.
if (config["CDIMAGE_INSTALL_BASE"] and
not config["CDIMAGE_ADDON"] and
not config["CDIMAGE_PREINSTALLED"]):
log_marker("Producing installability report")
check_installable(config)
if not config["DEBUG"] and not config["CDIMAGE_NOPUBLISH"]:
log_marker("Publishing")
tree = Tree.get_daily(config)
publisher = Publisher.get_daily(tree, image_type)
publisher.publish(date)
log_marker("Purging old images")
publisher.purge()
log_marker("Triggering mirrors")
trigger_mirrors(config)
log_marker("Finished")
return True
except Exception as e:
for line in traceback.format_exc().splitlines():
logger.error(line)
sys.stdout.flush()
sys.stderr.flush()
if not isinstance(e, LiveBuildsFailed):
notify_failure(config, log_path)
return False
def build_image_set(config, options):
"""Master entry point for building images."""
semaphore = Semaphore(
os.path.join(config.root, "etc", ".sem-build-image-set"))
with lock_build_image_set(config), semaphore.held() as semaphore_state:
return build_image_set_locked(config, options, semaphore_state)
|