setup.py 13.7 KB
Newer Older
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
1
#!/usr/bin/env python
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
2
# -*- coding: utf-8 -*-
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
3
import os
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
4
import sys
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
5

6
from subprocess import check_output, call, STDOUT
7 8
from distutils import log
from distutils.core import Command
9
from setuptools import setup, find_packages
10 11
from setuptools.command.develop import develop
from setuptools.command.sdist import sdist
12
from setuptools.command.install import install
13
from setuptools.command.bdist_egg import bdist_egg
14
from setuptools.command.egg_info import egg_info
15

Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
16
ROOT = os.path.join(os.path.dirname(os.path.realpath(__file__)))
17
DEVNULL = open(os.devnull, 'wb')
18

19 20 21 22 23 24 25 26 27 28 29
# Not sure bower was a great idea...
VENDOR_TO_KEEP = [
    'burpui/static/vendor/bootswatch/slate/bootstrap.min.css',
    'burpui/static/vendor/bootswatch/fonts/glyphicons-halflings-regular.eot',
    'burpui/static/vendor/bootswatch/fonts/glyphicons-halflings-regular.svg',
    'burpui/static/vendor/bootswatch/fonts/glyphicons-halflings-regular.ttf',
    'burpui/static/vendor/bootswatch/fonts/glyphicons-halflings-regular.woff',
    'burpui/static/vendor/bootswatch/fonts/glyphicons-halflings-regular.woff2',
    'burpui/static/vendor/nvd3/build/nv.d3.min.css',
    'burpui/static/vendor/datatables.net-bs/css/dataTables.bootstrap.min.css',
    'burpui/static/vendor/datatables.net-responsive-bs/css/responsive.bootstrap.min.css',
30 31
    'burpui/static/vendor/datatables.net-select-bs/css/select.bootstrap.min.css',
    'burpui/static/vendor/datatables.net-buttons-bs/css/buttons.bootstrap.min.css',
32
    'burpui/static/vendor/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css',
33 34
    'burpui/static/vendor/jquery.fancytree/dist/skin-bootstrap/ui.fancytree.min.css',
    'burpui/static/vendor/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css',
35
    'burpui/static/vendor/angular-ui-select/dist/select.min.css',
36 37 38
    'burpui/static/vendor/jquery/dist/jquery.min.js',
    'burpui/static/vendor/jquery-ui/jquery-ui.min.js',
    'burpui/static/vendor/bootstrap/dist/js/bootstrap.min.js',
39
    'burpui/static/vendor/typeahead.js/dist/typeahead.jquery.min.js',
40 41 42 43
    'burpui/static/vendor/d3/d3.min.js',
    'burpui/static/vendor/nvd3/build/nv.d3.min.js',
    'burpui/static/vendor/datatables.net/js/jquery.dataTables.min.js',
    'burpui/static/vendor/datatables.net-bs/js/dataTables.bootstrap.min.js',
44 45 46 47 48
    'burpui/static/vendor/datatables.net-responsive/js/dataTables.responsive.min.js',
    'burpui/static/vendor/datatables.net-responsive-bs/js/responsive.bootstrap.min.js',
    'burpui/static/vendor/datatables.net-select/js/dataTables.select.min.js',
    'burpui/static/vendor/datatables.net-buttons/js/dataTables.buttons.min.js',
    'burpui/static/vendor/datatables.net-buttons-bs/js/buttons.bootstrap.min.js',
49 50
    'burpui/static/vendor/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js',
    'burpui/static/vendor/jquery.floatThead/dist/jquery.floatThead.min.js',
51 52 53 54 55 56 57 58 59 60
    'burpui/static/vendor/jquery.fancytree/dist/jquery.fancytree-all.min.js',
    'burpui/static/vendor/jquery-file-download/src/Scripts/jquery.fileDownload.js',
    'burpui/static/vendor/lodash/dist/lodash.min.js',
    'burpui/static/vendor/angular/angular.min.js',
    'burpui/static/vendor/angular-route/angular-route.min.js',
    'burpui/static/vendor/angular-sanitize/angular-sanitize.min.js',
    'burpui/static/vendor/angular-resource/angular-resource.min.js',
    'burpui/static/vendor/angular-animate/angular-animate.min.js',
    'burpui/static/vendor/bootstrap-switch/dist/js/bootstrap-switch.min.js',
    'burpui/static/vendor/angular-bootstrap-switch/dist/angular-bootstrap-switch.min.js',
61
    'burpui/static/vendor/angular-ui-select/dist/select.min.js',
62 63 64
    'burpui/static/vendor/angular-strap/dist/angular-strap.min.js',
    'burpui/static/vendor/angular-strap/dist/angular-strap.tpl.min.js',
    'burpui/static/vendor/angular-onbeforeunload/build/angular-onbeforeunload.js',
65
    'burpui/static/vendor/angular-datatables-0.6.2/dist/angular-datatables.min.js',
66
    'burpui/static/vendor/angular-highlightjs/build/angular-highlightjs.min.js',
67 68 69
    'burpui/static/vendor/moment/min/moment.min.js',
    'burpui/static/vendor/moment/locale/fr.js',
    'burpui/static/vendor/moment/locale/es.js',
70
    'burpui/static/vendor/moment/locale/it.js',
71
    'burpui/static/vendor/moment-timezone/builds/moment-timezone-with-data-10-year-range.min.js',
72 73 74 75 76 77 78
    'burpui/static/vendor/angular-ui-calendar/src/calendar.js',
    'burpui/static/vendor/fullcalendar/dist/fullcalendar.min.css',
    'burpui/static/vendor/fullcalendar/dist/fullcalendar.print.min.css',
    'burpui/static/vendor/fullcalendar/dist/fullcalendar.min.js',
    'burpui/static/vendor/fullcalendar/dist/gcal.min.js',
    'burpui/static/vendor/fullcalendar/dist/locale/fr.js',
    'burpui/static/vendor/fullcalendar/dist/locale/es.js',
79
    'burpui/static/vendor/fullcalendar/dist/locale/it.js',
80 81 82 83 84 85 86 87 88
    'burpui/static/vendor/angular-bootstrap/ui-bootstrap.min.js',
    'burpui/static/vendor/angular-bootstrap/ui-bootstrap-tpls.min.js',
    'burpui/static/vendor/components-font-awesome/css/font-awesome.min.css',
    'burpui/static/vendor/components-font-awesome/fonts/FontAwesome.otf',
    'burpui/static/vendor/components-font-awesome/fonts/fontawesome-webfont.eot',
    'burpui/static/vendor/components-font-awesome/fonts/fontawesome-webfont.svg',
    'burpui/static/vendor/components-font-awesome/fonts/fontawesome-webfont.ttf',
    'burpui/static/vendor/components-font-awesome/fonts/fontawesome-webfont.woff',
    'burpui/static/vendor/components-font-awesome/fonts/fontawesome-webfont.woff2',
89
    'burpui/static/vendor/socket.io-client/dist/socket.io.js',
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
90
    'burpui/static/vendor/js-cookie/src/js.cookie.js',
91 92 93 94
    'burpui/static/vendor/ace-builds/src-min-noconflict/ace.js',
    'burpui/static/vendor/ace-builds/src-min-noconflict/mode-json.js',
    'burpui/static/vendor/ace-builds/src-min-noconflict/worker-json.js',
    'burpui/static/vendor/ace-builds/src-min-noconflict/theme-ambiance.js',
95 96 97 98
]

