Angelos Evripiotis pushed to branch aevri/safe_noninteractive at BuildStream / buildstream
Commits:
- 
1bb28761
by Angelos Evripiotis at 2018-11-29T16:34:30Z
- 
38f0853a
by Angelos Evripiotis at 2018-11-29T16:34:30Z
- 
7d7c465a
by Angelos Evripiotis at 2018-11-29T16:34:30Z
- 
32121eef
by Angelos Evripiotis at 2018-11-29T16:34:30Z
8 changed files:
- buildstream/_frontend/cli.py
- doc/sessions/developing.run
- doc/sessions/junctions.run
- doc/source/sessions-stored/developing-discard-workspace.html
- doc/source/sessions-stored/developing-reset-workspace.html
- man/bst-workspace-close.1
- man/bst-workspace-reset.1
- tests/frontend/workspace.py
Changes:
| ... | ... | @@ -769,12 +769,12 @@ def workspace_close(app, remove_dir, all_, assume_yes, elements): | 
| 769 | 769 |          if remove_dir and not assume_yes and app.context.prompt_workspace_close_remove_dir:
 | 
| 770 | 770 |              if app.interactive:
 | 
| 771 | 771 |                  if not click.confirm('This will remove all your changes, are you sure?'):
 | 
| 772 | -                    click.echo('Aborting', err=True)
 | |
| 773 | -                    sys.exit(-1)
 | |
| 772 | +                    raise AppError("User aborted")
 | |
| 774 | 773 |              else:
 | 
| 775 | -                click.echo("Aborted destructive non-interactive action.", err=True)
 | |
| 776 | -                click.echo("Please use the '--assume-yes' option to override.", err=True)
 | |
| 777 | -                sys.exit(-1)
 | |
| 774 | +                raise AppError(
 | |
| 775 | +                    "Aborted destructive non-interactive action.",
 | |
| 776 | +                    detail="Please use the '--assume-yes' option to override.",
 | |
| 777 | +                    reason='aborted-destructive-non-interactive-not-confirmed')
 | |
| 778 | 778 |  | 
| 779 | 779 |          for element_name in elements:
 | 
| 780 | 780 |              app.stream.workspace_close(element_name, remove_dir=remove_dir)
 | 
| ... | ... | @@ -810,12 +810,12 @@ def workspace_reset(app, soft, track_, all_, assume_yes, elements): | 
| 810 | 810 |          if not soft and not assume_yes and app.context.prompt_workspace_reset_hard:
 | 
| 811 | 811 |              if app.interactive:
 | 
| 812 | 812 |                  if not click.confirm('This will remove all your changes, are you sure?'):
 | 
| 813 | -                    click.echo('Aborting', err=True)
 | |
| 814 | -                    sys.exit(-1)
 | |
| 813 | +                    raise AppError("User aborted")
 | |
| 815 | 814 |              else:
 | 
| 816 | -                click.echo("Aborted destructive non-interactive action.", err=True)
 | |
| 817 | -                click.echo("Please use the '--assume-yes' option to override.", err=True)
 | |
| 818 | -                sys.exit(-1)
 | |
| 815 | +                raise AppError(
 | |
| 816 | +                    "Aborted destructive non-interactive action.",
 | |
| 817 | +                    detail="Please use the '--assume-yes' option to override.",
 | |
| 818 | +                    reason='aborted-destructive-non-interactive-not-confirmed')
 | |
| 819 | 819 |  | 
| 820 | 820 |          if all_:
 | 
| 821 | 821 |              elements = tuple(element_name for element_name, _ in app.context.get_workspaces().list())
 | 
| ... | ... | @@ -42,9 +42,9 @@ commands: | 
| 42 | 42 |  # Reset workspace
 | 
| 43 | 43 |  - directory: ../examples/developing/
 | 
| 44 | 44 |    output: ../source/sessions/developing-reset-workspace.html
 | 
| 45 | -  command: workspace reset hello.bst 
 | |
| 45 | +  command: workspace reset --assume-yes hello.bst
 | |
| 46 | 46 |  | 
| 47 | 47 |  # Discard workspace
 | 
| 48 | 48 |  - directory: ../examples/developing/
 | 
| 49 | 49 |    output: ../source/sessions/developing-discard-workspace.html
 | 
| 50 | -  command: workspace close --remove-dir hello.bst  | |
| 50 | +  command: workspace close --remove-dir --assume-yes hello.bst | 
| ... | ... | @@ -17,4 +17,4 @@ commands: | 
| 17 | 17 |  | 
| 18 | 18 |  # Remove the workspace 
 | 
| 19 | 19 |  - directory: ../examples/junctions
 | 
