setup.py 13.6 KB
Newer Older
Ziirish's avatar
Ziirish committed
1
#!/usr/bin/env python
Ziirish's avatar
Ziirish committed
2
# -*- coding: utf-8 -*-
Ziirish's avatar
Ziirish committed
3 4 5

import os
import re
Ziirish's avatar
Ziirish committed
6
import sys
Ziirish's avatar
Ziirish committed
7

8
from subprocess import check_output, call, STDOUT
9 10
from distutils import log
from distutils.core import Command
Ziirish's avatar
Ziirish committed
11
from setuptools import setup, find_packages
12 13
from setuptools.command.develop import develop
from setuptools.command.sdist import sdist
Ziirish's avatar
Ziirish committed
14
from setuptools.command.install import install
Ziirish's avatar
Ziirish committed
15
from setuptools.command.bdist_egg import bdist_egg
16
from setuptools.command.egg_info import egg_info
17

Ziirish's avatar
Ziirish committed
18
ROOT=os.path.join(os.path.dirname(os.path.realpath(__file__)))
19
DEVNULL = open(os.devnull, 'wb')
20

21 22 23 24 25 26 27 28 29 30 31
# 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',
32 33
    'burpui/static/vendor/datatables.net-select-bs/css/select.bootstrap.min.css',
    'burpui/static/vendor/datatables.net-buttons-bs/css/buttons.bootstrap.min.css',
34
    'burpui/static/vendor/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css',
35 36
    'burpui/static/vendor/jquery.fancytree/dist/skin-bootstrap/ui.fancytree.min.css',
    'burpui/static/vendor/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css',
Ziirish's avatar
Ziirish committed
37
    'burpui/static/vendor/angular-ui-select/dist/select.min.css',
38 39 40
    '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',
41
    'burpui/static/vendor/typeahead.js/dist/typeahead.jquery.min.js',
42 43 44 45
    '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',
46 47 48 49 50
    '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',
51 52
    'burpui/static/vendor/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js',
    'burpui/static/vendor/jquery.floatThead/dist/jquery.floatThead.min.js',
53 54 55 56 57 58 59 60 61 62
    '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',
Ziirish's avatar
Ziirish committed
63
    'burpui/static/vendor/angular-ui-select/dist/select.min.js',
64 65 66
    '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',
67
    'burpui/static/vendor/angular-datatables-0.6.2/dist/angular-datatables.min.js',
68
    'burpui/static/vendor/angular-highlightjs/build/angular-highlightjs.min.js',
69 70 71
    'burpui/static/vendor/moment/min/moment.min.js',
    'burpui/static/vendor/moment/locale/fr.js',
    'burpui/static/vendor/moment/locale/es.js',
Ziirish's avatar
Ziirish committed
72
    'burpui/static/vendor/moment/locale/it.js',
73 74 75 76 77 78 79
    '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',
Ziirish's avatar
Ziirish committed
80
    'burpui/static/vendor/fullcalendar/dist/locale/it.js',
81 82 83 84 85 86 87 88 89
    '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',
Ziirish's avatar
Ziirish committed
90
    'burpui/static/vendor/socket.io-client/dist/socket.io.js',
Ziirish's avatar
Ziirish committed
91
    'burpui/static/vendor/js-cookie/src/js.cookie.js',
92 93 94 95
    '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',
96 97 98 99
]

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

102 103 104 105 106 107 108

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


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


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


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


Ziirish's avatar
Ziirish committed
127 128 129 130 131 132 133 134 135 136
class PyTest(Command):
    user_options = []
    description = "Run tests"
    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:
Ziirish's avatar
Ziirish committed
141
            log.error('Looks like the tools to run the tests are missing')
Ziirish's avatar
Ziirish committed
142 143


144 145 146 147 148 149 150 151 152 153
class BuildStatic(Command):
    user_options = []
    description = "Install bower dependencies"
    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

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

Ziirish's avatar
Ziirish committed
206

Ziirish's avatar
Ziirish committed
207 208 209 210 211
class CustomInstall(install):
    def run(self):
        self.run_command('build_static')
        install.run(self)

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

232 233 234 235 236 237 238 239 240
sys.path.insert(0, os.path.join(ROOT))

from burpui.desc import __author__, __author_email__, __description__, \
        __url__, __title__
name = __title__
author = __author__
author_email = __author_email__
description = __description__
url = __url__
Ziirish's avatar
Ziirish committed
241

Ziirish's avatar
Ziirish committed
242
with open(os.path.join(ROOT, 'requirements.txt')) as f:
Ziirish's avatar
Ziirish committed
243 244
    requires = [x.strip() for x in f if x.strip()]

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

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

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