Commit Graph

943 Commits

Author SHA1 Message Date
Olivier Gayot f284d25757 utils: add parameter to avoid clearing the LC_* variables
We used to set LC_ALL=C unconditionally when executing a command. This
is a problem if we want the output of a specific command to be
translated (provided a locale definition and an actual translation exist
for the requested language).

This patch adds the clean_locale parameter, which can be used to specify
if we want the locale variable to be cleaned, to most of the helpers
that execute commands.

The value defaults to True so the default behavior is preserved.
If one wants a command to be translated, they have to  explicitly pass
clean_locale=False.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-02-07 18:18:16 +01:00
Olivier Gayot b0ced5afb0 async: add helper to run fire-and-forget tasks
calling asyncio.create_task(...) without storing a reference to the
result can lead to the task being garbage collected before it actually
executed.

https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task

The documentation gives an example of a reliable way to run
fire-and-forget background tasks.

This patch adds an helper to do exactly that.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-01-24 12:50:23 +01:00
Olivier Gayot 69264ad7f2
Merge pull request #1525 from ogayot/confirmation-overlay
Add helper to create confirmation dialog and use it for Ubuntu Pro
2023-01-05 10:50:54 +01:00
Olivier Gayot 51b6772175 ui: add a helper to open a confirmation dialog and get the response
The new ConfirmationOverlay object along with the
BaseView.ask_confirmation helper can be used to open a confirmation
dialog and get back the decision from the user.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-01-05 09:54:51 +01:00
Olivier Gayot 108b26d76d utils: fix unused stdin parameter in astart_command
Specifying the value of subprocess.PIPE as the stdin argument of
astart_command did not have any effect. This happened because the
parameter was not forwarded to the subprocess function. The parameter
was effectively unused.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-01-03 19:00:16 +01:00
Olivier Gayot e47f667e15
Merge pull request #1324 from ogayot/remove_overlay_no_overlay_ok
ui: avoid crashing when removing overlay that does not exist
2022-12-12 09:09:19 +01:00
Michael Hudson-Doyle 50ac03eacb Remove Application.aio_loop attribute 2022-12-08 12:52:14 +13:00
Olivier Gayot 163e6cfb4a ui: make not_found_ok false by default for overlays and pass it where needed
Attempting to close an overlay that does not exist is pretty much always
a bug in the code. Making not_found_ok true by default will hide obvious
bugs from us ; which is not a good thing. Perhaps more importantly, we
might just remove the wrong overlay.

Instead, we should just pass not_found_ok=True as a workaround when we
know the code is buggy and don't have time to fix the bug cleanly.

This is what happens for SSH keys import. If the import fails, we remove
the loading animation. However for answers-based runs, we do not have a
loading animation so the code bails. Let's add not_found_ok=True in this
context and we can fix the code later.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-12-07 10:31:15 +01:00
Olivier Gayot 4025cbf97f ui: avoid crashing when removing overlay that does not exist
BaseView.remove_overlay() would crash with AttributeError if no overlay
was found. We now add a not_found_ok parameter (defaulting to True) that
makes the function silently return if the overlay could not be found.

Passing not_found_ok=False and catching OverlayNotFoundError can be
helpful in some scenarios to do something different if no overlay was
found.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-12-07 10:31:05 +01:00
Michael Hudson-Doyle 06d7f04032 remove --script/--click command line arguments
I implemented these a long time ago to help working on parts of the ui
by allowing a way to script moving past some screens. I haven't used
them in ages, it's pretty bad code and probably a fragmentary answers
file is a better solution to the same problem. What do you think?
2022-12-07 14:56:00 +13:00
Michael Hudson-Doyle 7aab0b5de4 rewrite Spinner to not require a loop parameter 2022-12-07 14:19:27 +13:00
Michael Hudson-Doyle 7c3e966356 fix getting ssh info when sshd is not installed 2022-11-30 11:12:51 +13:00
Olivier Gayot fcebcac568 utils: inc. captured stdout / stderr when forging CalledProcessError
When executing a command via arun_command with check=True, we forge
and then raise a CalledProcessError exception if the command exits
abnormally (i.e., exit code != 0).

When doing so, we only instantiate the exception with the exit code and
the command executed. This means that we lose access to any output
captured so far. This is usually fine for stdout but stderr oftentimes
contains invaluable information to understand what caused the command to
exit abnormally.

