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 language: python
# These environments have to be spelled env:
# out so that libselinux bindings get - TOX_ENV=py27
# the right Python version. - TOX_ENV=py33
matrix: - TOX_ENV=py34
include: - TOX_ENV=pep8
- python: "2.7" - TOX_ENV=coverage
env: TOX_ENV=py27 - TOX_ENV=lint
- 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
matrix:
allow_failures: allow_failures:
- python: "3.3" - env: TOX_ENV=coverage
env: TOX_ENV=coverage
before_install: before_install:
- lsb_release -a - lsb_release -a
@ -58,9 +50,6 @@ before_install:
# error: declaration of 'index' shadows a global declarationo # error: declaration of 'index' shadows a global declarationo
- sudo make CFLAGS="-O2 -pipe -fPIC -Wall" -C selinux-src install - 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 # Ubuntu 12.04's flex generates a redundant decl in libqpol
- sed -i -e "/Wwrite-strings/s/,/, '-Wno-redundant-decls',/" setup.py - 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+ * Python 2.7 or 3.3+
* NetworkX 1.8+ * NetworkX 1.8+
* setuptools * setuptools
* libselinux (including Python bindings) * libselinux (Python bindings optional but recommended)
* libbz2 * libbz2
To build SETools, the following development packages are required, in To build SETools, the following development packages are required, in

View File

@ -26,7 +26,10 @@ import logging
from itertools import chain from itertools import chain
from errno import ENOENT from errno import ENOENT
import selinux try:
import selinux
except ImportError:
pass
from . import qpol from . import qpol
@ -82,7 +85,10 @@ class SELinuxPolicy(object):
if policyfile: if policyfile:
self._load_policy(policyfile) self._load_policy(policyfile)
else: 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): def __repr__(self):
return "<SELinuxPolicy(\"{0}\")>".format(self.filename) return "<SELinuxPolicy(\"{0}\")>".format(self.filename)