[arch] fix: error raised when the temporary directory does not exist (AUR build)

This commit is contained in:
Vinicius Moreira
2022-05-27 09:49:56 -03:00
parent 1a202d9746
commit 4d1a118b25
3 changed files with 27 additions and 11 deletions

View File

@@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Arch - Arch
- conflict resolution: removing hard dependencies that would be satisfied with the inclusion of the new package [#268](https://github.com/vinifmor/bauh/issues/268) - conflict resolution: removing hard dependencies that would be satisfied with the inclusion of the new package [#268](https://github.com/vinifmor/bauh/issues/268)
- e.g: `pipewire-pulse` conflicts with `pulseaudio`. `pulseaudio-alsa` (a dependency of pulseaudio) should not be removed, since `pipewire-pulse` provides `pulseaudio` - e.g: `pipewire-pulse` conflicts with `pulseaudio`. `pulseaudio-alsa` (a dependency of pulseaudio) should not be removed, since `pipewire-pulse` provides `pulseaudio`
- AUR build: error raised when the temporary directory does not exist (when changing the CPUs governors)
- Flatpak - Flatpak
- not all selected runtime partials to upgrade are actually requested to be upgraded - not all selected runtime partials to upgrade are actually requested to be upgraded

View File

@@ -2062,7 +2062,10 @@ class ArchManager(SoftwareManager, SettingsController):
cpus_changed, cpu_prev_governors = False, None cpus_changed, cpu_prev_governors = False, None
if optimize: if optimize:
cpus_changed, cpu_prev_governors = cpu_manager.set_all_cpus_to('performance', context.root_password, self.logger) cpus_changed, cpu_prev_governors = cpu_manager.set_all_cpus_to('performance', context.root_password,
self.logger)
pkgbuilt = False
try: try:
pkgbuilt, output = makepkg.build(pkgdir=context.project_dir, pkgbuilt, output = makepkg.build(pkgdir=context.project_dir,
@@ -2073,7 +2076,7 @@ class ArchManager(SoftwareManager, SettingsController):
finally: finally:
if cpus_changed and cpu_prev_governors: if cpus_changed and cpu_prev_governors:
self.logger.info("Restoring CPU governors") self.logger.info("Restoring CPU governors")
cpu_manager.set_cpus(cpu_prev_governors, context.root_password, {'performance'}, self.logger) cpu_manager.set_cpus(cpu_prev_governors, context.root_password, self.logger, {'performance'})
self._update_progress(context, 65) self._update_progress(context, 65)

View File

@@ -3,6 +3,7 @@ import os
import shutil import shutil
import traceback import traceback
from logging import Logger from logging import Logger
from pathlib import Path
from typing import Optional, Set, Tuple, Dict from typing import Optional, Set, Tuple, Dict
from bauh.api.paths import TEMP_DIR from bauh.api.paths import TEMP_DIR
@@ -25,10 +26,21 @@ def current_governors() -> Dict[str, Set[int]]:
return governors return governors
def set_governor(governor: str, root_password: Optional[str], cpu_idxs: Optional[Set[int]] = None): def set_governor(governor: str, root_password: Optional[str], logger: Logger, cpu_idxs: Optional[Set[int]] = None):
new_gov_file = f'{TEMP_DIR}/bauh_scaling_governor' new_gov_file = f'{TEMP_DIR}/bauh_scaling_governor'
with open(new_gov_file, 'w+') as f:
f.write(governor) try:
Path(TEMP_DIR).mkdir(exist_ok=True, parents=True)
except OSError:
logger.error(f"Could not create temporary directory for changing CPU governor: {TEMP_DIR}")
return
try:
with open(new_gov_file, 'w+') as f:
f.write(governor)
except OSError:
logger.error(f"Could not write new governor ({governor}) to {new_gov_file}")
return
for idx in (cpu_idxs if cpu_idxs else range(multiprocessing.cpu_count())): for idx in (cpu_idxs if cpu_idxs else range(multiprocessing.cpu_count())):
_change_governor(idx, new_gov_file, root_password) _change_governor(idx, new_gov_file, root_password)
@@ -37,7 +49,7 @@ def set_governor(governor: str, root_password: Optional[str], cpu_idxs: Optional
try: try:
os.remove(new_gov_file) os.remove(new_gov_file)
except OSError: except OSError:
traceback.print_exc() logger.error(f"Could not remove temporary governor file ({new_gov_file})")
def _change_governor(cpu_idx: int, new_gov_file_path: str, root_password: Optional[str]): def _change_governor(cpu_idx: int, new_gov_file_path: str, root_password: Optional[str]):
@@ -49,7 +61,7 @@ def _change_governor(cpu_idx: int, new_gov_file_path: str, root_password: Option
traceback.print_exc() traceback.print_exc()
def set_all_cpus_to(governor: str, root_password: Optional[str], logger: Optional[Logger] = None) \ def set_all_cpus_to(governor: str, root_password: Optional[str], logger: Logger) \
-> Tuple[bool, Optional[Dict[str, Set[int]]]]: -> Tuple[bool, Optional[Dict[str, Set[int]]]]:
cpus_changed, cpu_governors = False, current_governors() cpus_changed, cpu_governors = False, current_governors()
@@ -63,18 +75,18 @@ def set_all_cpus_to(governor: str, root_password: Optional[str], logger: Optiona
if logger: if logger:
logger.info(f"Changing CPUs {not_in_performance} governors to '{governor}'") logger.info(f"Changing CPUs {not_in_performance} governors to '{governor}'")
set_governor(governor, root_password, not_in_performance) set_governor(governor=governor, root_password=root_password, logger=logger, cpu_idxs=not_in_performance)
cpus_changed = True cpus_changed = True
return cpus_changed, cpu_governors return cpus_changed, cpu_governors
def set_cpus(governors: Dict[str, Set[int]], root_password: Optional[str], ignore_governors: Optional[Set[str]] = None, def set_cpus(governors: Dict[str, Set[int]], root_password: Optional[str], logger: Logger,
logger: Optional[Logger] = None): ignore_governors: Optional[Set[str]] = None):
for gov, cpus in governors.items(): for gov, cpus in governors.items():
if not ignore_governors or gov not in ignore_governors: if not ignore_governors or gov not in ignore_governors:
if logger: if logger:
logger.info(f"Changing CPUs {cpus} governors to '{gov}'") logger.info(f"Changing CPUs {cpus} governors to '{gov}'")
set_governor(gov, root_password, cpus) set_governor(governor=gov, root_password=root_password, logger=logger, cpu_idxs=cpus)