This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
forked from Pardus-Linux/catbox
-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
executable file
·184 lines (159 loc) · 5.12 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2006-2008, TUBITAK/UEKAE
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. Please read the COPYING file.
#
import sys
import os
import glob
import shutil
from setuptools import setup, Extension
from setuptools.command.install import install
from distutils.command.bdist import bdist
from distutils.command.build import build
from setuptools.command.build_ext import build_ext
try:
from wheel.bdist_wheel import bdist_wheel
except ImportError as e:
if 'bdist_wheel' in sys.argv:
sys.stderr.write("Can not build wheel: %r\n" % e)
sys.exit(1)
bdist_wheel = bdist
version='1.7.0'
distfiles = """
setup.py
OKUBENİ
README
src/*.c
src/*.h
tests/*.py
"""
source = [
'src/catbox.c',
'src/core.c',
'src/syscall.c',
'src/paths.c',
'src/retval.c',
]
if 'dist' in sys.argv:
distdir = "catbox-%s" % version
list = []
for t in distfiles.split():
list.extend(glob.glob(t))
if os.path.exists(distdir):
shutil.rmtree(distdir)
os.mkdir(distdir)
for file_ in list:
cum = distdir[:]
for d in os.path.dirname(file_).split('/'):
dn = os.path.join(cum, d)
cum = dn[:]
if not os.path.exists(dn):
os.mkdir(dn)
shutil.copy(file_, os.path.join(distdir, file_))
os.popen("tar -czf %s %s" % ("catbox-" + version + ".tar.gz", distdir))
shutil.rmtree(distdir)
sys.exit(0)
catbox_options = [('enable-pcre', None, "Enable regular expressions in path definitions (using PCRE)")]
catbox_boolean_options = ['enable-pcre']
enable_pcre = False
class Bdist(bdist):
user_options = bdist.user_options
boolean_options = bdist.boolean_options
user_options.extend(catbox_options)
boolean_options.extend(catbox_boolean_options)
def initialize_options(self):
self.enable_pcre = enable_pcre
bdist.initialize_options(self)
def finalize_options(self):
global enable_pcre
enable_pcre = self.enable_pcre
bdist.finalize_options(self)
class BdistWheel(bdist_wheel):
user_options = bdist_wheel.user_options
boolean_options = bdist_wheel.boolean_options
user_options.extend(catbox_options)
boolean_options.extend(catbox_boolean_options)
def initialize_options(self):
self.enable_pcre = enable_pcre
bdist_wheel.initialize_options(self)
def finalize_options(self):
global enable_pcre
enable_pcre = self.enable_pcre
bdist_wheel.finalize_options(self)
class BuildExt(build_ext):
user_options = build_ext.user_options
boolean_options = build_ext.boolean_options
user_options.extend(catbox_options)
boolean_options.extend(catbox_boolean_options)
def initialize_options(self):
self.enable_pcre = enable_pcre
build_ext.initialize_options(self)
def finalize_options(self):
global enable_pcre
enable_pcre = self.enable_pcre
build_ext.finalize_options(self)
def build_extension(self, ext):
global enable_pcre
if enable_pcre:
ext.extra_compile_args.append('-DENABLE_PCRE')
ext.libraries=['pcre']
ext.extra_compile_args.append('-Wall')
ext.extra_compile_args.append('-DVERSION=%s' % version)
build_ext.build_extension(self, ext)
class Build(build):
user_options = build.user_options
boolean_options = build.boolean_options
user_options.extend(catbox_options)
boolean_options.extend(catbox_boolean_options)
def initialize_options(self):
self.enable_pcre = enable_pcre
build.initialize_options(self)
def finalize_options(self):
global enable_pcre
enable_pcre = self.enable_pcre
build.finalize_options(self)
class Install(install):
user_options = install.user_options
boolean_options = install.boolean_options
user_options.extend(catbox_options)
boolean_options.extend(catbox_boolean_options)
def initialize_options(self):
self.enable_pcre = enable_pcre
install.initialize_options(self)
def finalize_options(self):
global enable_pcre
# NOTE: for Pardus distribution
if os.path.exists("/etc/pardus-release"):
self.install_platlib = '$base/lib/pardus'
self.install_purelib = '$base/lib/pardus'
enable_pcre = self.enable_pcre
install.finalize_options(self)
def run(self):
install.run(self)
setup(
name='catbox',
description='Fast sandbox implementation for Python',
author='Pardus Linux',
url='https://github.com/Pardus-Linux/catbox',
version=version,
scripts=['bin/catbox'],
ext_modules=[
Extension(
'catbox',
source,
)
],
cmdclass = {
'install' : Install,
'build' : Build,
'build_ext' : BuildExt,
'bdist' : Bdist,
'bdist_wheel' : BdistWheel,
}
)