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 360A113888F for ; Sat, 10 Oct 2015 00:29:59 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2A269E07F9; Sat, 10 Oct 2015 00:29:57 +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 AFDBBE07F9 for ; Sat, 10 Oct 2015 00:29:56 +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 595A73405D5 for ; Sat, 10 Oct 2015 00:29:55 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 3D370DDB for ; Sat, 10 Oct 2015 00:29:53 +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: <1444437315.438583d1e40fd764d491974d1b0ebd75cacf2148.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: 438583d1e40fd764d491974d1b0ebd75cacf2148 X-VCS-Branch: master Date: Sat, 10 Oct 2015 00:29:53 +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: 39b05c58-0764-46f9-a78a-414e546c8fec X-Archives-Hash: 75fb435371425c5811befee4c2361d75 commit: 438583d1e40fd764d491974d1b0ebd75cacf2148 Author: Anthony G. Basile gentoo org> AuthorDate: Sat Oct 10 00:35:08 2015 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sat Oct 10 00:35:15 2015 +0000 URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=438583d1 grs/Interpret.py: restructure semantic actions. grs/Interpret.py | 106 ++++++++++++++++++++++--------------------------------- 1 file changed, 42 insertions(+), 64 deletions(-) diff --git a/grs/Interpret.py b/grs/Interpret.py index 7add215..15b6cfa 100644 --- a/grs/Interpret.py +++ b/grs/Interpret.py @@ -79,20 +79,27 @@ class Interpret(Daemon): sys.exit(signum + 128) - def smartlog(_log, obj, has_obj): - """ 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' % _log) - return True + def signalexit(): + pid = os.getpid() + while True: + os.kill(pid, signal.SIGTERM) + time.sleep(2.0) + + + def semantic_action(_line, objs, n, execstr): + """ Execute the directive """ if self.mock_run: - _lo.log(_log) - return True - return False + _lo.log(_line) + return + try: + if len(objs) < n: + raise Exception('Number of objs for verb incorrect.') + exec(execstr) + except Exception as e: + _lo.log('Bad command: %s' % _line) + _lo.log('Exception throw: %s' % e) + _lo.log('SENDING SIGTERM to pid = %d\n' % pid) + signalexit() def stampit(progress): @@ -195,82 +202,53 @@ class Interpret(Daemon): sentence = _line.split() verb = sentence[0] objs = sentence[1:] - obj = objs[0] # This long concatenated if is where the semantics of the # 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 if verb == 'log': - if smartlog(_line, obj, True): - stampit(progress) - continue - if obj == 'stamp': - _lo.log('='*80) - else: - _lo.log(obj) + if objs[0] == 'stamp': + objs[0] = '='*80 + semantic_action(_line, objs, 1, '_lo.log(\' \'.join(objs))') elif verb == 'mount': - if smartlog(_line, obj, False): - stampit(progress) - continue - _md.mount_all() + semantic_action(_line, objs, 0, '_md.mount_all()') elif verb == 'unmount': - if smartlog(_line, obj, False): - stampit(progress) - continue - _md.umount_all() + semantic_action(_line, objs, 0, '_md.umount_all()') elif verb == 'populate': - if smartlog(_line, obj, True): - stampit(progress) - continue - _po.populate(cycle=int(obj)) + semantic_action(_line, objs, 1, '_po.populate(cycle=int(objs[0]))') elif verb == 'runscript': - if smartlog(_line, obj, True): - stampit(progress) - continue - _ru.runscript(obj) + semantic_action(_line, objs, 1, '_ru.runscript(objs[0])') elif verb == 'pivot': - if smartlog(_line, obj, True): - stampit(progress) - continue - _pc.pivot(obj, _md) + semantic_action(_line, objs, 1, '_pc.pivot(objs[0], _md)') elif verb == 'kernel': - if smartlog(_line, obj, False): - stampit(progress) - continue - _ke.kernel() + semantic_action(_line, objs, 0, '_ke.kernel()') elif verb == 'tarit': - # 'tarit' can either be just a verb, - # or a 'verb obj' pair. - if obj: - smartlog(_line, obj, True) - _bi.tarit(obj) + # 'tarit' can either be just a verb, or a 'verb obj' pair. + if len(objs): + semantic_action(_line, objs, 1, '_bi.tarit(objs[0])') else: - smartlog(_line, obj, False) - _bi.tarit() + semantic_action(_line, objs, 0, '_bi.tarit()') medium_type = 'tarit' elif verb == 'isoit': - # 'isoit' can either be just a verb, - # or a 'verb obj' pair. - if obj: - smartlog(_line, obj, True) - _io.isoit(obj) + # 'isoit' can either be just a verb, or a 'verb obj' pair. + if len(objs): + semantic_action(_line, objs, 1, '_io.isoit(objs[1])') else: - smartlog(_line, obj, False) - _io.isoit() + semantic_action(_line, objs, 0, '_io.isoit()') medium_type = 'isoit' elif verb == 'hashit': - if smartlog(_line, obj, False): - stampit(progress) - continue if medium_type == 'tarit': - _bi.hashit() + semantic_action(_line, objs, 0, '_bi.hashit()') elif medium_type == 'isoit': - _io.hashit() + semantic_action(_line, objs, 0, '_io.hashit()') else: raise Exception('Unknown medium to hash.') else: _lo.log('Bad command: %s' % _line) + _lo.log('Unknown verb: %s' % verb) + _lo.log('SENDING SIGTERM to pid = %d\n' % pid) + signalexit() stampit(progress)