Skip to content

Commit a314117

Browse files
committed
Made possible to update modules added by url
Ticket: CFE-3847 Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent 6d12a30 commit a314117

1 file changed

Lines changed: 49 additions & 31 deletions

File tree

cfbs/commands.py

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from cfbs.analyze import analyze_policyset
1414
from cfbs.args import get_args
1515

16+
from cfbs.cfbs_json import CFBSJson
1617
from cfbs.utils import (
1718
cfbs_dir,
1819
cfbs_filename,
@@ -43,6 +44,7 @@
4344
from cfbs.cfbs_config import CFBSConfig, CFBSReturnWithoutCommit
4445
from cfbs.validate import validate_config
4546
from cfbs.internal_file_management import (
47+
clone_url_repo,
4648
fetch_archive,
4749
get_download_path,
4850
local_module_copy,
@@ -815,41 +817,57 @@ def update_command(to_update):
815817
log.warning("Module '%s' not in build. Skipping its update." % update.name)
816818
continue
817819

818-
if "version" not in old_module:
819-
log.warning(
820-
"Module '%s' not updatable. Skipping its update." % old_module["name"]
820+
if "url" in old_module:
821+
path, commit = clone_url_repo(old_module["url"])
822+
remote_config = CFBSJson(
823+
path=path, url=old_module["url"], url_commit=commit
821824
)
822-
log.debug("Module '%s' has no version attribute." % old_module["name"])
823-
continue
824825

825-
index_info = index.get_module_object(update.name)
826-
if not index_info:
827-
log.warning(
828-
"Module '%s' not present in the index, cannot update it."
829-
% old_module["name"]
830-
)
831-
continue
826+
module_name = old_module["name"]
827+
provides = remote_config.get_provides()
832828

833-
local_ver = [
834-
int(version_number)
835-
for version_number in re.split(r"[-\.]", old_module["version"])
836-
]
837-
index_ver = [
838-
int(version_number)
839-
for version_number in re.split(r"[-\.]", index_info["version"])
840-
]
841-
if local_ver == index_ver:
842-
print("Module '%s' already up to date" % old_module["name"])
843-
continue
844-
elif local_ver > index_ver:
845-
log.warning(
846-
"The requested version of module '%s' is older than current version (%s < %s)."
847-
" Skipping its update."
848-
% (old_module["name"], index_info["version"], old_module["version"])
849-
)
850-
continue
829+
if not module_name or module_name not in provides:
830+
continue
831+
832+
new_module = provides[module_name]
833+
else:
834+
835+
if "version" not in old_module:
836+
log.warning(
837+
"Module '%s' not updatable. Skipping its update."
838+
% old_module["name"]
839+
)
840+
log.debug("Module '%s' has no version attribute." % old_module["name"])
841+
continue
842+
843+
index_info = index.get_module_object(update.name)
844+
if not index_info:
845+
log.warning(
846+
"Module '%s' not present in the index, cannot update it."
847+
% old_module["name"]
848+
)
849+
continue
850+
851+
local_ver = [
852+
int(version_number)
853+
for version_number in re.split(r"[-\.]", old_module["version"])
854+
]
855+
index_ver = [
856+
int(version_number)
857+
for version_number in re.split(r"[-\.]", index_info["version"])
858+
]
859+
if local_ver == index_ver:
860+
print("Module '%s' already up to date" % old_module["name"])
861+
continue
862+
elif local_ver > index_ver:
863+
log.warning(
864+
"The requested version of module '%s' is older than current version (%s < %s)."
865+
" Skipping its update."
866+
% (old_module["name"], index_info["version"], old_module["version"])
867+
)
868+
continue
851869

852-
new_module = index_info
870+
new_module = index_info
853871

854872
msg = update_module(old_module, new_module, module_updates, update)
855873

0 commit comments

Comments
 (0)