From: Nicolas Iooss <nicolas.iooss@m4x.org>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: SElinux list <selinux@vger.kernel.org>
Subject: Re: [PATCH] python/sepolicy: call segenxml.py with python3
Date: Thu, 26 Sep 2019 23:58:59 +0200 [thread overview]
Message-ID: <CAJfZ7=ntt2dH6PN3tMQMdw99x4dpU3eRoAd62W4Fqgkvt5Lb5g@mail.gmail.com> (raw)
In-Reply-To: <20190926125218.22958-1-sds@tycho.nsa.gov>
On Thu, Sep 26, 2019 at 2:52 PM Stephen Smalley <sds@tycho.nsa.gov> wrote:
>
> Fixes: https://github.com/SELinuxProject/selinux/issues/61
> Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
> ---
> python/sepolicy/sepolicy/interface.py | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/python/sepolicy/sepolicy/interface.py b/python/sepolicy/sepolicy/interface.py
> index 583091ae18aa..b1b39a492d73 100644
> --- a/python/sepolicy/sepolicy/interface.py
> +++ b/python/sepolicy/sepolicy/interface.py
> @@ -196,7 +196,7 @@ def get_xml_file(if_file):
> from subprocess import getstatusoutput
> basedir = os.path.dirname(if_file) + "/"
> filename = os.path.basename(if_file).split(".")[0]
> - rc, output = getstatusoutput("python /usr/share/selinux/devel/include/support/segenxml.py -w -m %s" % basedir + filename)
> + rc, output = getstatusoutput("/usr/bin/python3 /usr/share/selinux/devel/include/support/segenxml.py -w -m %s" % basedir + filename)
> if rc != 0:
> sys.stderr.write("\n Could not proceed selected interface file.\n")
> sys.stderr.write("\n%s" % output)
Considering that Python's "command" module was removed in Python 3
(according to https://docs.python.org/2/library/commands.html), and
that Python 3's subprocess.getstatusoutput() supports using a list of
arguments instead of a string, it seems better to change this code to
something like:
from subprocess import getstatusoutput
basedir = os.path.dirname(if_file)
filename = os.path.basename(if_file).split(".")[0]
rc, output = getstatusoutput(["python3",
"/usr/share/selinux/devel/include/support/segenxml.py", "-w", "-m",
os.path.join(basedir, filename)])
The code that I suggest is not compatible with Python 2 (which does
not support using list of arguments). Therefore, doing so makes
sepolicy really Python-3 only. I do not consider this to be an issue,
but others may prefer to wait for 3.0 to be released before dropping
support for Python 2 completely.
By the way, the current code is quite misleading because ("%s" % a +
b) is interpreted as (("%s" % a) + b), not ("%s" % (a + b)).
Thankfully the "%s" is at the end of the format string, but if you
want to keep Python 2 compatibility, I suggest adding parentheses
somewhere.
Nicolas
next prev parent reply other threads:[~2019-09-26 21:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-26 12:52 [PATCH] python/sepolicy: call segenxml.py with python3 Stephen Smalley
2019-09-26 21:58 ` Nicolas Iooss [this message]
2019-09-30 12:41 ` Stephen Smalley
2019-09-30 16:29 ` Petr Lautrbach
2019-09-30 19:36 ` Nicolas Iooss
2019-10-07 13:23 ` Stephen Smalley
2019-10-07 16:32 ` Nicolas Iooss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJfZ7=ntt2dH6PN3tMQMdw99x4dpU3eRoAd62W4Fqgkvt5Lb5g@mail.gmail.com' \
--to=nicolas.iooss@m4x.org \
--cc=sds@tycho.nsa.gov \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).