Skip to content

Commit

Permalink
Custom number of cores option included
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Nov 22, 2018
1 parent e8523bc commit dad3f18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 13 additions & 3 deletions kernel_upgrader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def application(arg):
usage = arg.usage
show_version = arg.version
check_kernel_updates = arg.check
cores = arg.cores if arg.cores != 0 else None
interactive = arg.interactive
if usage:
print(EXU_USAGE)
Expand Down Expand Up @@ -90,6 +91,10 @@ def application(arg):
"drive which mounts \"/home\" 20GB are needed "
"at least" + Colors.ENDC)
__log.info("There is enough free space available. Current free space: " + str(free_space) + " GB")
if cores is not None:
__log.info("Using predefined number of cores: " + str(cores))
else:
__log.info("Using default number of cores (system available cores)")
__log.info("Starting kernel compiling")
__log.debug("Checking versions")
current_version = getLinuxVersion()
Expand Down Expand Up @@ -164,7 +169,7 @@ def application(arg):
__log.debug("Starting kernel compilation...")
__log.debug("Cleaning up space of old kernels")
print(Colors.OKBLUE + "Copying old configuration & cleaning up space..." + Colors.ENDC)
compiler = Compiler(kernel_folder, new_version, current_date)
compiler = Compiler(kernel_folder, new_version, current_date, cores)
__log.debug("Copying old kernel boot config")
if compiler.copy_latest_config():
__log.debug("Copied old kernel boot configuration")
Expand Down Expand Up @@ -243,8 +248,13 @@ def main():
"--check",
action="store_true",
help="Only checks if there is any new version available")
arguments.add_argument("-i",
"--interactive",
arguments.add_argument("-j",
"--cores",
type=int,
default=0,
help="Use a predefined number of cores for thread compilation. Default: 0 (uses the number"
"of cores available on your system)")
arguments.add_argument("--interactive",
action="store_true",
help="Launches the KernelUpgrader tool with interactive mode for selecting the kernel "
"you want to install")
Expand Down
5 changes: 3 additions & 2 deletions kernel_upgrader/data_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def unzip(self):


class Compiler:
def __init__(self, kernel_folder, new_kernel_version, current_date):
def __init__(self, kernel_folder, new_kernel_version, current_date, number_of_cores=None):
returnToHomeDir()
home_dir = getHomeDir()
self.__kernel_path = "{}/linux_{}_{}/{}".format(home_dir,
Expand All @@ -53,6 +53,7 @@ def __init__(self, kernel_folder, new_kernel_version, current_date):
new_kernel_version,
current_date)
self.__log = logging.getLogger(LOG_KERNEL)
self.__number_of_cores = number_of_cores
self.__log.debug("Kernel path: \"" + self.__kernel_path + "\"")
self.__log.debug("Decompressed kernel path: \"" + self.__decompressed_path + "\"")
self.__log.debug(
Expand Down Expand Up @@ -125,7 +126,7 @@ def compileKernel(self):

returnToHomeDir()
self.__log.debug("Starting kernel compilation - log available on \"kernel_upgrader.compiler.log\"")
number_of_cores = getCPUCount()
number_of_cores = getCPUCount() if self.__number_of_cores is None else self.__number_of_cores
if isDEBSystem():
command = COMPILE_COMPILE_NEW_KERNEL.format(number_of_cores)
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE,
Expand Down

0 comments on commit dad3f18

Please sign in to comment.