Commit Graph

50 Commits

Author SHA1 Message Date
Dan Bungert c73fac697e utils: add gen_zsys_uuid
Add gen_zsys_uuid, to generate a uuid of the same form as used in the
ubiquity zsys-setup script.
2023-08-24 17:42:09 -06:00
Dan Bungert c08fdab2f8 one-off format of long lines with black 2023-07-25 15:27:49 -06:00
Dan Bungert 34d40643ad format with black + isort 2023-07-25 15:27:42 -06:00
Dan Bungert 7c5a7f4289 utils: stdout/stderr logger 2023-04-11 13:53:20 -06:00
Dan Bungert 15518fafd0 utils: matching_dicts handle key=None, typing
Co-authored-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-04-03 12:36:40 -06:00
Dan Bungert 6e15c46135 util: add matching_dicts
Move some of this logic to a common util, so it can be used in
unittests.  The curtin version is close but expects to work on a storage
config, which is not a flat list.
2023-04-03 11:41:47 -06:00
Dan Bungert 1d9ad848fe utils: orig_environ cleans LD_LIBRARY_PATH
LD_LIBRARY_PATH is set earlier than some of the other environment
variables like PATH or PYTHONPATH, so trying to save a clean version in
snapcraft is not viable.  Remove it here.
2023-03-30 16:34:12 -06:00
Michael Hudson-Doyle c0438b44ca fix "make lint" when run with the new pycodestyle/flake8 2023-03-23 16:38:35 +13:00
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 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 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
Dan Bungert 5b30732f14 debug shell: restore orig environment 2022-06-13 14:02:32 -06:00
Olivier Gayot a63a3ef753 utils: accept sequences of strings as commands
We used to only accept lists of strings for commands. We now accept
sequences of strings instead ; which are lists of strings or tuple of
strings.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-12 10:04:16 +02:00
Olivier Gayot dd788f9eee add assert statements following .communicate() to help type checkers
After calling .communicate() on an asyncio.subprocess.Process object,
the attribute returncode gets set to a non-None value. Type checkers are
not able to figure this out.

Fixed by adding an assert to help type checkers out.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-12 10:04:16 +02:00
Olivier Gayot 87c249d5d0 Add type annotations for command execution methods
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-02-28 14:05:56 +01:00
Michael Hudson-Doyle b144f234ac install packages listed by check-language-support when locale_support == "langpack" 2021-09-30 12:09:57 +13:00
Michael Hudson-Doyle a92b88ed9d asyncioify run_command_in_foreground 2019-12-15 08:53:36 +13:00
Michael Hudson-Doyle 05a61544fb asyncio.create_subprocess_exec defaults stdin to None 2019-12-13 11:44:12 +13:00
Michael Hudson-Doyle 3d80f46225 asyncioify the installation 2019-12-12 15:19:22 +13:00
Michael Hudson-Doyle cac9cba8ec asyncio.create_subprocess_exec does not support check=True 2019-12-11 15:02:18 +13:00
Michael Hudson-Doyle f805a9d9dd add a convenience wrapper 2019-12-11 14:39:48 +13:00
Michael Hudson-Doyle b24dbf7095 remove environment_check stuff 2019-09-09 15:27:29 +12:00
Ryan Harper b328c3deed pep8 fixes for subiquitycore/utils.py 2018-05-24 16:51:51 -05:00
Ryan Harper a0bf68f3c4 pyflakes3 fixes
Add and enable pyflakes3 on console_conf, subiquity, subiquitycore and tests.
Replace NOQA markers with __all__ declarations for module imports.
Replace some obvious deadcode that voilates flake8, separate pass for removing
dead code rather than commenting will be handled later.
2018-05-24 16:51:51 -05:00
Ryan Harper a84dd2b272 Encoding input when running commands 2018-05-21 13:35:26 -05:00
Ryan Harper 74ae9b9fde Drop use of encoding kwarg to subprocess for python3.5 compat 2018-05-21 11:54:34 -05:00
Michael Hudson-Doyle 3d5efcaf9c actually pass new defaults to run, oops 2018-05-18 13:53:25 +12:00
Michael Hudson-Doyle 1e4992a5e7 stop testing on xenial, we depend on python 3.6 now 2018-05-18 13:38:13 +12:00
Michael Hudson-Doyle cb61144144 small tweaks 2018-05-18 13:21:38 +12:00
Michael Hudson-Doyle c6468982ae Thin the wrappers around subprocess functions
Some of this stuff is not needed with modern Python.