for p in VENDOR_TO_KEEP:
    if not os.path.exists(p):
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
99
        log.info('!! missing: {}'.format(p))
100

101 102 103 104 105 106 107

class DevelopWithBuildStatic(develop):
    def install_for_development(self):
        self.run_command('build_static')
        return develop.install_for_development(self)


108 109 110 111 112 113
class EggWithBuildStatic(egg_info):
    def initialize_options(self):
        self.run_command('build_static')
        return egg_info.initialize_options(self)


114 115 116
class BdistWithBuildStatic(bdist_egg):
    def initialize_options(self):
        self.run_command('build_static')
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
117
        return bdist_egg.initialize_options(self)
118 119


120 121 122 123 124 125
class SdistWithBuildStatic(sdist):
    def make_distribution(self):
        self.run_command('build_static')
        return sdist.make_distribution(self)


126 127 128
class PyTest(Command):
    user_options = []
    description = "Run tests"
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
129

130 131 132 133 134 135 136
    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
137 138 139 140
        try:
            errno = call(['make', 'test'])
            raise SystemExit(errno)
        except OSError:
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
141
            log.error('Looks like the tools to run the tests are missing')
142 143


144 145 146
class BuildStatic(Command):
    user_options = []
    description = "Install bower dependencies"
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
147

