Bug 1890689 Don't pretend to pre-buffer with DynamicResampler r=pehrsons
[gecko.git] / python / mozboot / mozboot / centosfedora.py
blob37aa0e8eaa7955f6f4ab70d2267682afd38b9058
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
5 import subprocess
7 from mozfile import which
9 from mozboot.base import BaseBootstrapper
10 from mozboot.linux_common import LinuxBootstrapper
13 class CentOSFedoraBootstrapper(LinuxBootstrapper, BaseBootstrapper):
14 def __init__(self, distro, version, dist_id, **kwargs):
15 BaseBootstrapper.__init__(self, **kwargs)
17 self.distro = distro
18 self.version = int(version.split(".")[0])
19 self.dist_id = dist_id
21 def install_packages(self, packages):
22 if self.version >= 33 and "perl" in packages:
23 packages.append("perl-FindBin")
24 # watchman is not available on centos/rocky
25 if self.distro in ("centos", "rocky", "oracle"):
26 packages = [p for p in packages if p != "watchman"]
27 self.dnf_install(*packages)
29 def upgrade_mercurial(self, current):
30 if current is None:
31 self.dnf_install("mercurial")
32 else:
33 self.dnf_update("mercurial")
35 def dnf_install(self, *packages):
36 if which("dnf"):
38 def not_installed(package):
39 # We could check for "Error: No matching Packages to list", but
40 # checking `dnf`s exit code is sufficent.
41 # Ideally we'd invoke dnf with '--cacheonly', but there's:
42 # https://bugzilla.redhat.com/show_bug.cgi?id=2030255
43 is_installed = subprocess.run(
44 ["dnf", "list", "--installed", package],
45 stdout=subprocess.PIPE,
46 stderr=subprocess.STDOUT,
48 if is_installed.returncode not in [0, 1]:
49 stdout = is_installed.stdout
50 raise Exception(
51 f'Failed to determine whether package "{package}" is installed: "{stdout}"'
53 return is_installed.returncode != 0
55 packages = list(filter(not_installed, packages))
56 if len(packages) == 0:
57 # avoid sudo prompt (support unattended re-bootstrapping)
58 return
60 command = ["dnf", "install"]
61 else:
62 command = ["yum", "install"]
64 if self.no_interactive:
65 command.append("-y")
66 command.extend(packages)
68 self.run_as_root(command)
70 def dnf_update(self, *packages):
71 if which("dnf"):
72 command = ["dnf", "update"]
73 else:
74 command = ["yum", "update"]
76 if self.no_interactive:
77 command.append("-y")
78 command.extend(packages)
80 self.run_as_root(command)