| 20 | -  command: workspace close --remove-dirs hello-junction.bst:hello.bst | |
| 20 | +  command: workspace close --remove-dir --assume-yes hello-junction.bst:hello.bst | 
| ... | ... | @@ -2,7 +2,7 @@ | 
| 2 | 2 |      WARNING: This file was generated with bst2html.py
 | 
| 3 | 3 |  -->
 | 
| 4 | 4 |  <div class="highlight" style="font-size:x-small"><pre>
 | 
| 5 | -<span style="color:#C4A000;font-weight:bold">user@host</span>:<span style="color:#3456A4;font-weight:bold">~/developing</span>$ bst workspace close --remove-dir hello.bst
 | |
| 5 | +<span style="color:#C4A000;font-weight:bold">user@host</span>:<span style="color:#3456A4;font-weight:bold">~/developing</span>$ bst workspace close --remove-dir --assume-yes hello.bst
 | |
| 6 | 6 |  | 
| 7 | 7 |  <span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START  </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Loading pipeline
 | 
| 8 | 8 |  <span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Loading pipeline
 | 
| ... | ... | @@ -2,7 +2,7 @@ | 
| 2 | 2 |      WARNING: This file was generated with bst2html.py
 | 
| 3 | 3 |  -->
 | 
| 4 | 4 |  <div class="highlight" style="font-size:x-small"><pre>
 | 
| 5 | -<span style="color:#C4A000;font-weight:bold">user@host</span>:<span style="color:#3456A4;font-weight:bold">~/developing</span>$ bst workspace reset hello.bst
 | |
| 5 | +<span style="color:#C4A000;font-weight:bold">user@host</span>:<span style="color:#3456A4;font-weight:bold">~/developing</span>$ bst workspace reset --assume-yes hello.bst
 | |
| 6 | 6 |  | 
| 7 | 7 |  <span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START  </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Loading pipeline
 | 
| 8 | 8 |  <span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Loading pipeline
 | 
| ... | ... | @@ -12,4 +12,7 @@ Close a workspace | 
| 12 | 12 |  Remove the path that contains the closed workspace
 | 
| 13 | 13 |  .TP
 | 
| 14 | 14 |  \fB\-a,\fP \-\-all
 | 
| 15 | -Close all open workspaces | |
| \ No newline at end of file | ||
| 15 | +Close all open workspaces
 | |
| 16 | +.TP
 | |
| 17 | +\fB\-y,\fP \-\-assume\-yes
 | |
| 18 | +Assume 'yes' to confirmation of destructive changes | |
| \ No newline at end of file | 
| ... | ... | @@ -12,4 +12,7 @@ Reset a workspace to its original state | 
| 12 | 12 |  Track and fetch the latest source before resetting
 | 
| 13 | 13 |  .TP
 | 
| 14 | 14 |  \fB\-a,\fP \-\-all
 | 
| 15 | -Reset all open workspaces | |
| \ No newline at end of file | ||
| 15 | +Reset all open workspaces
 | |
| 16 | +.TP
 | |
| 17 | +\fB\-y,\fP \-\-assume\-yes
 | |
| 18 | +Assume 'yes' to confirmation of destructive changes | |
| \ No newline at end of file | 
| ... | ... | @@ -22,6 +22,7 @@ | 
| 22 | 22 |  #           Jonathan Maw <jonathan maw codethink co uk>
 | 
| 23 | 23 |  #           Richard Maw <richard maw codethink co uk>
 | 
| 24 | 24 |  #           William Salmon <will salmon codethink co uk>
 | 
| 25 | +#           Angelos Evripiotis <jevripiotis bloomberg net>
 | |
| 25 | 26 |  #
 | 
| 26 | 27 |  | 
| 27 | 28 |  import os
 | 
| ... | ... | @@ -519,6 +520,44 @@ def test_close_all(cli, tmpdir, datafiles): | 
| 519 | 520 |      assert not os.path.exists(workspace_beta)
 | 
| 520 | 521 |  | 
| 521 | 522 |  | 
| 523 | +@pytest.mark.datafiles(DATA_DIR)
 | |
| 524 | +@pytest.mark.parametrize("scenario", [
 | |
| 525 | +    {'assume_yes': True, 'no_prompt': True},
 | |
| 526 | +    {'assume_yes': False, 'no_prompt': True},
 | |
| 527 | +    # Covered by test_close: {'assume_yes': True, 'no_prompt': False},
 | |
| 528 | +    {'assume_yes': False, 'no_prompt': False},
 | |
| 529 | +])
 | |
| 530 | +def test_close_remove_dir_prompt(cli, tmpdir, datafiles, scenario):
 | |
| 531 | + | |
| 532 | +    assume_yes, no_prompt = scenario['assume_yes'], scenario['no_prompt']
 | |
