From fe4031ce01f9022f2b18bbd7d6fd5ab7f7736788 Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Sun, 23 Apr 2023 11:42:26 +0200 Subject: [PATCH] add support for lockfiles on checkout When checking out repositories, check if a file .lock. exists next to the file specified first on the kas CLI. In case this file exists and the --update option is not specified, automatically append this file to the kas CLI before performing any other kas operations. When --update is specified, the lockfile is ignored. Signed-off-by: Felix Moessbauer Signed-off-by: Jan Kiszka --- kas/config.py | 6 +++++- kas/includehandler.py | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/kas/config.py b/kas/config.py index b3eb311..ede8544 100644 --- a/kas/config.py +++ b/kas/config.py @@ -58,7 +58,11 @@ class Config: 'belong to the same repository or all ' 'must be outside of versioning control') - self.handler = IncludeHandler(self.filenames, self.top_repo_path) + update = ctx.args.update if hasattr(ctx.args, 'update') else False + + self.handler = IncludeHandler(self.filenames, + self.top_repo_path, + not update) self.repo_dict = self._get_repo_dict() def get_build_system(self): diff --git a/kas/includehandler.py b/kas/includehandler.py index 0a85fb4..c42b227 100644 --- a/kas/includehandler.py +++ b/kas/includehandler.py @@ -26,6 +26,7 @@ """ import os +from pathlib import Path from collections import OrderedDict from collections.abc import Mapping import functools @@ -121,12 +122,26 @@ class IncludeHandler: relative to the repository root path. The includes are read and merged from the deepest level upwards. + + In case ignore_lock is false, kas checks if a file .lock. + exists next to the first entry in top_files. This file is then appended + to the list of top_files. """ - def __init__(self, top_files, top_repo_path): + def __init__(self, top_files, top_repo_path, use_lock=True): self.top_files = top_files self.top_repo_path = top_repo_path + if use_lock: + lockfile = self.get_lockfile() + if Path(lockfile).exists(): + logging.debug('includehandler: append lockfile %s', lockfile) + self.top_files.append(lockfile) + + def get_lockfile(self): + file = Path(self.top_files[0]) + return file.parent / (file.stem + '.lock' + file.suffix) + def get_config(self, repos=None): """ Parameters: