Auto-generate image names.

This commit is contained in:
Ian Gulliver
2016-03-31 22:50:49 -07:00
parent 2a09d69b4c
commit 1a327afa65

View File

@@ -7,6 +7,7 @@ import stat
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
import time
parser = argparse.ArgumentParser(description='iconograph build_image') parser = argparse.ArgumentParser(description='iconograph build_image')
@@ -21,8 +22,8 @@ parser.add_argument(
action='store', action='store',
default='http://archive.ubuntu.com/ubuntu') default='http://archive.ubuntu.com/ubuntu')
parser.add_argument( parser.add_argument(
'--dest-iso', '--image-dir',
dest='dest_iso', dest='image_dir',
action='store', action='store',
required=True) required=True)
parser.add_argument( parser.add_argument(
@@ -82,13 +83,13 @@ class ImageBuilder(object):
'loopback.cfg': 'boot/grub/loopback.cfg', 'loopback.cfg': 'boot/grub/loopback.cfg',
} }
def __init__(self, source_iso, dest_iso, archive, arch, release, modules): def __init__(self, source_iso, image_dir, archive, arch, release, modules):
self._source_iso = source_iso self._source_iso = source_iso
self._dest_iso = dest_iso self._image_dir = image_dir
self._archive = archive self._archive = archive
self._arch = arch self._arch = arch
self._release = release self._release = release
self._modules = modules self._modules = modules or []
self._ico_server_path = os.path.dirname(sys.argv[0]) self._ico_server_path = os.path.dirname(sys.argv[0])
@@ -227,16 +228,19 @@ class ImageBuilder(object):
os.path.join(self._ico_server_path, 'iso_files', source), os.path.join(self._ico_server_path, 'iso_files', source),
os.path.join(union_path, dest)) os.path.join(union_path, dest))
def _CreateISO(self, union_path): def _CreateISO(self, union_path, timestamp):
dest_iso = os.path.join(self._image_dir, '%d.iso' % timestamp)
self._Exec( self._Exec(
'grub-mkrescue', 'grub-mkrescue',
'--output=%s' % self._dest_iso, '--output=%s' % dest_iso,
union_path) union_path)
def _BuildImage(self): def _BuildImage(self):
root = tempfile.mkdtemp() root = tempfile.mkdtemp()
self._rmtree.append(root) self._rmtree.append(root)
timestamp = int(time.time())
print('Building image in:', root) print('Building image in:', root)
self._Exec( self._Exec(
@@ -258,7 +262,7 @@ class ImageBuilder(object):
self._Exec('bash', cwd=root) self._Exec('bash', cwd=root)
self._Squash(chroot_path, union_path) self._Squash(chroot_path, union_path)
self._CopyISOFiles(union_path) self._CopyISOFiles(union_path)
self._CreateISO(union_path) self._CreateISO(union_path, timestamp)
def BuildImage(self): def BuildImage(self):
self._umount = [] self._umount = []
@@ -275,7 +279,7 @@ class ImageBuilder(object):
def main(): def main():
builder = ImageBuilder( builder = ImageBuilder(
FLAGS.source_iso, FLAGS.source_iso,
FLAGS.dest_iso, FLAGS.image_dir,
FLAGS.archive, FLAGS.archive,
FLAGS.arch, FLAGS.arch,
FLAGS.release, FLAGS.release,