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
import os
Ziirish's avatar
Ziirish committed
4
import sys
Ziirish's avatar
Ziirish committed
5

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

Ziirish's avatar
Ziirish 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',
Ziirish's avatar
Ziirish committed
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',
Ziirish's avatar
Ziirish committed
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',
Ziirish's avatar
Ziirish committed
70
    'burpui/static/vendor/moment/locale/it.js',
71 72 73 74 75 76 77
    '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
78
    'burpui/static/vendor/fullcalendar/dist/locale/it.js',
79 80 81 82 83 84 85 86 87
    '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
88
    'burpui/static/vendor/socket.io-client/dist/socket.io.js',
Ziirish's avatar
Ziirish committed
89
    'burpui/static/vendor/js-cookie/src/js.cookie.js',
90 91 92 93
    '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',
94 95 96 97
]

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

100 101 102 103 104 105 106

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


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


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


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


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

Ziirish's avatar
Ziirish committed
129 130 131 132 133 134 135
    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

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


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

147 148 149 150 151 152 153
    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

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

Ziirish's avatar
Ziirish committed
233

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

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

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

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

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

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