Skip to content

Commit a8d1208

Browse files
Julien VoisinFelipe Zimmerle
Julien Voisin
authored and
Felipe Zimmerle
committed
Make the setup.py file work in python3 and refactor find_modesec
- Add parentheses where needed for python3 - Refactor the find_modsec function to reduce its runtime complexity - Make the code more pythonic - The script now tell is the headers _or_ the lib was found
1 parent d21d728 commit a8d1208

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

setup.py

+30-24
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
libraries_dir = [
3131
"lib/",
32-
"lib64/"
32+
"lib64/",
33+
"./"
3334
]
3435

3536
headers_dir = [
@@ -38,37 +39,42 @@
3839
"./"
3940
]
4041

41-
def find_modsec():
42-
for i in possible_modsecurity_dirs:
43-
lib = None
44-
inc = None
45-
46-
for j in libraries_dir:
47-
p = os.path.join(i, j, "libmodsecurity.so")
48-
if os.path.isfile(p) or os.path.islink(p):
49-
lib = os.path.join(i, j)
5042

51-
for x in headers_dir:
52-
p = os.path.join(i, x, os.path.join("modsecurity", "modsecurity.h"))
53-
if os.path.isfile(p) or os.path.islink(p):
54-
inc = os.path.join(i, x)
55-
56-
if inc != None and lib != None:
57-
return (inc, lib)
58-
59-
return (None, None)
43+
def find_modsec():
44+
def find_library(modsec_dir):
45+
for i in libraries_dir:
46+
path = os.path.join(modsec_dir, i, "libmodsecurity.so")
47+
if os.path.isfile(path):
48+
return os.path.join(modsec_dir, i)
49+
return None
50+
51+
def find_header(modsec_dir):
52+
for i in headers_dir:
53+
path = os.path.join(modsec_dir, i, "modsecurity", "modsecurity.h")
54+
if os.path.isfile(path):
55+
return os.path.join(modsec_dir, i)
56+
return None
57+
58+
inc = lib = None
59+
for modsec_dir in possible_modsecurity_dirs:
60+
if not inc:
61+
inc = find_header(modsec_dir)
62+
if not lib:
63+
lib = find_library(modsec_dir)
64+
65+
return (inc, lib)
6066

6167
inc_dir, lib_dir = find_modsec()
6268

6369

64-
print "*** found modsecurity at:"
65-
print " headers: " + str(inc_dir)
66-
print " library: " + str(lib_dir)
70+
print("*** found modsecurity at:")
71+
print(" headers: " + str(inc_dir))
72+
print(" library: " + str(lib_dir))
6773

6874

6975
if inc_dir == None or lib_dir == None:
70-
print "libModSecurity was not found in your system."
71-
print "Make sure you have libModSecurity correctly installed in your system."
76+
print("libModSecurity was not found in your system.")
77+
print("Make sure you have libModSecurity correctly installed in your system.")
7278
sys.exit(1)
7379

7480

0 commit comments

Comments
 (0)