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 CDFF9138D19 for ; Tue, 14 Jul 2015 21:02:07 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 795B5E085C; Tue, 14 Jul 2015 21:02:04 +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 49C63E087D for ; Tue, 14 Jul 2015 21:02:03 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 202F434093A for ; Tue, 14 Jul 2015 21:02:02 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 5EE27904 for ; Tue, 14 Jul 2015 21:02:00 +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: <1436907839.cbe8e606b84a9a2e028646a686565df5ccd48db4.blueness@gentoo> Subject: [gentoo-commits] proj/grss:master commit in: grs/ X-VCS-Repository: proj/grss X-VCS-Files: grs/Interpret.py X-VCS-Directories: grs/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: cbe8e606b84a9a2e028646a686565df5ccd48db4 X-VCS-Branch: master Date: Tue, 14 Jul 2015 21:02:00 +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: a22255d8-fa52-492c-8024-c099b9114056 X-Archives-Hash: dd2a08264dd53aab4c99e3c406415a25 commit: cbe8e606b84a9a2e028646a686565df5ccd48db4 Author: Anthony G. Basile gentoo org> AuthorDate: Tue Jul 14 20:58:00 2015 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Tue Jul 14 21:03:59 2015 +0000 URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=cbe8e606 grs/Interpret.py: add documentation. grs/Interpret.py | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/grs/Interpret.py b/grs/Interpret.py index 4749561..a941f3e 100644 --- a/grs/Interpret.py +++ b/grs/Interpret.py @@ -20,15 +20,16 @@ from grs.TarIt import TarIt class Interpret(Daemon): - """ doc here - more doc - """ + """ This is the main daemon class. """ def run(self): - """ doc here - more doc + """ This overrides the empty Daemon run method and is started when .start() + is executed. This first daemonizes the process and then runs this method. + Note that the Daemon class does not set up any signal handles and expects + that to be done in the subclass. """ + # First we set up some inner methods: def handler(signum, frame): """ On SIGTERM, propagate the signal to all processes in the cgroup/subcgroup except yourself. If a process won't terminate nicely, then kill it. @@ -60,10 +61,14 @@ class Interpret(Daemon): pass sys.exit(signum + 128) - signal.signal(signal.SIGINT, handler) - signal.signal(signal.SIGTERM, handler) def smartlog(l, obj, has_obj = True): + """ This logs whether or not we have a grammatically incorrect + directive, or we are doing a mock run, and returns whether + or not we should execute the directive: + True = skip this directive + False = don't skip it + """ if (has_obj and not obj) or (not has_obj and obj): lo.log('Bad command: %s' % l) return True @@ -72,9 +77,19 @@ class Interpret(Daemon): return True return False + def stampit(progress): + """ Create an empty file to mark the progress through the + build script. + """ open(progress, 'w').close() + + # Register the signals to terminate the entire process cgroup + signal.signal(signal.SIGINT, handler) + signal.signal(signal.SIGTERM, handler) + + # Grab all the GRS namespace variables nameserver = CONST.nameservers[self.run_number] repo_uri = CONST.repo_uris[self.run_number] stage_uri = CONST.stage_uris[self.run_number] @@ -88,6 +103,9 @@ class Interpret(Daemon): kernelroot = CONST.kernelroots[self.run_number] portage_configroot = CONST.portage_configroots[self.run_number] + # Initialize all the classes that will run the directives from + # the build script. Note that we expect these classes to just + # initialize some variables but not do any work in their initializers. lo = Log(logfile) sy = Synchronize(repo_uri, name, libdir, logfile) se = Seed(stage_uri, tmpdir, portage_configroot, package, logfile) @@ -98,12 +116,15 @@ class Interpret(Daemon): ke = Kernel(libdir, portage_configroot, kernelroot, package, logfile) bi = TarIt(name, portage_configroot, logfile) + # Just in case /var/tmp/grs doesn't already exist. os.makedirs(tmpdir, mode=0o755, exist_ok=True) + # Rotate any prevously existing logs and make unmount any existing + # bind mounts from a previous run that were not cleaned up. lo.rotate_logs() md.umount_all() - # Both sync() + seed() are not scripted steps. + # Both sync() + seed() do not need build script directives. # sync() is done unconditionally for an update run. progress = os.path.join(tmpdir, '.completed_sync') if not os.path.exists(progress) or self.update_run: @@ -116,13 +137,14 @@ class Interpret(Daemon): se.seed() stampit(progress) + # Read the build script and execute a line at a time. build_script = os.path.join(libdir, 'build') with open(build_script, 'r') as s: line_number = 0 for l in s.readlines(): line_number += 1 - # Skip lines with initial # as comments + # Skip lines with initial # as comments. m = re.search('^(#).*$', l) if m: continue @@ -155,6 +177,8 @@ class Interpret(Daemon): verb = l.strip() obj = None + # This long concatenated if is where the semantics of the + # build script are implemented. if verb == '': stampit(progress) continue @@ -214,3 +238,10 @@ class Interpret(Daemon): lo.log('Bad command: %s' % l) stampit(progress) + + # Just in case the build script lacks a final unmount, if we + # are done, then let's make sure we clean up after ourselves. + try: + md.umount_all() + except NameError: + pass