Skip to content
Snippets Groups Projects
Commit b8120f50 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[scripts][editor_cli] Implement editor start for specific asset

Part of #186
Replaces !51
parent 7d2a4b5f
No related branches found
No related tags found
1 merge request!62Core implementation
......@@ -35,6 +35,7 @@ import click
import pkg_resources
from click_plugins import with_plugins
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QCoreApplication
......@@ -45,23 +46,21 @@ from beat.cmdline.decorators import verbosity_option
from ..utils import setup_logger
from ..widgets.mainwindow import MainWindow
from ..widgets.assetwidget import AssetWidget
from ..backend.assetmodel import AssetType
global logger
logger = None
EPILOG = """\b
START_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",
......@@ -76,35 +75,72 @@ def editor(ctx):
)
@verbosity_option()
@click.pass_context
def editor(ctx, prefix, cache):
"""beat.editor commands."""
ctx.meta["prefix"] = prefix
ctx.meta["cache"] = cache
global logger
logger = setup_logger("beat.editor", ctx.meta["verbosity"])
QCoreApplication.setApplicationName("beat.editor")
QCoreApplication.setOrganizationName("Idiap")
QCoreApplication.setOrganizationDomain("ch.idiap")
@editor.command(epilog=START_EPILOG)
@click.pass_context
@raise_on_error
def start(ctx, prefix, cache):
def start(ctx):
"""Start the beat editor
"""
ctx.meta["prefix"] = prefix
ctx.meta["cache"] = cache
config = Configuration(ctx.meta)
global logger
logger.info("BEAT prefix set to `%s'", config.path)
logger.info("BEAT cache set to `%s'", config.cache)
completions = dict(
prog=os.path.basename(sys.argv[0]),
version=pkg_resources.require("beat.editor")[0].version,
)
app = QApplication(sys.argv)
completions.update(Configuration({}).as_dict())
mainwindow = MainWindow()
mainwindow.set_prefix_root(os.path.abspath(config.path))
mainwindow.show()
return app.exec_()
EDIT_EPILOG = """\b
Example:
$ beat editor edit algorithm user/my_algo/1
"""
# Check that we are in a BEAT working folder
logger = setup_logger("beat.editor", ctx.meta["verbosity"])
@editor.command(epilog=EDIT_EPILOG)
@click.argument("asset_type")
@click.argument("asset_name")
@click.pass_context
@raise_on_error
def edit(ctx, asset_type, asset_name):
"""Edit one specific asset
"""
config = Configuration(ctx.meta)
global logger
logger.info("BEAT prefix set to `%s'", config.path)
logger.info("BEAT cache set to `%s'", config.cache)
prefix_root = os.path.abspath(config.path)
app = QApplication(sys.argv)
QCoreApplication.setApplicationName("beat.editor")
QCoreApplication.setOrganizationName("Idiap")
QCoreApplication.setOrganizationDomain("ch.idiap")
asset_widget = AssetWidget()
asset_widget.set_prefix_root(prefix_root)
asset_path = os.path.join(
prefix_root, AssetType.path(AssetType[asset_type.upper()]), asset_name + ".json"
)
asset_widget.load_json(asset_path)
asset_widget.show()
mainwindow = MainWindow()
mainwindow.set_prefix_root(config.path)
mainwindow.show()
return app.exec_()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment