From: Jason Ish Date: Mon, 26 Mar 2018 13:49:17 +0000 (-0600) Subject: suricatasc: allow to run from non-standard python locations X-Git-Tag: suricata-4.1.0-rc1~174 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4a115f4d56e63a6371552830e760b8fdb6be9ffe;p=thirdparty%2Fsuricata.git suricatasc: allow to run from non-standard python locations When we install to a non-standard prefix, the Python modules are not in the standard location requiring the PYTHONPATH to be fixed up. This wa a pre-existing issue with suricatasc, and not due to the move into the python directory. --- diff --git a/python/bin/suricatasc.in b/python/bin/suricatasc.in index 63b4ebfaf5..00b39d4d3d 100755 --- a/python/bin/suricatasc.in +++ b/python/bin/suricatasc.in @@ -14,10 +14,28 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - from __future__ import print_function + import sys +import os import argparse + +# Find the Python libdir. +exec_dir = os.path.dirname(__file__) +if os.path.exists(os.path.join(exec_dir, "..", "suricata", "ctl", "main.py")): + # Looks like we're running from the development directory. + sys.path.insert(0, ".") +else: + # This is to find the suricata module in the case of being installed + # to a non-standard prefix. + version_info = sys.version_info + pyver = "%d.%d" % (version_info.major, version_info.minor) + path = os.path.join( + exec_dir, "..", "lib", "python%s" % (pyver), "site-packages", + "suricata") + if os.path.exists(path): + sys.path.insert(0, os.path.dirname(path)) + from suricatasc import * parser = argparse.ArgumentParser(prog='suricatasc', description='Client for Suricata unix socket')