Angelos Evripiotis pushed to branch are_you_sure2 at BuildStream / buildstream
Commits:
-
b5615500
by Angelos Evripiotis at 2019-02-05T17:06:38Z
4 changed files:
- buildstream/_context.py
- buildstream/_frontend/cli.py
- buildstream/data/userconfig.yaml
- tests/frontend/workspace.py
Changes:
... | ... | @@ -121,10 +121,6 @@ class Context(): |
121 | 121 |
# Whether or not to attempt to pull build trees globally
|
122 | 122 |
self.pull_buildtrees = None
|
123 | 123 |
|
124 |
- # Boolean, whether we double-check with the user that they meant to
|
|
125 |
- # close the workspace when they're using it to access the project.
|
|
126 |
- self.prompt_workspace_close_project_inaccessible = None
|
|
127 |
- |
|
128 | 124 |
# Whether elements must be rebuilt when their dependencies have changed
|
129 | 125 |
self._strict_build_plan = None
|
130 | 126 |
|
... | ... | @@ -241,22 +237,6 @@ class Context(): |
241 | 237 |
self.sched_pushers = _yaml.node_get(scheduler, int, 'pushers')
|
242 | 238 |
self.sched_network_retries = _yaml.node_get(scheduler, int, 'network-retries')
|
243 | 239 |
|
244 |
- # Load prompt preferences
|
|
245 |
- #
|
|
246 |
- # We convert string options to booleans here, so we can be both user
|
|
247 |
- # and coder-friendly. The string options are worded to match the
|
|
248 |
- # responses the user would give at the cli, for least surprise. The
|
|
249 |
- # booleans are converted here because it's easiest to eyeball that the
|
|
250 |
- # strings are right.
|
|
251 |
- #
|
|
252 |
- prompt = _yaml.node_get(
|
|
253 |
- defaults, Mapping, 'prompt')
|
|
254 |
- _yaml.node_validate(prompt, [
|
|
255 |
- 'really-workspace-close-project-inaccessible',
|
|
256 |
- ])
|
|
257 |
- self.prompt_workspace_close_project_inaccessible = _node_get_option_str(
|
|
258 |
- prompt, 'really-workspace-close-project-inaccessible', ['ask', 'yes']) == 'ask'
|
|
259 |
- |
|
260 | 240 |
# Load per-projects overrides
|
261 | 241 |
self._project_overrides = _yaml.node_get(defaults, Mapping, 'projects', default_value={})
|
262 | 242 |
|
... | ... | @@ -808,6 +808,8 @@ def workspace_open(app, no_checkout, force, track_, directory, elements): |
808 | 808 |
def workspace_close(app, remove_dir, all_, elements):
|
809 | 809 |
"""Close a workspace"""
|
810 | 810 |
|
811 |
+ removed_required_element = False
|
|
812 |
+ |
|
811 | 813 |
with app.initialized():
|
812 | 814 |
if not (all_ or elements):
|
813 | 815 |
# NOTE: I may need to revisit this when implementing multiple projects
|
... | ... | @@ -834,18 +836,20 @@ def workspace_close(app, remove_dir, all_, elements): |
834 | 836 |
for element_name in elements:
|
835 | 837 |
if not app.stream.workspace_exists(element_name):
|
836 | 838 |
nonexisting.append(element_name)
|
837 |
- if (app.stream.workspace_is_required(element_name) and app.interactive and
|
|
838 |
- app.context.prompt_workspace_close_project_inaccessible):
|
|
839 |
- click.echo("Removing '{}' will prevent you from running "
|
|
840 |
- "BuildStream commands from the current directory".format(element_name))
|
|
841 |
- if not click.confirm('Are you sure you want to close this workspace?'):
|
|
842 |
- click.echo('Aborting', err=True)
|
|
843 |
- sys.exit(-1)
|
|
844 | 839 |
if nonexisting:
|
845 | 840 |
raise AppError("Workspace does not exist", detail="\n".join(nonexisting))
|
846 | 841 |
|
847 | 842 |
for element_name in elements:
|
848 | 843 |
app.stream.workspace_close(element_name, remove_dir=remove_dir)
|
844 |
+ if app.stream.workspace_is_required(element_name):
|
|
845 |
+ removed_required_element = True
|
|
846 |
+ |
|
847 |
+ # This message is echo'd last, as it's most relevant to the next
|
|
848 |
+ # thing the user will type.
|
|
849 |
+ if removed_required_element:
|
|
850 |
+ click.echo(
|
|
851 |
+ "Removed '{}', this will prevent you from running BuildStream "
|
|
852 |
+ "commands from the current directory.".format(element_name), err=True)
|
|
849 | 853 |
|
850 | 854 |
|
851 | 855 |
##################################################################
|
... | ... | @@ -102,20 +102,3 @@ logging: |
102 | 102 |
message-format: |
|
103 | 103 |
|
104 | 104 |
[%{elapsed}][%{key}][%{element}] %{action} %{message}
|
105 |
- |
|
106 |
-#
|
|
107 |
-# Prompt overrides
|
|
108 |
-#
|
|
109 |
-# Here you can suppress 'are you sure?' and other kinds of prompts by supplying
|
|
110 |
-# override values. Note that e.g. 'yes' and 'no' have the same meaning here as
|
|
111 |
-# they do in the actual cli prompt.
|
|
112 |
-#
|
|
113 |
-prompt:
|
|
114 |
- |
|
115 |
- # Whether to really proceed with 'bst workspace close' when doing so would
|
|
116 |
- # stop them from running bst commands in this workspace.
|
|
117 |
- #
|
|
118 |
- # ask - Ask the user if they are sure.
|
|
119 |
- # yes - Always close, without asking.
|
|
120 |
- #
|
|
121 |
- really-workspace-close-project-inaccessible: ask
|
... | ... | @@ -1183,6 +1183,7 @@ def test_external_close_other(cli, datafiles, tmpdir_factory): |
1183 | 1183 |
|
1184 | 1184 |
result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', beta_element])
|
1185 | 1185 |
result.assert_success()
|
1186 |
+ assert 'this will prevent you from running BuildStream' not in result.stderr
|
|
1186 | 1187 |
|
1187 | 1188 |
|
1188 | 1189 |
@pytest.mark.datafiles(DATA_DIR)
|
... | ... | @@ -1198,6 +1199,7 @@ def test_external_close_self(cli, datafiles, tmpdir_factory, guess_element): |
1198 | 1199 |
|
1199 | 1200 |
result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close'] + arg_elm)
|
1200 | 1201 |
result.assert_success()
|
1202 |
+ assert 'this will prevent you from running BuildStream' in result.stderr
|
|
1201 | 1203 |
|
1202 | 1204 |
|
1203 | 1205 |
@pytest.mark.datafiles(DATA_DIR)
|