Back in Python 3.5, stdout and stderr were introduced as new attributes
for CalledProcessError.
We now also include stdout and stderr in the CalledProcessError
instances that we forge. This allows us to access stderr (if any) when
catching the exception with:

  try:
      ...
  except CalledProcessError as exc:
      print(exc.stderr)

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-21 15:11:09 +01:00
Michael Hudson-Doyle 5dafdb916d call into snapd to set up encryption when required 2022-11-11 14:46:44 +13:00
Michael Hudson-Doyle 7618ce2af6 extend "unit" test to cover finish_install
and fix the bug it inevitably found.
2022-11-10 11:57:21 +13:00
Michael Hudson-Doyle 2bb3aab362 add sample data which will fail at the finish-install step 2022-11-10 11:48:37 +13:00
Michael Hudson-Doyle c24cfd3d04 call into snapd to finish the installation of a core boot classic system 2022-11-10 11:48:37 +13:00
Michael Hudson-Doyle 85b3cd0724 switch from loop.create_task to asyncio.create_task
mostly done with sed
2022-11-08 10:08:46 +13:00
Olivier Gayot fa351ed7bc
Merge pull request #1446 from ogayot/pr/event-loop-rework
Stop calling deprecated asyncio.get_event_loop() function
2022-10-28 17:50:24 +02:00
Olivier Gayot a62a0b6002 loop: start running the event loop before doing anything else
This allows us to use asyncio.run() and to avoid many pitfalls.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-28 17:05:54 +02:00
Olivier Gayot 01567251f6 loop: invoke asyncio.create_task() directly
asyncio.create_task() calls asyncio.get_running_loop() under the hood so
there is no need to call get_running_loop() ourselves if the sole
purpose is to create a task.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-28 17:05:54 +02:00
Olivier Gayot 561fff1d5b
Merge pull request #1336 from ogayot/password-passphrase
Refactor how we handle confirmation fields - use passphrase instead of password where relevant
2022-10-28 14:06:54 +02:00
Olivier Gayot f0e5c19ee7 loop: replace use of asyncio.get_event_loop
The behavior of asyncio.get_event_loop() will change in a future Python
version. It is deprecated starting Python 3.10.

The functions that we can use instead are:

 * asyncio.new_event_loop() - which creates a new event loop
 * asyncio.get_running_loop() - which returns the event loop only if it
   is already running

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-07 18:45:11 +02:00
Michael Hudson-Doyle faf78a1be1 Revert "Merge pull request #1442 from mwhudson/main"
This reverts commit cc33a668a2, reversing
changes made to f219cd717e.
2022-10-05 15:28:39 +13:00
Michael Hudson-Doyle 1a68b4759c Revert "Merge pull request #1435 from mwhudson/snapdapi"
This reverts commit f219cd717e, reversing
changes made to 7fe070dec3.
2022-10-05 14:37:34 +13:00
Michael Hudson-Doyle 521e7026de tweak AsyncSnapd api slightly
also remove dry-run delay for requests to /v2/change/{id}
2022-10-04 16:15:19 +13:00
Dan Bungert 9e0a90fc22 network: use routes instead of gateway directives 2022-09-06 16:44:12 -06:00
Dan Bungert 943ea53fbc
Merge pull request #1402 from dbungert/terminology
fix some easier cases of impolite language
2022-08-29 18:00:35 -06:00
Michael Hudson-Doyle 60953951fe
Merge pull request #1394 from CarlosNihelton/style-help-gray
Defaults help text style to gray
2022-08-30 11:34:42 +12:00
Dan Bungert d73772258d fix some easier cases of impolite language 2022-08-29 12:30:39 -06:00
Carlos Nihelton 6d51deedb6
Assign style if a str is passed
Otherwise assign self.help as passed.

