scripts: black

This commit is contained in:
Albert Hopkins 2018-10-27 11:15:59 -07:00
parent 5a96cc75a1
commit b2c92c5ec7
2 changed files with 33 additions and 40 deletions

View File

@ -8,7 +8,7 @@ import sys
def main(): def main():
chroot = os.environ["CHROOT"] chroot = os.environ["CHROOT"]
target = sys.argv[-1] target = sys.argv[-1]
chroot_target = os.path.join(chroot, target.lstrip('/')) chroot_target = os.path.join(chroot, target.lstrip("/"))
command = ["cp"] + sys.argv[1:-1] + [chroot_target] command = ["cp"] + sys.argv[1:-1] + [chroot_target]
subprocess.check_call(command) subprocess.check_call(command)

View File

@ -4,86 +4,82 @@ import os
import shutil import shutil
import subprocess import subprocess
EMERGE = os.environ['EMERGE'].split() EMERGE = os.environ["EMERGE"].split()
USEPKG = os.environ['USEPKG'].split() USEPKG = os.environ["USEPKG"].split()
def get_latest_available_kernel(): def get_latest_available_kernel():
kernel = os.environ['KERNEL'] kernel = os.environ["KERNEL"]
package_name = 'sys-kernel/{}'.format(kernel) package_name = "sys-kernel/{}".format(kernel)
popen = subprocess.Popen( popen = subprocess.Popen(
['portageq', 'best_visible', '/', package_name], ["portageq", "best_visible", "/", package_name], stdout=subprocess.PIPE
stdout=subprocess.PIPE,
) )
cpv = popen.stdout.read().decode().strip() cpv = popen.stdout.read().decode().strip()
return cpv.rpartition('-')[2] return cpv.rpartition("-")[2]
def get_current_kernel(): def get_current_kernel():
"""what kernel does /boot/vmlinuz point to""" """what kernel does /boot/vmlinuz point to"""
vmlinuz = '/boot/vmlinuz' vmlinuz = "/boot/vmlinuz"
if not os.path.islink(vmlinuz): if not os.path.islink(vmlinuz):
return None return None
filename = os.path.basename(os.path.realpath(vmlinuz)) filename = os.path.basename(os.path.realpath(vmlinuz))
assert filename.startswith('vmlinuz') assert filename.startswith("vmlinuz")
part_after_vmlinuz = filename[8:] part_after_vmlinuz = filename[8:]
# may have "-gentoo" or whatever in the name # may have "-gentoo" or whatever in the name
version = part_after_vmlinuz.rpartition('-')[0] version = part_after_vmlinuz.rpartition("-")[0]
return version return version
def install_kernel_package(): def install_kernel_package():
kernel = os.environ['KERNEL'] kernel = os.environ["KERNEL"]
package_name = 'sys-kernel/{}'.format(kernel) package_name = "sys-kernel/{}".format(kernel)
cmd = EMERGE + USEPKG + ['--oneshot', '--noreplace', package_name] cmd = EMERGE + USEPKG + ["--oneshot", "--noreplace", package_name]
subprocess.check_call(cmd) subprocess.check_call(cmd)
def copy_kernel_config(): def copy_kernel_config():
filename = '/root/kernel.config' filename = "/root/kernel.config"
shutil.copy(filename, '/usr/src/linux/.config') shutil.copy(filename, "/usr/src/linux/.config")
def build_kernel(): def build_kernel():
makeopts = os.environ.get('MAKEOPTS', '') makeopts = os.environ.get("MAKEOPTS", "")
subprocess.check_call([ subprocess.check_call(
'make', '-C', '/usr/src/linux', 'MAKEOPTS=' + makeopts, 'oldconfig' ["make", "-C", "/usr/src/linux", "MAKEOPTS=" + makeopts, "oldconfig"]
]) )
subprocess.check_call([ subprocess.check_call(["make", "-C", "/usr/src/linux", "MAKEOPTS=" + makeopts])
'make', '-C', '/usr/src/linux', 'MAKEOPTS=' + makeopts
])
def remove_old_kernels(): def remove_old_kernels():
kernel_files = ['vmlinuz-', 'System.map-', 'config-'] kernel_files = ["vmlinuz-", "System.map-", "config-"]
for filename in os.listdir('/boot'): for filename in os.listdir("/boot"):
for kernel_file in kernel_files: for kernel_file in kernel_files:
if filename.startswith(kernel_file): if filename.startswith(kernel_file):
path = os.path.join('/boot', filename) path = os.path.join("/boot", filename)
os.unlink(path) os.unlink(path)
if os.path.exists('/boot/vmlinuz'): if os.path.exists("/boot/vmlinuz"):
os.unlink('/boot/vmlinuz') os.unlink("/boot/vmlinuz")
shutil.rmtree('/lib/modules', ignore_errors=True) shutil.rmtree("/lib/modules", ignore_errors=True)
def install_kernel(): def install_kernel():
makeopts = os.environ.get('MAKEOPTS', '') makeopts = os.environ.get("MAKEOPTS", "")
subprocess.check_call([ subprocess.check_call(
'make', '-C', '/usr/src/linux', 'MAKEOPTS=' + makeopts, 'install', ["make", "-C", "/usr/src/linux", "MAKEOPTS=" + makeopts, "install", "modules_install"]
'modules_install' )
])
# create the symlink. /sbin/installkernel claims this is not used on # create the symlink. /sbin/installkernel claims this is not used on
# "modern" distributions and doesn't create it (unless it already # "modern" distributions and doesn't create it (unless it already
@ -97,15 +93,13 @@ def install_kernel():
def uninstall_kernel_package(): def uninstall_kernel_package():
subprocess.check_call([ subprocess.check_call(["make", "-C", "/usr/src/linux", "distclean"])
'make', '-C', '/usr/src/linux', 'distclean'
])
subprocess.check_call(EMERGE + USEPKG + ['--depclean', '--with-bdeps=n']) subprocess.check_call(EMERGE + USEPKG + ["--depclean", "--with-bdeps=n"])
def backup_kernel_config(): def backup_kernel_config():
shutil.copy('/usr/src/linux/.config', '/root/kernel.config') shutil.copy("/usr/src/linux/.config", "/root/kernel.config")
def main(): def main():
@ -126,4 +120,3 @@ def main():
main() main()