forked from carbonblack/cb-lastline-connector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
175 lines (145 loc) · 6.11 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
from cbopensource.connectors.joesandbox import __version__
from distutils.core import setup
from distutils.core import Command
from distutils.command.bdist_rpm import bdist_rpm
from distutils import log
from distutils.file_util import write_file
from distutils.util import change_root, convert_path
import os
from subprocess import call
class bdist_binaryrpm(bdist_rpm):
description = "create a Cb Open Source Binary RPM distribution"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
sdist = self.reinitialize_command('sdist')
self.run_command('sdist')
source = sdist.get_archive_files()[0]
self.copy_file(source, os.path.join(os.getenv("HOME"), "rpmbuild", "SOURCES"))
# Lots TODO here: generate spec file on demand from the rest of this setup.py file, for starters...
# self._make_spec_file()
call(['rpmbuild', '-bb', '%s.spec' % self.distribution.get_name()])
"""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."""
class install_cb(Command):
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 xrange(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-joesandbox-connector.spec')
data_files.append('scripts/cb-joesandbox-connector')
scripts = {
'cb-joesandbox-connector': {
'spec': 'cb-joesandbox-connector.spec',
'dest': '/usr/share/cb/integrations/joesandbox/bin/'
}
}
setup(
name='python-cb-joesandbox-connector',
version='1.2',
packages=['cbopensource', 'cbopensource.connectors', 'cbopensource.connectors.joesandbox'],
url='https://github.com/carbonblack/cb-joesandbox-connector',
license='MIT',
author='Carbon Black Developer Network',
author_email='dev-support@carbonblack.com',
description=
'Connector between Carbon Black and Joe Sandbox',
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',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
],
keywords='carbonblack bit9',
cmdclass={'install_cb': install_cb, 'bdist_binaryrpm': bdist_binaryrpm}
)