Co-authored-by: Dan Bungert <danielbungert@gmail.com>
2022-08-29 13:55:07 -03:00
J-P Nurmi 05ca22b320 Log NetworkModel.has_network changes 2022-08-26 15:06:15 +02:00
Dan Bungert d3275c3e90
Merge pull request #1393 from CarlosNihelton/fix-gray-contrast
Makes our gray ligther to increase contrast.
2022-08-24 08:44:45 -06:00
Carlos Nihelton eb722fef0b
Defaults help text style to gray
Per
https://github.com/canonical/ubuntu-desktop-installer/issues/1073#issuecomment-1224493840.
Custom styles can still be applied.
2022-08-24 11:24:24 -03:00
Carlos Nihelton 5763f33813
Makes our gray ligther to increase contrast.
Per Design's recommendation in:
https://github.com/canonical/ubuntu-desktop-installer/issues/1073#issuecomment-1225569053
2022-08-24 10:16:59 -03:00
Olivier Gayot eb69f23ce7 ubuntu-pro: update the view to include magic-attach
We now have the view display the user-code fetched via u-a-c and
automatically validate the contract token when the contract selection
succeeds.

If the magic token expires (i.e., u-a-c times out), a new contract
selection is initiated.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-08-18 16:10:44 +02:00
Chad Smith ddaf48b334 models: subiquitycore.network.rendered_config_paths to list generated files 2022-07-14 21:48:51 -06:00
Chad Smith a531ade6c3 file_util: generate_timestamped_header function to any subiquity written files 2022-07-14 21:48:51 -06:00
Olivier Gayot 384e4b62ac ui: move confirmation mechanism in subiquitycore.ui
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-06-24 17:24:20 +02:00
Dan Bungert dffb155203 tests: s/run_coro/IsolatedAsyncioTestCase/
Tests that use run_coro are at risk of being broken by the introduction
of another test using IsolatedAsyncioTestCase.  Switch over to only use
IsolatedAsyncioTestCase.
2022-06-23 17:43:14 -06:00
Olivier Gayot 2ee5550c9e ui: add ability to change button label in SomethingFailed message box
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-06-15 11:54:32 +02:00
Olivier Gayot a93202e0a1
Merge pull request #1307 from ogayot/subforms-recurse-validation
Check child forms status when disabling/enabling Done button of a form
2022-06-14 15:23:05 +02:00
Dan Bungert 5b30732f14 debug shell: restore orig environment 2022-06-13 14:02:32 -06:00
Olivier Gayot c72e7eec87 form: use subclass of BoundFormField that overrides is_in_error
Instead of using isinstance(self.widget, SubFormWidget) in
BoundFormField.is_in_error, we now implement a BoundSubFormField
class that inherits from BoundFormField. It is meant to be instantianted
for subforms fields only.

This class overrides is_in_error() to perform the additional checks in
the forms' sub-fields.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-06-09 11:28:36 +02:00
Olivier Gayot 348195b4d6 form: disable Done button on validation failure of a child form
When the validation of a field fails in a form, we disable the Done
button. With child forms, however, it did not work because they have
their own set of hidden buttons ; that are not the ones the users
interacts with.

This patch makes parent forms recurse on the child forms when checking
if any field is in error. Also, when a child form undertakes validation,
it now propagates to the parent, so that the done button can be
immediately enabled/disabled.

Having a validation error in a child form that is not currently enabled
should not prevent the user from moving forward, so we disable recursion
for child forms that are disabled.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-06-09 11:28:36 +02:00
Dan Bungert 77119a8e0b SingleInstanceTask: add cancel_restart
cancel_restart is a mode for SingleInstanceTask that changes the
behavior when starting the task - if the task is already running, do not
cancel it to start another.
2022-05-25 10:25:00 -06:00
Dan Bungert 884f1c87ae pubsub: fix test fragility 2022-05-24 13:36:02 -06:00
Olivier Gayot 37de61f245 snaplist: display starred indication (✪) in orange
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-05-10 09:45:25 +02:00
Olivier Gayot 2fdeb55218 snaplist: improve hack to display double stars instead of ✓
We used to rely on the narrow non-breakable space to be displayed as a
star in basic mode. This is not great and could impact other screens.

We now make use of two check-marks (each replaced by a star in basic
mode) and mask one of them in rich mode using display attributes.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-05-10 09:45:25 +02:00
Olivier Gayot fcb33b8a0a snaplist: do not use green color for stars in basic mode
The "**" signs replace the check-mark for a verified publisher when in
basic mode.

These "**" signs where still used green foreground color. This was the
only place where we tried to display colors in basic mode.

Keep the default colors instead. This should be more compatible.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-05-04 10:32:32 +02:00