diff options
author | Tristan Maat <tristan.maat@codethink.com> | 2017-07-14 15:28:21 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-07-17 23:03:00 +0900 |
commit | e21bf756032cc7995fe1e2648c30fe9139382142 (patch) | |
tree | 05a923df52f585dc26067b6189c86945832fd124 | |
parent | 785fa4abb4daa249d50bbfa143ab4f2d97aa2cfd (diff) | |
download | buildstream-e21bf756032cc7995fe1e2648c30fe9139382142.tar.gz |
main.py: Add workspace command to the frontend
-rw-r--r-- | buildstream/_frontend/main.py | 131 |
1 files changed, 122 insertions, 9 deletions
diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py index d57b93cf2..b7525a635 100644 --- a/buildstream/_frontend/main.py +++ b/buildstream/_frontend/main.py @@ -247,15 +247,17 @@ def show(app, target, variant, deps, except_, order, format): the following symbols can be used in the format string: \b - %{name} The element name - %{variant} The selected element variant - %{key} The abbreviated cache key (if all sources are consistent) - %{full-key} The full cache key (if all sources are consistent) - %{state} cached, buildable, waiting or inconsistent - %{config} The element configuration - %{vars} Variable configuration - %{env} Environment settings - %{public} Public domain data + %{name} The element name + %{variant} The selected element variant + %{key} The abbreviated cache key (if all sources are consistent) + %{full-key} The full cache key (if all sources are consistent) + %{state} cached, buildable, waiting or inconsistent + %{config} The element configuration + %{vars} Variable configuration + %{env} Environment settings + %{public} Public domain data + %{workspaced} If the element is workspaced + %{workspace-dirs} A list of workspace directories The value of the %{symbol} without the leading '%' character is understood as a pythonic formatting string, so python formatting features apply, @@ -418,6 +420,117 @@ def source_bundle(app, target, variant, force, directory, ################################################################## +# Workspace Command # +################################################################## +@cli.group(short_help="") +def workspace(): + pass + + +################################################################## +# Workspace Open Command # +################################################################## +@workspace.command(short_help="Create a workspace for manual source modification") +@click.option('--no-checkout', default=False, is_flag=True, + help="Do not checkout the source, only link to the given directory") +@click.option('--force', '-f', default=False, is_flag=True, + help="Overwrite files existing in checkout directory") +@click.option('--source', '-s', default=None, + help="The source to create a workspace for. Projects with one source may omit this") +@click.option('--variant', + help='A variant of the specified target') +@click.option('--track', default=False, is_flag=True, + help="Track and fetch new source references before checking out the workspace") +@click.argument('element') +@click.argument('directory') +@click.pass_obj +def open(app, no_checkout, force, source, variant, track, element, directory): + app.initialize(element, variant, rewritable=track, inconsistent=track) + try: + app.pipeline.open_workspace(app.scheduler, directory, source, no_checkout, track, force) + click.echo("") + except _BstError as e: + click.echo("") + click.echo("ERROR: {}".format(e)) + sys.exit(-1) + + +################################################################## +# Workspace Close Command # +################################################################## +@workspace.command(short_help="Close a workspace created with `workspace open`") +@click.option('--source', '-s', default=None, + help="The source of the workspace to remove. Projects with one source may omit this") +@click.option('--remove-dir', default=False, is_flag=True, + help="Remove the path that contains the closed workspace") +@click.option('--variant', + help='A variant of the specified target') +@click.argument('element') +@click.pass_obj +def close(app, source, remove_dir, variant, element): + if remove_dir: + if not click.confirm('This will remove all your changes, are you sure?'): + click.echo('Aborting') + sys.exit(-1) + + app.initialize(element, variant) + try: + app.pipeline.close_workspace(source, remove_dir) + click.echo("") + except _BstError as e: + click.echo("") + click.echo("ERROR: {}".format(e)) + sys.exit(-1) + + +################################################################## +# Workspace Reset Command # +################################################################## +@workspace.command(short_help="Reset a workspace to its original state") +@click.option('--source', '-s', default=None, + help="The source of the workspace to reset. Projects with one source may omit this") +@click.option('--track', default=False, is_flag=True, + help="Track and fetch the latest source before resetting") +@click.option('--no-checkout', default=False, is_flag=True, + help="Do not checkout the source, only link to the given directory") +@click.option('--variant', + help='A variant of the specified target') +@click.confirmation_option(prompt='This will remove all your changes, are you sure?') +@click.argument('element') +@click.pass_obj +def reset(app, source, track, no_checkout, variant, element): + app.initialize(element, variant) + try: + app.pipeline.reset_workspace(app.scheduler, source, track, no_checkout) + click.echo("") + except _BstError as e: + click.echo("") + click.echo("ERROR: {}".format(e)) + sys.exit(-1) + + +################################################################## +# Workspace List Command # +################################################################## +@workspace.command(name="list", short_help="List open workspaces") +@click.pass_obj +def list_(app): + project = Project(app.main_options['directory'], + app.host_arch, + app.target_arch) + + logger = LogLine(app.content_profile, + app.format_profile, + app.success_profile, + app.error_profile, + app.detail_profile, + indent=4) + + report = logger.show_workspaces(project._workspaces()) + click.echo(report, color=app.colors) + + +################################################################## # Main Application State # ################################################################## |