Commit 0a214156 authored by Flavio TARSETTI's avatar Flavio TARSETTI

[scripts] removed deprecated server.py script

parent fa1c94fa
Pipeline #23014 failed with stages
in 90 minutes and 8 seconds
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.editor module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
"""Starts the BEAT editor
Usage: %(prog)s [-v...] [--debug] [--prefix=<path>] [--cache=<path>] [--dev]
%(prog)s --help
%(prog)s --version
Options:
-h, --help Shows this help message and exits
-V, --version Prints the version and exits
-v, --verbose Increases the output verbosity level. Using "-vv"
allows the program to output informational messages as
it goes along.
-d, --debug Use the debug version of the javascript source to
launch the editor
--dev Use the development version, which doesn't open a new
web browser tab.
-p, --prefix=<path> Overrides the prefix of your local data. If not set use
the value from your RC file
[default: %(prefix)s]
-c, --cache=<path> Overrides the cache prefix. If not set, use the value
from your RC file, otherwise defaults to
`<prefix>/%(cache)s'
Examples:
Start the editor:
$ %(prog)s -vv
Start the editor in development mode:
$ %(prog)s -vv --debug
"""
import os
import sys
import docopt
from beat.cmdline.config import Configuration
def main(user_input=None):
if user_input is not None:
argv = user_input
else:
argv = sys.argv[1:]
import pkg_resources
completions = dict(
prog=os.path.basename(sys.argv[0]),
version=pkg_resources.require('beat.editor')[0].version
)
from beat.cmdline.config import Configuration
completions.update(Configuration({}).as_dict())
args = docopt.docopt(
__doc__ % completions,
argv=argv,
version=completions['version'],
)
from ..utils import setup_logger
logger = setup_logger('beat.editor', args['--verbose'])
# Check that we are in a BEAT working folder
config = Configuration(args)
logger.info('BEAT prefix set to `%s\'', config.path)
logger.info('BEAT cache set to `%s\'', config.cache)
from flask import Flask, request, redirect, url_for
from flask_restful import Api
from flask_cors import CORS
from ..resources import Layout, Templates, Environments, Settings
from ..resources import VALID_ENTITIES, gen_endpoint
static_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../js')
app = Flask(__name__, static_folder=static_folder, static_url_path='')
errors = errors = {
'PythonFileAlreadyExistsError': {
'message': "The python template file trying to be created already exists.",
'status': 409,
}
}
api = Api(app, errors=errors)
CORS(app)
@app.route('/')
def home():
return redirect(url_for('static', filename='index.html'))
api.add_resource(Layout, '/layout', resource_class_kwargs={'config': config})
api.add_resource(Templates, '/templates', resource_class_kwargs={'config': config})
api.add_resource(Settings, '/settings', resource_class_kwargs={'config': config})
api.add_resource(Environments, '/environments')
for entity in VALID_ENTITIES:
api.add_resource(gen_endpoint(entity), '/' + entity,
resource_class_kwargs={'config': config})
# open the browser tab right before starting the server
# the latency of opening the tab will keep us from getting 404s
if not args['--dev']:
import webbrowser
webbrowser.open('http://localhost:5000/')
app.run(debug=args['--debug'])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment