From patchwork Thu Aug 4 18:33:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Zaman X-Patchwork-Id: 9264053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C7796048B for ; Thu, 4 Aug 2016 18:38:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F394D283E4 for ; Thu, 4 Aug 2016 18:38:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7FE32841F; Thu, 4 Aug 2016 18:38:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (smtp.nsa.gov [8.44.101.8]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AF41283E4 for ; Thu, 4 Aug 2016 18:38:20 +0000 (UTC) Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 04 Aug 2016 18:38:18 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u74IcH3n011843; Thu, 4 Aug 2016 14:38:17 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u74IYR1Y250303 for ; Thu, 4 Aug 2016 14:34:27 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u74IYMKW011354 for ; Thu, 4 Aug 2016 14:34:29 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1BwAABGiqNXf0HcVdFcHQGCeoEDfLEshWSEDCCFfQKBSEwBAQEBAQETAQEJCwsJF4UQAgEDEi4BATcBD0ARNAEFARwZIogPAaEUgTI+MYpUhSoBAQWLRQEBAQEBAQQCARwIEIQPiCKFPwuDB4gqhXJ0iimGGohqZYFShw2Feo5pMIEPglmCAmEBhyoBAQE X-IPAS-Result: A1BwAABGiqNXf0HcVdFcHQGCeoEDfLEshWSEDCCFfQKBSEwBAQEBAQETAQEJCwsJF4UQAgEDEi4BATcBD0ARNAEFARwZIogPAaEUgTI+MYpUhSoBAQWLRQEBAQEBAQQCARwIEIQPiCKFPwuDB4gqhXJ0iimGGohqZYFShw2Feo5pMIEPglmCAmEBhyoBAQE X-IronPort-AV: E=Sophos;i="5.28,471,1464667200"; d="scan'208";a="5626384" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 04 Aug 2016 14:35:17 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/AES128-GCM-SHA256; 04 Aug 2016 18:34:28 +0000 Received: by mail-pa0-f65.google.com with SMTP id q2so17934449pap.0 for ; Thu, 04 Aug 2016 11:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=perfinion-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tdIkzS4QR0Qq0BT//mdDQ9eEVUioFY1RIN5su0gFvRQ=; b=QB4CgUzANm6GM2Vnf+ozdk091pAwB67CN8QEdXSZHmkU0he1qJBwJI+W4mje915AKH KnWAMM222RAi9G1irjCZdbsbVTSOCibCqEVnLPxmwkI9TwJB4TdRGQreLnIqL4/zsSo5 GHhVo71ygHw9d1BTJL1Om+0FmyG6XkBELCABBTOaJp2jD2Zc+KvNIQNbNhAinXYKdYoV EJd1laSyVYU/fRVsPzgjD19/SkQRwyNFKYp8NIMcYrzFE9slA05mmBEcJ61bwrSr/IRz R1Uai//imLgmjcy79ncfBYGvySEclHOv8nf+GRymjrPYgW0txkDNX+3K79ZiXQBTSt2z MyEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tdIkzS4QR0Qq0BT//mdDQ9eEVUioFY1RIN5su0gFvRQ=; b=I/26DpJ5cjid2QZFGfUEzoflOa/zdzKksF8bpwQqdjQmkkJIAD4AoVwoNuglcgquF+ WM2ibH+P4TCK3cJRnXaOtVokbKCs91bRNyjjWsBeN2+EQRDVIs+0iIr+CiHbIZXTEbM0 tg8kN4w/fS2O8HbBGpHR+W66VjrltKZ41EmKNkFbi5/1VrSwkLIL0D0yRTz38RUj73f0 NzZfsh8FPKUjn4JG1rY6FaXbEmdM1VCU8K8Vobxb1ADV2FSErfgFaVXN9/5TWkeaA5/e imX5bXcrfq6bM9+/r3Ui/fc+gYvaha4lD9JzKTtIGz7jkSe8dV1+/SMe3mwsBA/Oq6s0 OpoQ== X-Gm-Message-State: AEkoouueU/18nTlsRyPAQBmTQGsbdU/XbTkvwPLuTNq/x8qpGE++6DZqAjgu96MqDJBhLQ== X-Received: by 10.67.13.196 with SMTP id fa4mr130472138pad.115.1470335667671; Thu, 04 Aug 2016 11:34:27 -0700 (PDT) Received: from localhost ([2404:e800:e600:57b:dcfa:b5a4:c9d2:f744]) by smtp.gmail.com with ESMTPSA id n13sm22081041pfj.16.2016.08.04.11.34.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 11:34:27 -0700 (PDT) From: Jason Zaman To: selinux@tycho.nsa.gov Subject: [PATCH 03/12] semanage: misc style issues Date: Fri, 5 Aug 2016 02:33:56 +0800 Message-Id: <1470335645-24224-4-git-send-email-jason@perfinion.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1470335645-24224-1-git-send-email-jason@perfinion.com> References: <1470335645-24224-1-git-send-email-jason@perfinion.com> X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP Unused imports == None should be is None Signed-off-by: Jason Zaman --- policycoreutils/semanage/semanage | 5 +++-- policycoreutils/semanage/seobject.py | 15 +++++---------- policycoreutils/semanage/test-semanage.py | 3 --- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/policycoreutils/semanage/semanage b/policycoreutils/semanage/semanage index 954411d..e6e3a49 100644 --- a/policycoreutils/semanage/semanage +++ b/policycoreutils/semanage/semanage @@ -23,6 +23,7 @@ # # +import traceback import argparse import seobject import sys @@ -111,7 +112,7 @@ class SetExportFile(argparse.Action): try: sys.stdout = open(values, 'w') except: - sys.stderr.write("%s: %s\n" % (e.__class__.__name__, str(e))) + sys.stderr.write(traceback.format_exc()) sys.exit(1) setattr(namespace, self.dest, values) @@ -702,7 +703,7 @@ def handlePermissive(args): if args.action is "list": OBJECT.list(args.noheading) - elif args.type != None: + elif args.type is not None: if args.action is "add": OBJECT.add(args.type) if args.action is "delete": diff --git a/policycoreutils/semanage/seobject.py b/policycoreutils/semanage/seobject.py index 66ff00e..5100720 100644 --- a/policycoreutils/semanage/seobject.py +++ b/policycoreutils/semanage/seobject.py @@ -23,14 +23,11 @@ import pwd import grp -import string import selinux -import tempfile import os import re import sys import stat -import shutil from semanage import * PROGNAME = "policycoreutils" import sepolicy @@ -129,9 +126,9 @@ except: message += " role=" + serole if oldserole != "": message += " old_role=" + oldserole - if serange != "" and serange != None: + if serange != "" and serange is not None: message += " MLSRange=" + serange - if oldserange != "" and oldserange != None: + if oldserange != "" and oldserange is not None: message += " old_MLSRange=" + oldserange self.log_list.append(message) @@ -416,7 +413,7 @@ class dontauditClass(semanageRecords): if dontaudit not in ["on", "off"]: raise ValueError(_("dontaudit requires either 'on' or 'off'")) self.begin() - rc = semanage_set_disable_dontaudit(self.sh, dontaudit == "off") + semanage_set_disable_dontaudit(self.sh, dontaudit == "off") self.commit() @@ -459,7 +456,6 @@ class permissiveRecords(semanageRecords): print(t) def add(self, type): - import glob try: import sepolgen.module as module except ImportError: @@ -830,7 +826,6 @@ class seluserRecords(semanageRecords): self.mylog.log("seuser", sename=name, serole=",".join(roles), serange=serange) def add(self, name, roles, selevel, serange, prefix): - serole = " ".join(roles) try: self.begin() self.__add(name, roles, selevel, serange, prefix) @@ -1897,7 +1892,7 @@ class fcontextRecords(semanageRecords): if setype != "<>": con = semanage_fcontext_get_con(fcontext) - if con == None: + if con is None: con = self.createcon(target) if (is_mls_enabled == 1) and (serange != ""): @@ -2071,7 +2066,7 @@ class booleanRecords(semanageRecords): self.current_booleans = [] ptype = None - if self.store == None or self.store == ptype: + if self.store is None or self.store == ptype: self.modify_local = True else: self.modify_local = False diff --git a/policycoreutils/semanage/test-semanage.py b/policycoreutils/semanage/test-semanage.py index 10c4d8f..12ffc98 100644 --- a/policycoreutils/semanage/test-semanage.py +++ b/policycoreutils/semanage/test-semanage.py @@ -1,8 +1,5 @@ import unittest -import os -import shutil import sys -from tempfile import mkdtemp from subprocess import Popen, PIPE import argparse