148 149 150 151 152 153 154
    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
155
        os.chdir(ROOT)
156
        log.info('compiling translations')
157
        call('{} ./burpui -m manage compile-translation'.format(sys.executable).split(), stderr=DEVNULL)
158
        log.info('getting revision number')
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
159
        rev = 'stable'
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
160 161 162
        ci = os.getenv('CI')
        commit = os.getenv('CI_COMMIT_SHA')
        if not ci and os.path.exists('.git') and call("which git", shell=True, stderr=STDOUT, stdout=DEVNULL) == 0:
163
            try:
164
                branch = check_output('git rev-parse HEAD', shell=True).rstrip()
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
165
                ver = open(os.path.join('burpui', 'VERSION')).read().rstrip()
166
                log.info('version: {}'.format(ver))
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
167 168
                if branch and 'dev' in ver:
                    rev = branch
169 170 171 172 173 174
                try:
                    log.info('revision: {}'.format(rev))
                    with open('burpui/RELEASE', 'wb') as f:
                        f.write(rev)
                except:
                    log.error('Unable to create release file')
175 176
            except:
                pass
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
177 178 179 180 181 182 183 184 185 186 187 188
        elif ci:
            try:
                ver = open(os.path.join('burpui', 'VERSION')).read().rstrip()
                if 'dev' in ver:
                    rev = commit
                try:
                    with open('burpui/RELEASE', 'wb') as f:
                        f.write(rev)
                except:
                    pass
            except:
                pass
189 190
        else:
            log.info('using upstream revision')
191
        keep = VENDOR_TO_KEEP
192
        dirlist = []
193 194 195
        for dirname, subdirs, files in os.walk('burpui/static/vendor'):
            for filename in files:
                path = os.path.join(dirname, filename)
196
                _, ext = os.path.splitext(path)
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
197
                if os.path.isfile(path) and path not in keep and filename not in ['bower.json', 'package.json']:
198 199
                    if (rev == 'stable' and ext == '.map') or ext != '.map':
                        os.unlink(path)
200 201
                elif os.path.isdir(path):
                    dirlist.append(path)
202
        dirlist.sort(reverse=True)
203 204 205
        for d in dirlist:
            if os.path.isdir(d) and not os.listdir(d):
                os.rmdir(d)
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
206

Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
207

208 209 210 211 212
class CustomInstall(install):
    def run(self):
        self.run_command('build_static')
        install.run(self)

Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
213

Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
214 215 216 217 218 219
def readme():
    """
    Function used to skip the screenshots part
    """
    desc = ''
    cpt = 0
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
220
    skip = False
221
    with open(os.path.join(ROOT, 'README.rst')) as f:
Benjamin "Ziirish" SANS's avatar
lint  
Benjamin "Ziirish" SANS committed
222 223
        for line in f.readlines():
            if line.rstrip() == 'Screenshots':
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
224 225
                skip = True
            if skip:
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
226
                cpt += 1
227
            if cpt > 6:
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
228 229
                skip = False
            if skip:
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
230
                continue
Benjamin "Ziirish" SANS's avatar
lint  
Benjamin "Ziirish" SANS committed
231
            desc += line
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
232 233
    return desc

Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
234

235 236 237
sys.path.insert(0, os.path.join(ROOT))

from burpui.desc import __author__, __author_email__, __description__, \
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
238
                        __url__, __title__  # noqa
239 240 241 242 243
name = __title__
author = __author__
author_email = __author_email__
description = __description__
url = __url__
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
244

245
with open(os.path.join(ROOT, 'requirements.txt')) as f:
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
246 247
    requires = [x.strip() for x in f if x.strip()]

248
dev_requires = ['flake8', 'pylint']
249
test_requires = [
250 251
    'pytest',
    'pytest-cov',
252
    'pytest-flask',
253
    'pytest-mock',
254 255 256 257 258 259 260 261 262 263 264
    'nose',
    'coverage',
    'mock',
    'mockredispy',
    'Flask-Session',
    'Celery',
    'redis',
    'Flask-SQLAlchemy',
    'Flask-Migrate',
    'sqlalchemy_utils',
]
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
265

