-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup.py
executable file
·219 lines (194 loc) · 7.08 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# $Id$
#
# PyXMLSec - Python bindings for XML Security library (XMLSec)
#
# Copyright (C) 2003-2013 Easter-eggs, Valery Febvre
# http://pyxmlsec.labs.libre-entreprise.org
#
# Author: Valery Febvre <[email protected]>
#
# This is free software; see COPYING file in the source
# distribution for preciese wording.
__doc__ = """Python bindings for XMLSec Library
PyXMLSec is a set of Python bindings for XML Security Library (XMLSec).
"""
from distutils.core import setup, Extension
import sys, commands
# check python version
if not hasattr(sys, 'version_info') or sys.version_info < (2,2):
raise SystemExit, "PyXMLSec requires Python version 2.2 or above."
# sanity check for any arguments
if len(sys.argv) == 1:
msg = 'Choose an action :\n' \
' 1. Build\n' \
' 2. Install\n' \
' 3. Clean\n' \
' 4. Exit\n' \
'Your choice : '
reply = raw_input(msg)
choice = None
if reply:
choice = reply[0]
if choice == '1':
sys.argv.append('build')
elif choice == '2':
sys.argv.append('install')
elif choice == '3':
sys.argv.append('clean')
sys.argv.append('-a')
elif choice == '4':
sys.exit(0)
# the crypto engine name : openssl, gnutls or nss
xmlsec1_crypto = "openssl"
if 'build' in sys.argv:
msg = '\nChoose a crypto engine :\n' \
' 1. OpenSSL\n' \
' 2. GnuTLS\n' \
' 3. NSS\n' \
'Your choice : '
reply = raw_input(msg)
choice = None
if reply:
choice = reply[0]
if choice == '1':
xmlsec1_crypto = "openssl"
elif choice == '2':
xmlsec1_crypto = "gnutls"
elif choice == '3':
xmlsec1_crypto = "nss"
define_macros = []
include_dirs = []
library_dirs = []
libraries = []
def extract_cflags(cflags):
global define_macros, include_dirs
xmlsec_openssl_prefix = 'XMLSEC_OPENSSL_'
list = cflags.split(' ')
for flag in list:
if flag == '':
continue
flag = flag.replace("\\\"", "")
if flag[:2] == "-I":
if flag[2:] not in include_dirs:
include_dirs.append(flag[2:])
elif flag[:2] == "-D":
t = tuple(flag[2:].split('='))
if len(t) == 1:
t = (t[0], None)
# Problem: app.c only checks XMLSEC_OPENSSL_098,
# but newer OpenSSL libs emit other flags such as
# XMLSEC_OPENSSL_100
#
# Assumption: Methods provided by OpenSSL 098 will still
# be provided by newer versions of OpenSSL.
#
# Solution: Add the old flag for newer OpenSSL libs.
#
# See https://github.com/dnet/pyxmlsec/issues/4
if t[0].startswith(xmlsec_openssl_prefix) and t[1] == '1':
version_as_string = t[0][len(xmlsec_openssl_prefix):]
try:
version = int(version_as_string)
if version > 98:
hacked_t = (xmlsec_openssl_prefix + '098', t[1])
if hacked_t not in define_macros:
define_macros.append(hacked_t)
except Exception as ex:
print "Warning: I thought %s was a version flag but I don't understand %s as a number." % (repr(t), repr(version_as_string))
if t not in define_macros:
define_macros.append(t)
else:
print "Warning : cflag %s skipped" % flag
def extract_libs(libs):
global library_dirs, libraries
list = libs.split(' ')
for flag in list:
if flag == '':
continue
if flag[:2] == "-l":
if flag[2:] not in libraries:
libraries.append(flag[2:])
elif flag[:2] == "-L":
if flag[2:] not in library_dirs:
library_dirs.append(flag[2:])
else:
print "Warning : linker flag %s skipped" % flag
libxml2_cflags = commands.getoutput('pkg-config libxml-2.0 --cflags')
if libxml2_cflags[:2] not in ["-I", "-D"]:
libxml2_cflags = commands.getoutput('xml2-config --cflags')
if libxml2_cflags[:2] not in ["-I", "-D"]:
print "Error : cannot get LibXML2 pre-processor and compiler flags"
libxml2_libs = commands.getoutput('pkg-config libxml-2.0 --libs')
if libxml2_libs[:2] not in ["-l", "-L"]:
libxml2_libs = commands.getoutput('xml2-config --libs')
if libxml2_libs[:2] not in ["-l", "-L"]:
print "Error : cannot get LibXML2 linker flags"
cmd = 'pkg-config xmlsec1-%s --cflags' % xmlsec1_crypto
xmlsec1_cflags = commands.getoutput(cmd)
if xmlsec1_cflags[:2] not in ["-I", "-D"]:
cmd = 'xmlsec1-config --cflags --crypto=%s' % xmlsec1_crypto
xmlsec1_cflags = commands.getoutput(cmd)
if xmlsec1_cflags[:2] not in ["-I", "-D"]:
print "Error : cannot get XMLSec1 pre-processor and compiler flags"
cmd = 'pkg-config xmlsec1-%s --libs' % xmlsec1_crypto
xmlsec1_libs = commands.getoutput(cmd)
if xmlsec1_libs[:2] not in ["-l", "-L"]:
cmd = 'xmlsec1-config --libs --crypto=%s' % xmlsec1_crypto
xmlsec1_libs = commands.getoutput(cmd)
if xmlsec1_libs[:2] not in ["-l", "-L"]:
print "Error : cannot get XMLSec1 linker flags"
#print libxml2_cflags
#print libxml2_libs
#print xmlsec1_cflags
#print xmlsec1_libs
extract_cflags(libxml2_cflags)
extract_libs(libxml2_libs)
extract_cflags(xmlsec1_cflags)
extract_libs(xmlsec1_libs)
#print define_macros
#print include_dirs
#print library_dirs
#print libraries
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: POSIX',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: Security',
'Topic :: Software Development :: Libraries :: Python Modules',
]
em = Extension("xmlsecmod",
sources = ["utils.c", "wrap_objs.c",
"app.c", "base64.c", "buffer.c", "errors.c",
"keyinfo.c", "keys.c", "keysdata.c", "keysmngr.c",
"list.c", "membuf.c", "nodeset.c", "parser.c",
"templates.c", "transforms.c", "version.c",
"xmldsig.c", "xmlenc.c", "xmlsec.c", "xmltree.c",
"x509.c",
"xmlsecmod.c"],
define_macros = define_macros,
include_dirs = include_dirs,
library_dirs = library_dirs,
libraries = libraries
)
doclines = __doc__.split("\n")
setup(name = "pyxmlsec",
version = "0.4.0",
description = doclines[0],
long_description = "\n" . join(doclines[2:]),
author = "Valery Febvre",
author_email = "[email protected]",
license = "MIT",
platforms = ["any"],
url = "http://pyxmlsec.labs.libre-entreprise.org",
classifiers = classifiers,
download_url = 'https://labs.libre-entreprise.org/frs/?group_id=17',
ext_modules = [em],
py_modules = ["xmlsec", "xmlsec_strings"]
)