-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup.py
219 lines (176 loc) · 6.91 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
from distutils.core import setup
from distutils.core import Command
from distutils import dir_util
from distutils.spawn import spawn
from distutils.file_util import write_file
from distutils.util import change_root, convert_path
import os
from subprocess import call
class RpmDirs(object):
_standard_dirs = ('SOURCES', 'SPECS', 'BUILD', 'BUILDROOT', 'RPMS', 'SRPMS')
def __init__(self, root: str):
self._root = root
self._dirs = {_dir: os.path.join(self._root, _dir) for _dir in self._standard_dirs}
@property
def root(self):
return self._root
@property
def sources(self):
return self._dirs['SOURCES']
@property
def specs(self):
return self._dirs['SPECS']
@property
def build(self):
return self._dirs['BUILD']
@property
def buildroot(self):
return self._dirs['BUILDROOT']
@property
def rpms(self):
return self._dirs['RPMS']
@property
def srpms(self):
return self._dirs['SRPMS']
def create_dirs(self):
for _dir in self._dirs.values():
dir_util.mkpath(_dir)
class build_rpm(Command):
description = 'creates an RPM distribution'
user_options = [
('rpmbuild-dir=', 'r', 'RPM Build output directory')
]
def initialize_options(self):
self.rpmbuild_dir = None
def finalize_options(self):
self.rpm_dirs = RpmDirs(self.rpmbuild_dir)
def run(self):
self.rpm_dirs.create_dirs()
sdist = self.reinitialize_command('sdist')
self.run_command('sdist')
source = sdist.get_archive_files()[0]
self.copy_file(source, self.rpm_dirs.sources)
spawn(['rpmbuild', '-v', '-bb', '--define', f'_topdir {self.rpm_dirs.root}',
f'{self.distribution.get_name()}.spec'])
class install_cb(Command):
"""This install_cb plugin will install all data files associated with the
tool as well as the pyinstaller-compiled single binary scripts so that
they can be packaged together in a binary RPM."""
description = "install binary distribution files"
user_options = [
('install-dir=', 'd',
"base directory for installing data files "
"(default: installation base dir)"),
('root=', None,
"install everything relative to this alternate root directory"),
('force', 'f', "force installation (overwrite existing files)"),
('record=', None,
"filename in which to record list of installed files"),
]
boolean_options = ['force']
def initialize_options(self):
self.install_dir = None
self.outfiles = []
self.root = None
self.force = 0
self.data_files = self.distribution.data_files
self.warn_dir = 1
self.record = None
def finalize_options(self):
self.set_undefined_options('install',
('install_data', 'install_dir'),
('root', 'root'),
('force', 'force'),
)
def run(self):
for f in self.data_files:
if isinstance(f, str):
# don't copy files without path information
pass
else:
# it's a tuple with path to install to and a list of files
dir = convert_path(f[0])
if not os.path.isabs(dir):
dir = os.path.join(self.install_dir, dir)
elif self.root:
dir = change_root(self.root, dir)
self.mkpath(dir)
if f[1] == []:
# If there are no files listed, the user must be
# trying to create an empty directory, so add the
# directory to the list of output files.
self.outfiles.append(dir)
else:
# Copy files, adding them to the list of output files.
for data in f[1]:
data = convert_path(data)
(out, _) = self.copy_file(data, dir)
self.outfiles.append(out)
for scriptname in scripts.keys():
pathname = scripts[scriptname]['dest']
dir = convert_path(pathname)
dir = os.path.dirname(dir)
dir = change_root(self.root, dir)
self.mkpath(dir)
data = os.path.join('dist', scriptname)
out = self.copy_tree(data, dir, preserve_mode=True)
self.outfiles.extend(out)
if self.record:
outputs = self.get_outputs()
if self.root: # strip any package prefix
root_len = len(self.root)
for counter in range(len(outputs)):
outputs[counter] = outputs[counter][root_len:]
self.execute(write_file,
(self.record, outputs),
"writing list of installed files to '%s'" %
self.record)
def get_inputs(self):
return self.data_files or []
def get_outputs(self):
return self.outfiles
def get_data_files(rootdir):
# automatically build list of (dir, [file1, file2, ...],)
# for all files under src/root/ (or provided rootdir)
results = []
for root, dirs, files in os.walk(rootdir):
if len(files) > 0:
dirname = os.path.relpath(root, rootdir)
flist = [os.path.join(root, f) for f in files]
results.append(("/%s" % dirname, flist))
return results
data_files = get_data_files("root")
data_files.append('cb-lastline-connector.spec')
data_files.append('scripts/cb-lastline-connector')
scripts = {
'cb-lastline-connector': {
'spec': 'cb-lastline-connector.spec',
'dest': '/usr/share/cb/integrations/lastline/bin/'
}
}
setup(
name='python-cb-lastline-connector',
version='2.0.0',
packages=['cbopensource', 'cbopensource.connectors', 'cbopensource.connectors.lastline'],
package_dir={'': 'src'},
url='https://github.com/carbonblack/cb-lastline-connector',
license='MIT',
author='VMware Carbon Black Developer Network',
author_email='dev-support@carbonblack.com',
description=
'Connector between VMware Carbon Black EDR and ThreatConnect',
data_files=data_files,
classifiers=[
'Development Status :: 4 - Beta',
# Indicate who your project is intended for
'Intended Audience :: Developers',
# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: MIT License',
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
],
keywords='carbonblack bit9',
cmdclass={'install_cb': install_cb, 'build_rpm': build_rpm}
)