Repository navigation
Implement the Danger zone section on the Control page #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
daf6aca
Implement Danger zone control section
yakutovicha 3056d7e
Describe the reset trigger without a command
yakutovicha 1ddd757
Test the Danger zone's unreadable-flag paths
yakutovicha 0efc3ef
Show the factory-reset confirmation phrase
yakutovicha 6078664
Adapt the Danger zone to the single `local` reset mode
yakutovicha 64eed04
Fit the Danger zone buttons to their labels
yakutovicha e5d9aa8
Call the Danger zone reset a package reset
yakutovicha 47e0ba3
Show only the package reset notice on the home page
yakutovicha 54bd585
Share the package reset notice between both pages
yakutovicha f66fa03
Test the package reset module directly
yakutovicha 7432bef
Test the package reset notice once, directly
yakutovicha 99852e4
Merge the Danger zone's schedule failure tests
yakutovicha 7568a46
Say what the package reset notice actually blocks
yakutovicha d0a5389
Parse the reset mode like the container does
yakutovicha 7732dca
Give the package reset a title and a one-line explanation
yakutovicha 4d30de5
List how to restart the container in the reset notice
yakutovicha ebea949
Name the aiidalab-launch profile in the restart command
yakutovicha 48b342c
Point to aiidalab-launch status for the profile name
yakutovicha ec4e068
Update home/control.py
yakutovicha 24df05c
Update home/package_reset.py
yakutovicha f726ecb
Remove extra space from reset message
edan-bainglass 1918737
Apply batched suggestions from code review
yakutovicha 9476b59
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 843b920
Point to the reset script's new location
yakutovicha 8903c96
Drop the read-back check when scheduling a reset
yakutovicha f4ccce5
Show terminal link just in case something goes terribly wrong.
yakutovicha f561422
Treat a bad reset flag file as no reset, like the container
yakutovicha 2bacb5c
Refresh the Danger zone synchronously
yakutovicha 80416fd
Merge branch 'main' into feature/danger-zone-tab
yakutovicha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| """The package reset that the AiiDAlab container performs on its next start. | ||
|
|
||
| Kept free of heavy imports: the home page checks it before rendering anything. | ||
| """ | ||
|
|
||
| import html | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import ipywidgets as ipw | ||
|
|
||
| from home.themes import ThemeDefault as Theme | ||
|
|
||
| # The container's entrypoint hook (from aiidalab-docker-stack), at | ||
| # /usr/local/bin/before-notebook.d/05_factory-reset.sh, reads this file on | ||
| # start, performs the reset mode it contains and removes it. | ||
| _FACTORY_RESET_FILE = Path.home() / "AIIDALAB_FACTORY_RESET" | ||
|
|
||
| # The only reset mode of that script; it ignores any other content. | ||
| _RESET_MODE = "local" | ||
| RESET_LABEL = "Reset user-installed Python packages" | ||
|
|
||
|
|
||
| def is_scheduled() -> bool: | ||
| """Whether the container performs the reset on its next start. | ||
|
|
||
| Applies the script's own rule, so that nothing it would ignore blocks the | ||
| home page: a regular file, not a symlink, whose first 64 bytes are the | ||
| mode, ignoring whitespace. Compared as bytes, so any content is safe. | ||
| """ | ||
| if _FACTORY_RESET_FILE.is_symlink() or not _FACTORY_RESET_FILE.is_file(): | ||
| return False | ||
| try: | ||
| with _FACTORY_RESET_FILE.open("rb") as f: | ||
| content = f.read(64) | ||
| except OSError: | ||
| return False | ||
| return b"".join(content.split()) == _RESET_MODE.encode() | ||
|
|
||
|
|
||
| def schedule(): | ||
| # Replace whatever is there rather than write through a symlink. | ||
| _FACTORY_RESET_FILE.unlink(missing_ok=True) | ||
| _FACTORY_RESET_FILE.write_text(_RESET_MODE) | ||
|
|
||
|
|
||
| def cancel(): | ||
| _FACTORY_RESET_FILE.unlink(missing_ok=True) | ||
|
|
||
|
|
||
| def scheduled_message() -> str: | ||
| """An alert describing the scheduled reset and how to perform it.""" | ||
| # Set by JupyterHub in the environment of the user's server. | ||
| hub_home = os.environ.get("JUPYTERHUB_BASE_URL", "/") + "hub/home" | ||
| return f""" | ||
| <div class="alert alert-warning" role="alert"> | ||
| <div style="line-height: 1.5"> | ||
| A reset has been scheduled: <b>{html.escape(RESET_LABEL)}</b> | ||
| <br /> | ||
| Please restart your AiiDAlab container. | ||
| </div> | ||
| <div> | ||
| <h2>How to restart</h2> | ||
| <h3>On an AiiDAlab server</h3> | ||
| <ul style="margin: 0; padding-left: 20px; line-height: 1.8"> | ||
| <li> | ||
| Open the | ||
| <a class="alert-link" href="{html.escape(hub_home)}" target="_blank"> | ||
| Control Panel</a | ||
| >. | ||
| </li> | ||
| <li>Click <b>Stop My Server</b> and wait.</li> | ||
| <li>Once available, click <b>Start My Server</b>.</li> | ||
| </ul> | ||
| <h3>On a local machine</h3> | ||
| <h4>Using aiidalab-launch</h4> | ||
| <ul style="margin: 0; padding-left: 20px; line-height: 1.8"> | ||
| <li> | ||
| Find your active profile with | ||
| <code>aiidalab-launch status</code> | ||
| </li> | ||
| <li> | ||
| Run <code>aiidalab-launch start --restart -p <profile></code> | ||
| </li> | ||
| </ul> | ||
| <h4>Using Docker directly</h4> | ||
| <ul style="margin: 0; padding-left: 20px; line-height: 1.8"> | ||
| <li>Find your active container with <code>docker ps</code></li> | ||
| <li>Run <code>docker restart <container></code></li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| """ | ||
|
|
||
|
|
||
| class PackageResetNotice(ipw.VBox): | ||
| """Notice of a scheduled package reset, with a way to cancel it.""" | ||
|
|
||
| def __init__(self, on_cancelled): | ||
| self._on_cancelled = on_cancelled | ||
| self.cancel_button = ipw.Button( | ||
| description="Cancel package reset", | ||
| icon="undo", | ||
| layout=ipw.Layout(width="fit-content"), | ||
| ) | ||
| self.cancel_button.on_click(self._on_cancel) | ||
| self.error = ipw.HTML() | ||
| # The home page hides the terminal link while a reset is scheduled. | ||
| fallback = ipw.HTML( | ||
| f"<div style='color:{Theme.COLORS.GRAY};font-size:13px;margin-top:8px;'>" | ||
| "<b>If cancelling fails:</b> open a " | ||
| "<a href='./terminal.ipynb' target='_blank'>terminal</a> and run " | ||
| f"<code>rm {html.escape(str(_FACTORY_RESET_FILE))}</code></div>" | ||
| ) | ||
| super().__init__( | ||
| children=[ | ||
| ipw.HTML(scheduled_message()), | ||
| self.cancel_button, | ||
| self.error, | ||
| fallback, | ||
| ] | ||
| ) | ||
|
|
||
| def _on_cancel(self, _=None): | ||
| try: | ||
| cancel() | ||
| except Exception as exc: | ||
| self.error.value = ( | ||
| f"<span style='color: {Theme.COLORS.DANGER}'>" | ||
| f"Failed to cancel the package reset: {html.escape(str(exc))}</span>" | ||
| ) | ||
| else: | ||
| self._on_cancelled() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file con
10BC8
tains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Sugg
2E82
estions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.