diff --git a/beat/editor/scripts/editor_cli.py b/beat/editor/scripts/editor_cli.py new file mode 100644 index 0000000000000000000000000000000000000000..94980f238300a7209207f39975245e64e1cb317d --- /dev/null +++ b/beat/editor/scripts/editor_cli.py @@ -0,0 +1,104 @@ +#!/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/. # +# # +############################################################################### + +""" +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.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 +Example: + $ beat editor start + + """ + + +@with_plugins(pkg_resources.iter_entry_points("beat.editor.cli")) +@click.group(cls=AliasedGroup) +@click.pass_context +def editor(ctx): + """beat.editor commands.""" + pass + + +@editor.command(epilog=EPILOG) +@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 start(ctx, prefix, cache): + """Start the beat editor + """ + + 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, + ) + + completions.update(Configuration({}).as_dict()) + + # Check that we are in a BEAT working folder + 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) + + app = QApplication(sys.argv) + mainwindow = MainWindow() + mainwindow.set_prefix_root(config.path) + mainwindow.show() + return app.exec_() diff --git a/beat/editor/scripts/server_cli.py b/beat/editor/scripts/server_cli.py deleted file mode 100644 index 79a51745fb39f25f575d969e480b4c2250a65177..0000000000000000000000000000000000000000 --- a/beat/editor/scripts/server_cli.py +++ /dev/null @@ -1,132 +0,0 @@ -#!/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/. # -# # -############################################################################### - - -"""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 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 - -EPILOG = '''\b -Example: - $ beat editor serve - $ beat editor serve --dev - - To run the development server add option --dev - ''' - -@with_plugins(pkg_resources.iter_entry_points('beat.editor.cli')) -@click.group(cls=AliasedGroup) -@click.pass_context -def editor(ctx): - """beat.editor commands webserver.""" - 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) -@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 - ''' - - ctx.meta['dev'] = dev - ctx.meta['debug'] = debug - 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 - ) - - 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']) - - 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) diff --git a/setup.py b/setup.py index 74ff89972028433390b49cb9a911d6dd7f059546..74c630a693755184f02023fcadab45ff17ee0fe6 100644 --- a/setup.py +++ b/setup.py @@ -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", ], )