add support for lockfiles on checkout

When checking out repositories, check if a file <filename>.lock.<ext>
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 <felix.moessbauer@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Felix Moessbauer 2023-04-23 11:42:26 +02:00 committed by Jan Kiszka
parent 3e0dd10416
commit fe4031ce01
2 changed files with 21 additions and 2 deletions

View File

@ -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):

View File

@ -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 <file>.lock.<ext>
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: