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 55C3413888F for ; Sat, 10 Oct 2015 11:10:13 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 05608E07C7; Sat, 10 Oct 2015 11:10:09 +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 8DE7AE07C7 for ; Sat, 10 Oct 2015 11:10:08 +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 1FB3D34074E for ; Sat, 10 Oct 2015 11:10:07 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 25BAA27A for ; Sat, 10 Oct 2015 11:10:01 +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: <1444475744.c8e8855012e458322bacf094ac2e06ccac716cb0.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: c8e8855012e458322bacf094ac2e06ccac716cb0 X-VCS-Branch: master Date: Sat, 10 Oct 2015 11:10:01 +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: a958b6cd-6194-4f1f-ac8d-47ea32c72c33 X-Archives-Hash: 29c9f6627b56344b60713f08b401848a commit: c8e8855012e458322bacf094ac2e06ccac716cb0 Author: Anthony G. Basile gentoo org> AuthorDate: Sat Oct 10 11:15:44 2015 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sat Oct 10 11:15:44 2015 +0000 URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=c8e88550 grs/Interpret.py: exec() is bad, get rid of it. grs/Interpret.py | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/grs/Interpret.py b/grs/Interpret.py index 12271d6..ea6d2e2 100644 --- a/grs/Interpret.py +++ b/grs/Interpret.py @@ -86,18 +86,23 @@ class Interpret(Daemon): time.sleep(2.0) - def semantic_action(_line, objs, num_objs, execstr): + def semantic_action(_line, objs, nargs, func, *args): """ Execute the directive """ - if self.mock_run: - _lo.log(_line) - return - try: - if len(objs) < num_objs: - raise Exception('Number of objs for verb incorrect.') - exec(execstr) - except Exception as err: - _lo.log('Bad command: %s' % _line) - _lo.log('Exception throw: %s' % err) + err = None + if len(objs) == nargs: + if self.mock_run: + _lo.log(_line) + return + try: + f(*args) + except Exception as err: + pass + else: + err = 'Number of parameters incorrect.' + + if err: + _lo.log('Bad command: %s' % _line) + _lo.log('Error message: %s' % err) _lo.log('SENDING SIGTERM\n') signalexit() @@ -213,44 +218,44 @@ class Interpret(Daemon): if verb == 'log': if objs[0] == 'stamp': objs[0] = '='*80 - semantic_action(_line, objs, 1, '_lo.log(\' \'.join(objs))') + semantic_action(_line, objs, 1, _lo.log, ' '.join(objs)) elif verb == 'mount': - semantic_action(_line, objs, 0, '_md.mount_all()') + semantic_action(_line, objs, 0, _md.mount_all) elif verb == 'unmount': - semantic_action(_line, objs, 0, '_md.umount_all()') + semantic_action(_line, objs, 0, _md.umount_all) elif verb == 'populate': - semantic_action(_line, objs, 1, '_po.populate(cycle=int(objs[0]))') + semantic_action(_line, objs, 1, _po.populate, int(objs[0])) elif verb == 'runscript': - semantic_action(_line, objs, 1, '_ru.runscript(objs[0])') + semantic_action(_line, objs, 1, _ru.runscript, objs[0]) elif verb == 'pivot': - semantic_action(_line, objs, 1, '_pc.pivot(objs[0], _md)') + semantic_action(_line, objs, 1, _pc.pivot, objs[0], _md) elif verb == 'kernel': - semantic_action(_line, objs, 0, '_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 len(objs): - semantic_action(_line, objs, 1, '_bi.tarit(objs[0])') + semantic_action(_line, objs, 1, _bi.tarit, objs[0]) else: - semantic_action(_line, objs, 0, '_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 len(objs): - semantic_action(_line, objs, 1, '_io.isoit(objs[1])') + semantic_action(_line, objs, 1, _io.isoit, objs[0]) else: - semantic_action(_line, objs, 0, '_io.isoit()') + semantic_action(_line, objs, 0, _io.isoit) medium_type = 'isoit' elif verb == 'hashit': if medium_type == 'tarit': - semantic_action(_line, objs, 0, '_bi.hashit()') + semantic_action(_line, objs, 0, _bi.hashit) elif medium_type == 'isoit': - semantic_action(_line, objs, 0, '_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) + _lo.log('SENDING SIGTERM\n') signalexit() stampit(progress)