Commit b2fb4c7c authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[scripts] Change entry points for new version of the application

parent de6f8e4e
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
......@@ -25,108 +24,81 @@
# #
###############################################################################
"""The main entry for beat.editor (click-based) scripts.
"""
The main entry for beat.editor (click-based) scripts.
"""
import os
import sys
import click
import pkg_resources
from click_plugins import with_plugins
from PyQt5.QtWidgets import QApplication
from beat.cmdline.click_helper import AliasedGroup
from beat.cmdline.decorators import verbosity_option
from beat.cmdline.decorators import raise_on_error
from beat.cmdline.config import Configuration
from beat.cmdline.decorators import raise_on_error
from beat.cmdline.decorators import verbosity_option
from ..utils import setup_logger
from ..widgets.mainwindow import MainWindow
EPILOG = '''\b
EPILOG = """\b
Example:
$ beat editor serve
$ beat editor serve --dev
$ beat editor start
To run the development server add option --dev
'''
"""
@with_plugins(pkg_resources.iter_entry_points('beat.editor.cli'))
@with_plugins(pkg_resources.iter_entry_points("beat.editor.cli"))
@click.group(cls=AliasedGroup)
@click.pass_context
def editor(ctx):
"""beat.editor commands webserver."""
"""beat.editor commands."""
pass
@editor.command(epilog=EPILOG)
@click.option('--dev', help='Use the development version, which doesn\'t open a new web browser tab.',
is_flag=True)
@click.option('--debug', '-d', help='Use the debug version of the javascript source to lauch the editor',
is_flag=True)
@click.option('--prefix', '-p', help='Overrides the prefix of your local data. If not set use the value from your RC file [default: %(prefix)s]',
type=click.STRING)
@click.option('--cache', '-c', help='Overrides the cache prefix. If not set, use the value from your RC file, otherwise defaults to `<prefix>/%(cache)s\'',
type=click.STRING)
@click.option(
"--prefix",
"-p",
help="Overrides the prefix of your local data. If not set use the value from your RC file [default: %(prefix)s]",
type=click.STRING,
)
@click.option(
"--cache",
"-c",
help="Overrides the cache prefix. If not set, use the value from your RC file, otherwise defaults to `<prefix>/%(cache)s'",
type=click.STRING,
)
@verbosity_option()
@click.pass_context
@raise_on_error
def serve(ctx, dev, debug, prefix, cache):
'''Run Flask server
To run the development server add option --dev
$ beat editor serve --dev
'''
def start(ctx, prefix, cache):
"""Start the beat editor
"""
ctx.meta['dev'] = dev
ctx.meta['debug'] = debug
ctx.meta['prefix'] = prefix
ctx.meta['cache'] = cache
ctx.meta["prefix"] = prefix
ctx.meta["cache"] = cache
completions = dict(
prog=os.path.basename(sys.argv[0]),
version=pkg_resources.require('beat.editor')[0].version
version=pkg_resources.require("beat.editor")[0].version,
)
from beat.cmdline.config import Configuration
completions.update(Configuration({}).as_dict())
# Check that we are in a BEAT working folder
from ..utils import setup_logger
logger = setup_logger('beat.editor', ctx.meta['verbosity'])
logger = setup_logger("beat.editor", ctx.meta["verbosity"])
config = Configuration(ctx.meta)
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})
if not dev:
import webbrowser
webbrowser.open('http://localhost:5000')
return app.run(debug=debug)
logger.info("BEAT prefix set to `%s'", config.path)
logger.info("BEAT cache set to `%s'", config.cache)
app = QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.set_prefix_root(config.path)
mainwindow.show()
return app.exec_()
......@@ -27,47 +27,43 @@
from setuptools import setup, find_packages, dist
dist.Distribution(dict(setup_requires=['beat.cmdline']))
dist.Distribution(dict(setup_requires=["beat.cmdline"]))
def load_requirements(f):
retval = [str(k.strip()) for k in open(f, 'rt')]
return [k for k in retval if k and k[0] not in ('#', '-')]
retval = [str(k.strip()) for k in open(f, "rt")]
return [k for k in retval if k and k[0] not in ("#", "-")]
# The only thing we do in this file is to call the setup() function with all
# parameters that define our package.
setup(
name='beat.editor',
name="beat.editor",
version=open("version.txt").read().rstrip(),
description='Local editor for BEAT objects',
url='https://gitlab.idiap.ch/beat/beat.editor',
license='AGPLv3',
author='Idiap Research Institute',
author_email='beat.support@idiap.ch',
long_description=open('README.rst').read(),
description="Local editor for BEAT objects",
url="https://gitlab.idiap.ch/beat/beat.editor",
license="AGPLv3",
author="Idiap Research Institute",
author_email="beat.support@idiap.ch",
long_description=open("README.rst").read(),
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=load_requirements('requirements.txt'),
install_requires=load_requirements("requirements.txt"),
entry_points={
# main entry for beat editor cli
'beat.cli': [
'editor = beat.editor.scripts.server_cli:editor',
],
'beat.editor.cli': [
'serve = beat.editor.scripts.server_cli:serve',
],
"beat.cli": ["editor = beat.editor.scripts.editor_cli:editor"],
"beat.editor.cli": ["start = beat.editor.scripts.editor_cli:start"],
},
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Affero General Public License v3',
'Natural Language :: English',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries :: Python Modules',
classifiers=[
"Framework :: BEAT",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)
Supports Markdown
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