Make libselinux bindings optional.

This commit is contained in:
Chris PeBenito 2015-05-10 12:15:16 -04:00
parent 20ee139f3b
commit ab3772843e
3 changed files with 18 additions and 23 deletions

View File

@ -4,25 +4,17 @@
language: python
# These environments have to be spelled
# out so that libselinux bindings get
# the right Python version.
matrix:
include:
- python: "2.7"
env: TOX_ENV=py27
- python: "3.3"
env: TOX_ENV=py33
- python: "3.4"
env: TOX_ENV=py34
- python: "3.3"
env: TOX_ENV=coverage
- env: TOX_ENV=pep8
- env: TOX_ENV=lint
env:
- TOX_ENV=py27
- TOX_ENV=py33
- TOX_ENV=py34
- TOX_ENV=pep8
- TOX_ENV=coverage
- TOX_ENV=lint
matrix:
allow_failures:
- python: "3.3"
env: TOX_ENV=coverage
- env: TOX_ENV=coverage
before_install:
- lsb_release -a
@ -58,9 +50,6 @@ before_install:
# error: declaration of 'index' shadows a global declarationo
- sudo make CFLAGS="-O2 -pipe -fPIC -Wall" -C selinux-src install
# Install libselinux Python bindings.
- sudo make CFLAGS="-O2 -pipe -fPIC -Wall" -C selinux-src/libselinux install-pywrap
# Ubuntu 12.04's flex generates a redundant decl in libqpol
- sed -i -e "/Wwrite-strings/s/,/, '-Wno-redundant-decls',/" setup.py

View File

@ -17,7 +17,7 @@ To run SETools, the following packages are required:
* Python 2.7 or 3.3+
* NetworkX 1.8+
* setuptools
* libselinux (including Python bindings)
* libselinux (Python bindings optional but recommended)
* libbz2
To build SETools, the following development packages are required, in

View File

@ -26,7 +26,10 @@ import logging
from itertools import chain
from errno import ENOENT
import selinux
try:
import selinux
except ImportError:
pass
from . import qpol
@ -82,7 +85,10 @@ class SELinuxPolicy(object):
if policyfile:
self._load_policy(policyfile)
else:
self._load_running_policy()
try:
self._load_running_policy()
except NameError:
raise RuntimeError("Loading the running policy requires libselinux Python bindings")
def __repr__(self):
return "<SELinuxPolicy(\"{0}\")>".format(self.filename)