| 533 | + | |
| 534 | +    element_name, project, workspace = open_workspace(
 | |
| 535 | +        cli, tmpdir, datafiles, 'git', track=False)
 | |
| 536 | + | |
| 537 | +    workspace_args = [
 | |
| 538 | +        'workspace', 'close', '--remove-dir', element_name
 | |
| 539 | +    ]
 | |
| 540 | + | |
| 541 | +    if assume_yes:
 | |
| 542 | +        workspace_args.append('--assume-yes')
 | |
| 543 | + | |
| 544 | +    if no_prompt:
 | |
| 545 | +        cli.configure(
 | |
| 546 | +            {'prompt': {'really-workspace-close-remove-dir': 'yes'}}
 | |
| 547 | +        )
 | |
| 548 | + | |
| 549 | +    result = cli.run(project=project, args=workspace_args)
 | |
| 550 | + | |
| 551 | +    if assume_yes or no_prompt:
 | |
| 552 | +        result.assert_success()
 | |
| 553 | +        assert not os.path.exists(workspace)
 | |
| 554 | +    else:
 | |
| 555 | +        result.assert_main_error(
 | |
| 556 | +            ErrorDomain.APP,
 | |
| 557 | +            'aborted-destructive-non-interactive-not-confirmed')
 | |
| 558 | +        assert os.path.exists(workspace)
 | |
| 559 | + | |
| 560 | + | |
| 522 | 561 |  @pytest.mark.datafiles(DATA_DIR)
 | 
| 523 | 562 |  def test_reset(cli, tmpdir, datafiles):
 | 
| 524 | 563 |      # Open the workspace
 | 
| ... | ... | @@ -592,6 +631,48 @@ def test_reset_all(cli, tmpdir, datafiles): | 
| 592 | 631 |      assert not os.path.exists(os.path.join(workspace_beta, 'etc', 'pony.conf'))
 | 
| 593 | 632 |  | 
| 594 | 633 |  | 
| 634 | +@pytest.mark.datafiles(DATA_DIR)
 | |
| 635 | +@pytest.mark.parametrize("scenario", [
 | |
| 636 | +    {'assume_yes': True, 'no_prompt': True},
 | |
| 637 | +    {'assume_yes': False, 'no_prompt': True},
 | |
| 638 | +    # Covered by test_reset: {'assume_yes': True, 'no_prompt': False},
 | |
| 639 | +    {'assume_yes': False, 'no_prompt': False},
 | |
| 640 | +])
 | |
| 641 | +def test_reset_prompt(cli, tmpdir, datafiles, scenario):
 | |
| 642 | + | |
| 643 | +    assume_yes, no_prompt = scenario['assume_yes'], scenario['no_prompt']
 | |
| 644 | + | |
| 645 | +    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, 'git', False)
 | |
| 646 | + | |
| 647 | +    # Make a change to revert.
 | |
| 648 | +    os.makedirs(os.path.join(workspace, 'etc'))
 | |
| 649 | +    with open(os.path.join(workspace, 'etc', 'pony.conf'), 'w') as f:
 | |
| 650 | +        f.write("PONY='pink'")
 | |
| 651 | + | |
| 652 | +    workspace_args = [
 | |
| 653 | +        'workspace', 'reset', element_name
 | |
| 654 | +    ]
 | |
| 655 | + | |
| 656 | +    if assume_yes:
 | |
| 657 | +        workspace_args.append('--assume-yes')
 | |
| 658 | + | |
| 659 | +    if no_prompt:
 | |
| 660 | +        cli.configure(
 | |
| 661 | +            {'prompt': {'really-workspace-reset-hard': 'yes'}}
 | |
| 662 | +        )
 | |
| 663 | + | |
| 664 | +    result = cli.run(project=project, args=workspace_args)
 | |
| 665 | + | |
| 666 | +    if assume_yes or no_prompt:
 | |
| 667 | +        result.assert_success()
 | |
| 668 | +        assert not os.path.exists(os.path.join(workspace, 'etc', 'pony.conf'))
 | |
| 669 | +    else:
 | |
| 670 | +        result.assert_main_error(
 | |
| 671 | +            ErrorDomain.APP,
 | |
| 672 | +            'aborted-destructive-non-interactive-not-confirmed')
 | |
| 673 | +        assert os.path.exists(os.path.join(workspace, 'etc', 'pony.conf'))
 | |
| 674 | + | |
| 675 | + | |
| 595 | 676 |  @pytest.mark.datafiles(DATA_DIR)
 | 
| 596 | 677 |  def test_list(cli, tmpdir, datafiles):
 | 
| 597 | 678 |      element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, 'git', False)
 | 
