mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 18:54:16 +02:00
arch: automatically optimizing arch packages compilation | aria2c stdout sleep
This commit is contained in:
@@ -1,17 +1,24 @@
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from math import ceil
|
||||
from multiprocessing import Process
|
||||
from threading import Thread
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager
|
||||
|
||||
from bauh.api.constants import HOME_PATH
|
||||
from bauh.gems.arch import pacman, disk
|
||||
|
||||
URL_INDEX = 'https://aur.archlinux.org/packages.gz'
|
||||
URL_INFO = 'https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'
|
||||
|
||||
GLOBAL_MAKEPKG = '/etc/makepkg.conf'
|
||||
USER_MAKEPKG = '{}/makepkg.conf'.format(HOME_PATH)
|
||||
|
||||
RE_MAKE_FLAGS = re.compile(r'#?\s*MAKEFLAGS\s*=\s*.+\s*')
|
||||
|
||||
|
||||
class AURIndexUpdater(Thread):
|
||||
|
||||
@@ -52,3 +59,50 @@ class ArchDiskCacheUpdater(Thread if bool(os.getenv('BAUH_DEBUG', 0)) else Proce
|
||||
saved = disk.save_several({app for app in installed['not_signed']}, 'aur', overwrite=False)
|
||||
|
||||
self.logger.info('Pre-cached data of {} AUR packages to the disk'.format(saved))
|
||||
|
||||
|
||||
class ArchCompilationOptimizer(Thread if bool(os.getenv('BAUH_DEBUG', 0)) else Process):
|
||||
|
||||
def __init__(self, logger: logging.Logger):
|
||||
super(ArchCompilationOptimizer, self).__init__(daemon=True)
|
||||
self.logger = logger
|
||||
self.compilation_optimizations = bool(int(os.getenv('BAUH_ARCH_OPTIMIZE', 1)))
|
||||
|
||||
def run(self):
|
||||
|
||||
if not self.compilation_optimizations:
|
||||
self.logger.info("Arch packages compilation optimization is disabled. Aborting...")
|
||||
else:
|
||||
try:
|
||||
ncpus = ceil(os.cpu_count() * 1.5)
|
||||
except:
|
||||
self.logger.error('Could not determine the number of processors. Aborting...')
|
||||
return
|
||||
|
||||
if os.path.exists(GLOBAL_MAKEPKG) and not os.path.exists(USER_MAKEPKG):
|
||||
self.logger.info("Verifying if it is possible to optimize Arch packages compilation")
|
||||
|
||||
with open(GLOBAL_MAKEPKG) as f:
|
||||
global_makepkg = f.read()
|
||||
|
||||
makeflags = RE_MAKE_FLAGS.findall(global_makepkg)
|
||||
user_makepkg = None
|
||||
|
||||
if makeflags:
|
||||
not_commented = [f for f in makeflags if not makeflags[0].startswith('#')]
|
||||
|
||||
if not not_commented:
|
||||
user_makepkg = RE_MAKE_FLAGS.sub('', global_makepkg)
|
||||
else:
|
||||
self.logger.warning("It seems '{}' compilation flags are already customized".format(GLOBAL_MAKEPKG))
|
||||
else:
|
||||
user_makepkg = global_makepkg
|
||||
|
||||
if user_makepkg:
|
||||
user_makepkg = '# <generated by bauh>\n' + user_makepkg + '\nMAKEFLAGS="-j{}"'.format(ncpus)
|
||||
with open(USER_MAKEPKG, 'w+') as f:
|
||||
f.write(user_makepkg)
|
||||
|
||||
self.logger.info("A custom optimized 'makepkg.conf' was generated at '{}'".format(HOME_PATH))
|
||||
else:
|
||||
self.logger.warning("A custom 'makepkg.conf' is already defined at '{}'".format(HOME_PATH))
|
||||
|
||||
Reference in New Issue
Block a user