mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
pre-commit: run black with string normalization
This commit is contained in:
22
tljh/apt.py
22
tljh/apt.py
@@ -13,9 +13,9 @@ def trust_gpg_key(key):
|
||||
key is a GPG public key (bytes) that can be passed to apt-key add via stdin.
|
||||
"""
|
||||
# If gpg2 doesn't exist, install it.
|
||||
if not os.path.exists('/usr/bin/gpg2'):
|
||||
install_packages(['gnupg2'])
|
||||
utils.run_subprocess(['apt-key', 'add', '-'], input=key)
|
||||
if not os.path.exists("/usr/bin/gpg2"):
|
||||
install_packages(["gnupg2"])
|
||||
utils.run_subprocess(["apt-key", "add", "-"], input=key)
|
||||
|
||||
|
||||
def add_source(name, source_url, section):
|
||||
@@ -27,20 +27,20 @@ def add_source(name, source_url, section):
|
||||
# lsb_release is not installed in most docker images by default
|
||||
distro = (
|
||||
subprocess.check_output(
|
||||
['/bin/bash', '-c', 'source /etc/os-release && echo ${VERSION_CODENAME}'],
|
||||
["/bin/bash", "-c", "source /etc/os-release && echo ${VERSION_CODENAME}"],
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
.decode()
|
||||
.strip()
|
||||
)
|
||||
line = f'deb {source_url} {distro} {section}\n'
|
||||
with open(os.path.join('/etc/apt/sources.list.d/', name + '.list'), 'a+') as f:
|
||||
line = f"deb {source_url} {distro} {section}\n"
|
||||
with open(os.path.join("/etc/apt/sources.list.d/", name + ".list"), "a+") as f:
|
||||
# Write out deb line only if it already doesn't exist
|
||||
f.seek(0)
|
||||
if line not in f.read():
|
||||
f.write(line)
|
||||
f.truncate()
|
||||
utils.run_subprocess(['apt-get', 'update', '--yes'])
|
||||
utils.run_subprocess(["apt-get", "update", "--yes"])
|
||||
|
||||
|
||||
def install_packages(packages):
|
||||
@@ -48,9 +48,9 @@ def install_packages(packages):
|
||||
Install debian packages
|
||||
"""
|
||||
# Check if an apt-get update is required
|
||||
if len(os.listdir('/var/lib/apt/lists')) == 0:
|
||||
utils.run_subprocess(['apt-get', 'update', '--yes'])
|
||||
if len(os.listdir("/var/lib/apt/lists")) == 0:
|
||||
utils.run_subprocess(["apt-get", "update", "--yes"])
|
||||
env = os.environ.copy()
|
||||
# Stop apt from asking questions!
|
||||
env['DEBIAN_FRONTEND'] = 'noninteractive'
|
||||
utils.run_subprocess(['apt-get', 'install', '--yes'] + packages, env=env)
|
||||
env["DEBIAN_FRONTEND"] = "noninteractive"
|
||||
utils.run_subprocess(["apt-get", "install", "--yes"] + packages, env=env)
|
||||
|
||||
Reference in New Issue
Block a user