From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 9815D1384AC for ; Sat, 12 Sep 2015 20:56:46 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7092EE0852; Sat, 12 Sep 2015 20:56:43 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 025DAE0852 for ; Sat, 12 Sep 2015 20:56:42 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E84E9340A22 for ; Sat, 12 Sep 2015 20:56:41 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B5DBF18F for ; Sat, 12 Sep 2015 20:56:40 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1442091660.25eb96b12eabb19cceab7205696fc5d7fa90933b.blueness@gentoo> Subject: [gentoo-commits] proj/grss:master commit in: grs/ X-VCS-Repository: proj/grss X-VCS-Files: grs/ISOIt.py grs/Interpret.py grs/__init__.py X-VCS-Directories: grs/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 25eb96b12eabb19cceab7205696fc5d7fa90933b X-VCS-Branch: master Date: Sat, 12 Sep 2015 20:56:40 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: d34d0201-6152-409a-b697-c4d8e6e8fde9 X-Archives-Hash: 9fd9fd8cf5b11e684b3f1267fb216939 commit: 25eb96b12eabb19cceab7205696fc5d7fa90933b Author: Anthony G. Basile gentoo org> AuthorDate: Sat Sep 12 20:14:53 2015 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sat Sep 12 21:01:00 2015 +0000 URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=25eb96b1 grs/ISOIt.py: initial commit of isoit directive. grs/ISOIt.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ grs/Interpret.py | 25 ++++++++++++++++++-- grs/__init__.py | 1 + 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/grs/ISOIt.py b/grs/ISOIt.py new file mode 100644 index 0000000..9b3a920 --- /dev/null +++ b/grs/ISOIt.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# +# ISOIt.py: this file is part of the GRS suite +# Copyright (C) 2015 Anthony G. Basile +# +# 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, either version 3 of the License, or +# (at your option) any later version. +# +# 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 . + +import os +from datetime import datetime +from grs.Constants import CONST +from grs.Execute import Execute +from grs.HashIt import HashIt + +class ISOIt(HashIt): + """ Create a bootable ISO of the system. """ + + def __init__(self, name, libdir = CONST.LIBDIR, workdir = CONST.WORKDIR, \ + portage_configroot = CONST.PORTAGE_CONFIGROOT, logfile = CONST.LOGFILE): + self.libdir = libdir + self.workdir = workdir + self.portage_configroot = portage_configroot + self.logfile = logfile + # Prepare a year, month and day for a ISO name timestamp. + self.year = str(datetime.now().year).zfill(4) + self.month = str(datetime.now().month).zfill(2) + self.day = str(datetime.now().day).zfill(2) + self.medium_name = '%s-%s%s%s.iso' % (name, self.year, self.month, self.day) + self.digest_name = '%s.DIGESTS' % self.medium_name + + + def isoit(self, alt_name = None): + # Create the ISO with the default name unless an alt_name is given. + if alt_name: + self.medium_name = '%s-%s%s%s.iso' % (alt_name, self.year, self.month, self.day) + self.digest_name = '%s.DIGESTS' % self.medium_name + iso_path = os.path.join(self.workdir, 'iso') + grub_path = os.path.join(iso_path, 'boot/grub') + os.makedirs(grub_path, mode=0o755, exist_ok=False) + # + # 1. build initramfs image and copy it in + # locate a build script for the initramfs in self.libdir/scripts + # locate a busybox config script in self.libdir/scripts + # locate an init scripts in self.libdir/scripts + # copy in any kernel modules(?) + # find . | cpio -H newc -o | gzip -9 > iso/boot/initramfs.igz + # + # 2. make the squashfs image and copy it into the iso/boot + squashfs_path = os.path.join(iso_path, 'rootfs') + cmd = 'mksquashfs %s %s -xattrs -comp xz' % (self.portage_configroot, squashfs_path) + Execute(cmd, timeout=None, logfile=self.logfile) + # + # 3. prepare the grub bootloader + # copy in stage2_eltorito into iso/boot/grub + # copy in menu.lst into iso/boot/grub + # + # 4. create the iso image + # mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 \ + # -boot-info-table -o medium_pathname.iso iso diff --git a/grs/Interpret.py b/grs/Interpret.py index 5f06fe9..4fdb31b 100644 --- a/grs/Interpret.py +++ b/grs/Interpret.py @@ -24,6 +24,7 @@ import time from grs.Constants import CONST from grs.Daemon import Daemon +from grs.ISOIt import ISOIt from grs.Log import Log from grs.Kernel import Kernel from grs.MountDirectories import MountDirectories @@ -130,6 +131,7 @@ class Interpret(Daemon): pc = PivotChroot(tmpdir, portage_configroot, logfile) ke = Kernel(libdir, portage_configroot, kernelroot, package, logfile) bi = TarIt(name, portage_configroot, logfile) + io = ISOIt(name, libdir, workdir, portage_configroot, logfile) # Just in case /var/tmp/grs doesn't already exist. os.makedirs(tmpdir, mode=0o755, exist_ok=True) @@ -193,7 +195,10 @@ class Interpret(Daemon): obj = None # This long concatenated if is where the semantics of the - # build script are implemented. + # build script are implemented. Note: 'hashit' can only come + # after 'tarit' or 'isoit' so that it knows the medium_name + # to hash, ie whether its a .tar.xz or a .iso + medium_type = None if verb == '': stampit(progress) continue @@ -244,11 +249,27 @@ class Interpret(Daemon): else: smartlog(l, obj, False) bi.tarit() + medium_type = 'tarit' + elif verb == 'isoit': + # 'isoit' can either be just a verb, + # or a 'verb obj' pair. + if obj: + smartlog(l, obj, True) + io.isoit(obj) + else: + smartlog(l, obj, False) + io.isoit() + medium_type = 'isoit' elif verb == 'hashit': if smartlog(l, obj, False): stampit(progress) continue - bi.hashit() + if medium_type == 'tarit': + bi.hashit() + elif medium_type == 'isoit': + io.hashit() + else: + raise Exception('Unknown medium to hash.') else: lo.log('Bad command: %s' % l) diff --git a/grs/__init__.py b/grs/__init__.py index 2ed47f7..fb1b64b 100644 --- a/grs/__init__.py +++ b/grs/__init__.py @@ -21,6 +21,7 @@ from grs.Daemon import Daemon from grs.Execute import Execute from grs.HashIt import HashIt from grs.Interpret import Interpret +from grs.ISOIt import ISOIt from grs.Log import Log from grs.Kernel import Kernel from grs.MountDirectories import MountDirectories