Breaks everything of course, updates to follow.
2018-05-18 13:00:43 +12:00
Michael Hudson-Doyle a14b8debda try different process for exit to shell 2018-02-13 15:38:55 +13:00
Mathieu Trudel-Lapierre 3098d108b2 Support special paths for environment check binaries in snaps. 2017-03-06 13:28:44 -05:00
Michael Hudson-Doyle 2408dda6c7 remove references to firstboot (an old name for console-conf?) 2017-01-26 11:18:03 +13:00
Michael Hudson-Doyle 78ca3c610f make disable_subiquity work again
this makes selecting "quit installer" at the end of installation work
2017-01-25 14:38:03 +13:00
Michael Hudson-Doyle a4d6682478 simpler api for doing stuff in a background thread 2017-01-18 12:03:56 +13:00
Michael Hudson-Doyle 9cb0c00271 remove some unused code from utils.py 2017-01-13 15:08:31 +13:00
Michael Hudson-Doyle 17b943209e remove subiquitycore/async.py
it was just a glorified global variable.
2017-01-13 15:08:31 +13:00
Mathieu Trudel-Lapierre 87b8dc3ccc Support conditional 'shell=True' calls, required for top's redirection, and not supported in curtin... 2016-12-22 22:15:02 -05:00
Mathieu Trudel-Lapierre 862684efbc Fix stop calls for subiquity service. 2016-12-22 22:12:03 -05:00
Mathieu Trudel-Lapierre 449688f9a1 Fix controller ordering and disable step for subiquity 2016-12-20 15:42:04 -05:00
Michael Hudson-Doyle 65daafde05 fix run_command of a non-existent command 2016-11-22 21:31:51 +13:00
Michael Hudson-Doyle 7bef718e18 re-work logic, including having console-conf generate the file to show 2016-11-09 14:33:58 +13:00
Michael Hudson-Doyle 0e56b0cba0 Clean up systemd jobs.
The main visible effect of this is that if console-conf crashes or is killed
it restarts instantly rather than 90 seconds later. It also removes the flicker
where a getty gets started and then instantly killed during startup.
2016-09-01 22:33:00 +12:00
Michael Hudson-Doyle ef01c7d291 break run_command in two
and use the two halves when applying network config (to allow cancellation)
2016-08-22 17:02:42 +12:00
Mathieu Trudel-Lapierre 1980c4e483 fake-merge mwhudson/network 2016-08-12 22:31:31 -04:00
Michael Hudson-Doyle 070a96bcc4 Write stamp file and logs to somewhere more sensible. 2016-08-05 14:41:50 +12:00
Mathieu Trudel-Lapierre 1c7fbac977 Update paths to /writable for snappy 2016-07-27 22:16:26 +12:00
Michael Hudson-Doyle 2c749d944c Have console-conf and subiquity check differing environments.
This means that console-conf no longer needs to have hdparm installed.

I'm not sure console-conf needs to call this at all TBH.
2016-07-26 15:09:44 +12:00
Michael Hudson-Doyle 264f698299 Fix flake8 warnings in subiquitycore.
Except for line length warnings, because life is too short of that.

A few of these are real bugs.
2016-07-25 14:44:51 +12:00
Mathieu Trudel-Lapierre e1970b6477 Rename subiquity to subiquitycore -- will serve as base classes for everything
Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
2016-06-30 14:17:01 -04:00