266 267 268
datadir = os.path.join('share', 'burpui')
confdir = os.path.join(datadir, 'etc')
contrib = os.path.join(datadir, 'contrib')
269
migrations = [(os.path.join(datadir, root), [os.path.join(root, f) for f in files if not f.endswith('.pyc')])
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
270
              for root, dirs, files in os.walk('migrations')]
271

Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
272
setup(
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
273
    name=name,
274
    version=open(os.path.join(ROOT, 'burpui', 'VERSION')).read().rstrip(),
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
275
    description=description,
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
276
    long_description=readme(),
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
277
    license=open(os.path.join(ROOT, 'LICENSE')).readline().rstrip(),
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
278 279 280
    author=author,
    author_email=author_email,
    url=url,
281
    keywords='burp web ui backup monitoring',
282
    packages=find_packages(),
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
283 284
    include_package_data=True,
    package_data={
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
285 286 287
        'static': ['burpui/static/*'],
        'templates': ['burpui/templates/*'],
        'VERSION': ['burpui/VERSION'],
288 289 290 291
    },
    entry_points={
        'console_scripts': [
            'burp-ui=burpui.__main__:server',
292
            'bui-celery=burpui.__main__:celery',
293
            'bui-manage=burpui.__main__:manage',
294
            'bui-agent-legacy=burpui.__main__:agent',
295
            'bui-monitor=burpui.__main__:monitor',
296
            'burp-ui-legacy=burpui.__main__:legacy',
297
        ],
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
298
    },
299
    data_files=[
300
        (confdir, [os.path.join(confdir, 'burpui.sample.cfg')]),
301
        (os.path.join(contrib, 'centos'), ['contrib/centos/init.sh']),
302
        (os.path.join(contrib, 'freebsd'), ['contrib/freebsd/gunicorn.rc']),
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
303
        (os.path.join(contrib, 'gunicorn'), ['contrib/gunicorn/burpui_gunicorn.py']),
304 305 306 307 308 309
        (os.path.join(contrib, 'systemd'), ['contrib/systemd/bui-agent.service',
                                            'contrib/systemd/bui-celery.service',
                                            'contrib/systemd/bui-celery-beat.service',
                                            'contrib/systemd/bui-gunicorn.service',
                                            'contrib/systemd/bui-monitor.service',
                                            'contrib/systemd/bui-websocket.service']),
310
    ] + migrations,
311
    python_requires=">=3.6",
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
312
    install_requires=requires,
313
    extras_require={
314
        'ldap_authentication': ['ldap3'],
315
        'gunicorn': ['gunicorn'],
316
        'gunicorn-extra': ['redis'],
317
        'ci': test_requires,
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
318
        'dev': dev_requires,
319
        'celery': ['Celery>=4.3', 'redis'],
320
        'sql': ['Flask-SQLAlchemy', 'Flask-Migrate>=2.1.0', 'sqlalchemy-utils'],
321
        'limit': ['Flask-Limiter', 'redis'],
322
        'websocket': ['flask-socketio', 'redis', 'gevent-websocket'],
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
323
        'rtd': ['sphinxcontrib-httpdomain==1.6.1'],
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
324
    },
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
325
    tests_require=test_requires,
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
326 327 328 329 330 331 332
    classifiers=[
        'Framework :: Flask',
        'Intended Audience :: System Administrators',
        'Natural Language :: English',
        'License :: OSI Approved :: BSD License',
        'Operating System :: POSIX :: Linux',
        'Programming Language :: Python',
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
333
        'Programming Language :: Python :: 3.6',
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
334
        'Topic :: System :: Archiving :: Backup',
335
        'Topic :: System :: Monitoring',
336 337 338 339 340
    ],
    cmdclass={
        'build_static': BuildStatic,
        'develop': DevelopWithBuildStatic,
        'sdist': SdistWithBuildStatic,
341
        'install': CustomInstall,
342
        'bdist_egg': BdistWithBuildStatic,
343
        'egg_info': EggWithBuildStatic,
344
    }
Benjamin "Ziirish" SANS's avatar
Benjamin "Ziirish" SANS committed
345
)